Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] deriving from xml_iarchive
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-04-19 13:10:19


OK- here goes:

a) make your own class my_helper and put it into a header file
b) start with boost/archive/xml_iarchive.hpp
c) where it says #include <boost/archive/shared_ptr_helper.hpp>
add another line "#include "my_helper"
d) where it says public detail::shared_ptr_helper
add ", my_helper
e) recompile xml_iarchive.cpp

good luck,

Robert Ramey

Kenny Riddile wrote:
> Both me and another dev have read all the relevant
> documentation/examples and still can't make this work. Would it be
> possible to get a simple example...maybe an input archive that behaves
> exactly like xml_iarchive and lets you pass an additional int to the
> constructor and retrieve it later via something like
> myArchive.GetStoredInt() ?
>
> Robert Ramey wrote:
>> I think the best way to handle this is by making an archive helper.
>>
>> If you look into the implemenation of ..._oarchive, you'll see that
>> it looks something like the following:
>>
>>
>> class xml_oarchive : public naked_xml_oarchive, shared_ptr_helper
>> {... This is to implement special facility for shared_ptr which would
>> otherwise not be serializable. (note: this is the only case where
>> the archive classes address issues related to the implemenation
>> of a particular type).
>>
>> You could do something similar for your own "special" type.
>>
>> Look in the documentaion under "case studies" for a
>> more complete explanation.
>>
>> Robert Ramey
>>
>> Kenny Riddile wrote:
>>> I have a situation where I want an additional piece of data to be
>>> owned by the archive type we're using. Previously, I had this
>>> typedef that's used throughout our code:
>>>
>>> typedef boost::archive::xml_iarchive IutputArchive;
>>>
>>> I changed it to something like this:
>>>
>>> class InputArchive : public boost::archive::xml_iarchive
>>> {
>>> public:
>>> InputArchive( std::istream& is, Foo bar )
>>> : boost::archive::xml_iarchive( is )
>>> , m_bar( bar )
>>>
>>> Foo GetFoo() const
>>> {
>>> return m_bar;
>>> }
>>>
>>> private:
>>> Foo m_bar;
>>> };
>>>
>>> The problem I'm seeing is that whenever a serializable class's
>>> serialize() method is invoked via an InputArchive object, the
>>> template parameter to serialize() is instantiated with
>>> boost::archive::xml_iarchive, not InputArchive, which I need. Is it
>>> possible to get the behavior I want through public derivation like
>>> this, or is there a better way?


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net