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?
Yes. Something similar to that. I am attaching the header files for the class definitions.
> 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@lists.boost.org <mailto:boost-users@lists.boost.org>> 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@lists.boost.org <mailto:Boost-users@lists.boost.org>
> > https://lists.boost.org/mailman/listinfo.cgi/boost-users
> >
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users@lists.boost.org <mailto:Boost-users@lists.boost.org>
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users@lists.boost.org
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
>
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
https://lists.boost.org/mailman/listinfo.cgi/boost-users