Steven Samuel Cole | 10 Feb 03:53
Picon
Gravatar

Re: [iostreams] multichar_output_filter works only the first time

i tried using a boost::iostreams::file_sink in the output filter instead 
of std::cout --> same result.

i also tried running the code on the latest ubuntu instead of mac osx 
lion --> same result.
JIA Pei | 10 Feb 02:49
Picon

std:string to boost::filesystem::path, then, create directories.



Hi, all:


After upgrading to boost 1.48.0, my code seems to stopping working.

The original code is pretty simple:

char* folderName = "./test";
if (!boost::filesystem::is_directory( folderName  ) )
    boost::filesystem::create_directories(  folderName  );

It used to work fine but after upgrading to boost 1.48.0, I got the following annoying errors always:

Unhandled exception at 0x51d8ee9e (msvcr90d.dll) in myTest.exe: 0xC0000005: Access violation writing location 0xcdcdcdcd.

The program stops at the line "if (!boost::filesystem::is_directory( folderName  ) )", and the call stack seems to hint it's an error coming from memcpy.asm

"
TrailUp1:
        mov     al,[esi]        ;U - get byte from source
                                ;V - spare
        mov     [edi],al        ;U - put byte in destination
        mov     eax,[dst]       ;V - return pointer to destination
        pop     esi             ;U - restore esi
        pop     edi             ;V - restore edi
        M_EXIT
"



Can anybody help me out?

Thank you very much....

Best Regards
Pei


--

Pei JIA

cell:    +1 604-362-5816

Welcome to Vision Open
http://www.visionopen.com
_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Bill Buklis | 10 Feb 02:46
Gravatar

[tuple] Tuple arithmetic

Is there any facility to perform arithmetic operations on a tuple?

For example:

     struct data
     {
         double    a, b;
     };

     data    d1 = {1.0, 2.0};
     data    d2 = {2.5, 5.5};

     // These two lines are not valid, but simulate what I want.
     boost::tie(d1.a, d1.b) *= 10.0;        // Multiply each element by 10.0
     boost::tie(d1.a, d1.b) += boost::tie(d2.a, d2.b);    // Add the 
elements from the second object

After calculations, d1 should equal {12.5, 25.5};

Thanks,

--

-- 
Bill
Bill Buklis | 9 Feb 22:08
Gravatar

[range] count vs count_if

The documentation for boost range states that count_if can be expressed as count using a filtered adaptor and then goes on to say that no algorithm needs the _if suffix. I'm having trouble seeing how that is the case. Here is the relevant section from the latest (1.49 beta) documentation.

Range Adaptor alternative to count_if algorithm

boost::count_if( rng, pred );

can be expressed as

boost::count( rng | boost::adaptors::filtered(pred), out );

What this means is that no algorithm with the _if suffix is needed.


First of all, what is "out"? I think this is supposed to be "value" as count requires the value to compare against for the count. But, since it does require the value, this makes the function fundamentally different than count_if which will only count the values that match the predicate. As far as I can tell, this means that "count" will filter values both by the predicate and by the value.

What am I missing? How can count_if be properly expressed as count. To me it seems like it can't.

-- Bill
_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Gheorghe Marinca | 9 Feb 20:04
Gravatar

Using boost::asio with thousands of concurrent connections

Hi,

I started to use boost::asio some time ago and want to use it for a windows commercial product that does web filtering and handles thousands of connections concurrently (proxy based product)

I am wandering if anybody had experience using it at such a large scale, where besides handling many connections you have to handle inside a connection communication with databases, things that potentially incur delaying handling of subsequent requests. What kind of configuration would you advise in such a case (multiple I/O services per n threads, on IO service that handles all incoming connections and a thread pool that handles processing of async handlers - how one would assure in this case a connections is handled in the same thread then ..etc)

Thanks for any input
-Ghira

_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost Users List | 9 Feb 18:26
Picon
Gravatar

XML and Boost Property Tree

Hey Boost users! I'm iterating over an XML document using boost property
tree and storing the results in a struct. The issue I have is that I can
only get to the first "item" nodes and can't access the second "item"
nodes. I was hoping someone would point out where I've made a mistake.

My program output looks like this (you can see items are missing.. there
is no cookie2, candy2 or chocolate2 items shown):

jar : snAcks
snack : coOkie
item : cooKie1
snack : canDy
item : caNdy1
snack : cHocolate
item : choColate1

Here's the xml file:

<root>
  <jar name="snAcks">
    <snack name="coOkie">
      <item name="cooKie1"></item>
      <item name="cookIe2"></item>
    </snack>
    <snack name="canDy">
      <item name="caNdy1"></item>
      <item name="candY2"></item>
    </snack>
    <snack name="cHocolate">
        <item name="choColate1"></item>
	<item name="chocOlate2"></item>
    </snack>
  </jar>
</root>

Here's the source code:

void parse_xml( boost::property_tree::iptree const& pt )
{
    BOOST_FOREACH( boost::property_tree::iptree::value_type const& v,
pt.get_child("root.jar") )
    {
        // Show jar
        if ( boost::iequals( v.first, "<xmlattr>" ) )
        {
            std::cout << "jar : " << v.second.get<std::string>("NaME") <<
std::endl;
        }

        if ( boost::iequals( v.first, "snack" ) )
        {
            // Show snack
            std::cout << "snack : " <<
v.second.get<std::string>("<xmlattr>.name")  << std::endl;

            try
            {
                BOOST_FOREACH( boost::property_tree::iptree::value_type
const& val, v.second.get_child("item") )
                {
                    if ( boost::iequals( val.first, "<xmlattr>" ) ) {
                        // Show item
                        std::cout << "item : " <<
val.second.get<std::string>("nAmE")  << std::endl;
                    }
                }
            }

            catch (boost::property_tree::ptree_bad_path& e)
            {
                // Show what caused exception
                std::cout << "Exception: " << e.what() << std::endl;
            }
        }
    }
}

