Boost logo

Boost :

From: Scott Woods (scott.suzuki_at_[hidden])
Date: 2008-05-25 19:26:59


Hi Brian,

Apologies to other list members. I am experiencing very odd mail service
that
means I am not receiving messages on the Boost list sent by myself. Here's a
brief response to Brian while I try to figure things out.

----- Original Message -----
From: "brass goowy" <brass_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Monday, May 26, 2008 10:43 AM
Subject: Re: [boost]Question regarding logging, persistence,
threadcommunication, network messaging and async frameworks

> Scott Woods writes:
>>Hi,
>>Is there a place in Boost for a library that tackles all of the above? I
>>believe the realistic
>>answer is no but I would be happy to be proven wrong.
>>Work in the different areas mentioned in the subject line recently
>>collapsed
>>into a single
>>underlying technique. Given the example UDT below;
>>struct person
>>{
>>std::string name;
>>std::vector<unsigned> score;
>>std::set<string> team;
>>};

<snip>

>>actually this is precisely the most compelling thing about the library -
>>it
>>reduces code
>>that traditionally can be quite difficult into fragments such as those
>>shown.
>
> Shalom
>
>>From what you've shown it looks like the duplication of data members
> in serialization methods is not needed. Some have been struggling to
> eliminate the need for that duplication --
> http://preview.tinyurl.com/6kpx8t .
> Maybe more details about codec_object<> would be helpful.

I'm not so sure about that ;-) but in good faith;

    struct object_stack
    {
         typedef file_device device_type;
         typedef transfer_block<device_type> transfer_type;
         typedef binary_run_codec<transfer_type> codec_type;
    };

    // Declaration of the left side (the device+transfer+object)
    // of the transfer.

    template<typename V,typename S=object_stack>
    struct codec_object
    {
         typedef V value_type;
         typedef S::codec_type codec_type;

        type_hash type;
        std::string base_name;
        std::string name_to_open;
        codec_type codec;

        void
        decorate( const std::string &s )
        {
            name_to_open = base_name = s;

            name_to_open += '.';
            name_to_open += codec.codec_tag();
        }

        codec_object() :
        type( type_of<value_type>::hash() )
        {}

        codec_object( const std::string &k ) :
        type( type_of<value_type>::hash() )
        {
            decorate( k );
        }

        void
        change_to( const std::string &k )
        {
            decorate( k );
        }
    };

I looked through the thread at "for each member of a sturcture/class ?" and
not
sure how to respond; the issue being dealt with in that thread (while
interesting) is
subordinate to my goals.

I do not have any magic technique for avoiding duplication of member
information. Any C++ type that wishes to play within my library
must define the following two global operators;

    inline network_variant &
    operator<<( network_variant &nv, const person &p )
    {
        network_memory::iterator i = network_output<3>()( nv );
        *i++ << p.name;
        *i++ << p.score;
        *i++ << p.team;
        return nv;
    }

    inline person &
    operator>>( network_variant &nv, person &p )
    {
        network_memory::iterator i = network_input<3>()( nv );
        *i++ >> p.name;
        *i++ >> p.score;
        *i++ >> p.team;
        return p;
    }

My library for persistence, thread communication and network messaging
deals with the movement and representation of "network_variants", i.e.
by providing transform functions as above, the type acquires persistence,
transfer-between-threads and transfer-across-networks capabilities, in
one hit.

There is more to say in this area (type declaration) but I'm not sure that
either
of us was actually headed there.

Scott.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk