|
Boost Users : |
Subject: Re: [Boost-users] BoostSerialization callinga customserialize method
From: Robert Ramey (ramey_at_[hidden])
Date: 2010-08-27 13:55:02
Pooyan Dadvand wrote:
> Do you know any boost tool to get the pointer to the derive class
> like this:
>
>
> template<class TArchiveType>
> MyContainer::serialize(TArchiveType &rArchive, const unsigned int
> Version)
> {
>
> boost_tool_to_get_drived_class_pointer(p_variable_data)->MyCustomSerialize(rArchive,
> Version, MyData);
> }
I'm not going to tell you how to do this because doing this won't help you !
Reread the section of the documentation which addresses serialization of
pointers. It
discusses the serialization of an object through a pointer to the virtual
base class
so all you have to do is
base_class *m_bc; // where base class is a virtual base class.
ar << m_dc
The serialization library keeps track of the "true" (most derived) class and
call the serialize
function on THAT class. You don't have to do anything to get what you want.
I would
suggest you look through the tests/examples (there are 50+ in the library!)
and find
one that does this and study it.
> Or tell me how the following code in oserializer.hpp can be used for
> my case
<snip>
the above example ar << m_dc will in fact use that code.
One time we had a similar thread. The final result was
"Oh - this is really simple - once you see it!"
So if what you want to do is NOT simple, you're doing it wrong.
Start make taking one of your types
serialize it
make a small test to prove that it works.
Add the next higher type
and repeat
make a test which does the above through a pointer
and repeat
add a virtual base class
and repeat
Robert Ramey
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