Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2019-11-01 15:50:48


On 11/1/19 4:46 AM, Pritam Gharat via Boost-users wrote:
> Hi Robert,
>
> I have gone through the documentation. Below is the list of things I did
> for serialization and deserialization.
>
> 1. Define serialize function in the class whose instances I wish to
> serialize. In my example it is ObjectNew which has pointers of type
> Bar_A and Foo_A. Both are base classes and the pointers of these
> pointers point to instances of theri derived classes.
Not sure I'm getting this. So we have
        struct Bar_A_base ...
        struct Foo_A_base ...

        struct Bar_A_derived : public Bar_A_base ...
        struct Foo_A_base : public Bar_A_base ...

        struct ObjectNew {
                Bar_A_base *m_bar_a;
                Foo_A_base *m_foo_a;
                ...
                template<class Archive>
                void serialize(Archive & ar, const unsigned in version){
                        ar & m_bar_a;
                        ar & m_foo_a;
                }
        };

Right?

> So I have
> serialize function defined for Bar_A, Foo_A and all their derived
> classes (which includes Foo_C, Foo_D, Bar_B, Bar_C).
sounds good
> 2. Call to boost::serialization::base_object in the serialize function
> of derived classes which in turn calls serialize function of the
> corresponding base classes.
sounds good
> 3. For classes with non-defualt constructor, I have over-ridden
> save_construct_data and load_construct_data functions.
sounds good
> 4. Registering derived classes whose instances are pointed by pointers
> with types of their base classes using BOOST_CLASS_EXPORT.
sounds good
> 5. And finally use boost::archive::text_oarchive and
> boost::archive::text_iarchive for serialization and deserialization.

sounds good
> Please let me know if I have missed something or I am doing something wrong.

That sounds about right.
>
> Pritam Gharat
>
> On Thu, Oct 31, 2019 at 5:13 PM Robert Ramey via Boost-users
> <boost-users_at_[hidden] <mailto:boost-users_at_[hidden]>> wrote:
>
> Have you read the documentation?
>
> Robert Ramey
>
> On 10/31/19 2:47 AM, Pritam Gharat via Boost-users wrote:
> > Hi,
> >
> > I am using Boost to serialize pointers of a base class which
> points to
> > instances  of a derived template class. I am using boost 1.7.0 and
> > running it on Ubuntu 16.04.
> >
> > The source code of the example is available at
> > https://github.com/PritamMG/Boost-Serialization-Example
> >
> > My example has a base class Bar_A (definition available in
> > include/Abstract.hpp) which has a virtual function toStr(). It
> has two
> > derived classes Bar_B and Bar_C. Bar_B is a template class.
> > I have registered the derived classes in sc/Test.cpp. Class
> ObjectNew
> > (include/Object.hpp) has a member pointer of type Bar_A which
> points to
> > instances of classes Bar_B and Bar_C.
> >
> > I get an error as "unregistered class".  I am not sure for which
> class
> > do I get this error message.
> >
> > There is also an issue of non-default. If Bar_B does not have a
> default
> > constructor, save_construct_data and load_construct_data are
> over-ridden
> > and there I run into an error "too many template-parameter-lists".
> >
> > How do I define these functions?
> >
> > Thanks,
> > Pritam
> >
> >
> >
> >
> > _______________________________________________
> > Boost-users mailing list
> > Boost-users_at_[hidden] <mailto:Boost-users_at_[hidden]>
> > https://lists.boost.org/mailman/listinfo.cgi/boost-users
> >
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden] <mailto:Boost-users_at_[hidden]>
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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