Thank you for taking time to read this. I think I've made a simple
mistake, but cannot understand where.
Steven Samuel Cole | 9 Feb 17:43
Picon
Gravatar

[iostreams] multichar_output_filter works only the first time

hello,

to get started with iostreams, i'm trying to write a multichar output 
filter that adds a string to the beginning and the end of whatever comes 
through. my code builds with a warning about unused parameter n and 
works - but only the first time, the second time, i get no output.

i thought at first sending '\0' would trigger the stream's fail-bit or 
so, but out.good() returns true.

any chance someone takes a look at my code and hazards a guess where the 
problem might be ?

disclaimer: i was actually born and bred in C++ country long time ago, 
but i've been coding in python for a couple of years and got back only 
recently, so there's a good chance what i'm doing wrong is something 
really simple. guess you can tell from the code, it's been a while. good 
to be back though... :-)

#include <iostream>
#include <sstream>

#include <boost/iostreams/concepts.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/operations.hpp>

using std::cin;
using std::cout;
using std::endl;
using std::streamsize;
using std::string;
using std::stringstream;

class add_string_output_filter
  : public boost::iostreams::multichar_output_filter
{
     public:

     template<typename Sink>
     streamsize write(Sink& sink, const char* s, streamsize n)
     {
         // remove trailing '\0' to prevent line break
         // TODO: there's probably a better way
         string tmp_string = string(s);
         string out_string = tmp_string.substr(0, tmp_string.size()-1);
         string pre_string("prepended string - ");
         string app_string(" - appended string");

         stringstream sstrm;
         sstrm << pre_string << out_string << app_string << endl;

         // TODO: char* to string, back to char* ?!?
         return boost::iostreams::write(sink,
                                        sstrm.str().c_str(),
                                        sstrm.str().length());
     }
};

int main()
{
     boost::iostreams::filtering_ostream out;
     out.push(add_string_output_filter());
     out.push(cout);

     cout << "prompt: ";

     string str;
     while (getline(cin, str))
     {
         out << str << endl;
         cout << "prompt: ";
     }
}

# sample session:

prompt: some string
prepended string - some string - appended string
prompt: another string
prompt: why no output ?
prompt:

# ssc
Dario Ramos | 9 Feb 15:59
Picon
Gravatar

[asio::serial_port] I can read and write synchronously, but how do I unblock when I want to end?

I'm using boost::asio::serial_port to read and write to a serial port device. I do the reading inside a boost::thread to take advantage of RS-232 being full-duplex. My read calls are like this one:

BYTE b;
read( m_SerialPort, boost::asio::buffer(&b,1) );

Everything works OK except for shutdown. When I want to end the thread, it's almost always blocked in a read call. How do I unblock it? I tried:

  • Calling close on the port: This generates an exception, which I can catch, but I was told I can't distinguish shutdown from error if I do this.
  • Stopping the io_service I passed to the serial_port's constructor. This had no effect, the thread remained blocked on the read call.

--

Darío Eduardo Ramos
Meditech S.A. www.meditech.com.ar
(+54) 01147603300, Interno 31

Av. Julio A. Roca 3456

Florida Oeste, Bs.As. Argentina


_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Sean Farrow | 9 Feb 12:34
Picon

retrieving section names from a boost::proper_tree

Hi All:

I have parsed a .ini file in to a boost::property_tree. I now would like to retrieve all the section names and place them in a vector.

Am I needing the key_type or the value_type. I am suspecting the former! Also is there a quick way of outputting the section names without having to use a boost_foreach or similar loop construct?

Any herlp appreciated.

Regards

Sean.

_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
John M. Dlugosz | 9 Feb 07:13
Favicon

Metaprogramming Question

I've not had much opportunity to do much template metaprogramming in my work, but I've 
kept up with my reading.  So, might I get some advice on how to approach this problem?

I'm thinking of an assert-like statement that follows the syntax of Boost.Format, thus 
avoiding the variadic argument list.

     MY_FANCY_ASSERT (cond, "format string") % arg % arg;

works if the macro expands to an unnamed temporary, whose destructor does the interesting 
work if the first argument is false.

     my_assert_formatter_type (cond, "cond", __FILE__, __LINE__, "format string")

This is easy to do, simply deriving from boost::formatter, I would think.

But, I want to avoid doing any work except on failure.  This means remembering the 
arguments including the following %arg stuff, and passing everything through to 
Boost.Format based on the condition.

So I'm thinking that template metaprogramming can let me collect all the arguments (any 
number of them) into one object, efficiently at compile time.

So, what approach should I use?
     Plain MPL and classic metaprogramming?
     Fusion?
     Phoenix?

and any concrete suggestions on how to proceed, or pointers to similar works?

Thanks,
—John

_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Bill Buklis | 8 Feb 20:27
Gravatar

[multi_array] Accessing elements via an iterator

Given this simple definition for multi_array:

struct data
{
     int value;
};

typedef boost::multi_array<data, 3> array_type;

array_type    a;

Can someone tell me why pointer dereferencing, i.e. operator->, an 
element does not successfully compile? Normal derefencing does work, 
i.e. operator*. Am I doing something wrong or is this a problem with 
multi_array?

For example:

// Successfully compiles
(*a.begin()->begin()->begin()).value = 10;

// Does NOT compile
a.begin()->begin()->begin()->value = 10;

I'm using MSVC 2010 and it returns an error that "pointer to reference 
is illegal". I'm using multi_array from the trunk section.

--

-- 
Bill

Gmane