Boost logo

Boost :

From: Thomas Conway (conway_at_[hidden])
Date: 2005-09-27 18:31:13


Hi all,

I'm trying to use the serialization library for the first time and I'm
wondering if there is an extant solution for the problem I'm trying to solve.

I have an application which has dynamicly loaded plugin modules. The
application structure is something like:

main app:

----
class base
{
   ...
   template <class Archive>
   void serialize(Archive& pAr, unsigned int pVer)
   {
     ...
   }
   ...
};
class baseFactory
{
   shared_ptr<base> create(...) = 0;
};
----
plugin:
----
class myPluginN : public base
{
   ...
   template <class Archive>
   void serialize(Archive& pAr, unsigned int pVer)
   {
     ...
   }
};
class myPluginNFactory : public baseFactory
{
   shared_ptr<base> create(...);
};
extern "C" {
   void* makeFactory();
}
----
Now the problem is that by my reading of the serialization library 
documentation, the registration of derived classes is going to present 
difficulties. If I understand things correctly, derived classes need to be 
registered, and the archive contains a "tag" for each derived class. Now in 
this instance the set of derived classes is dynamic, and I don't want to 
require the set of derived classes to be the same in order to be able to load 
a structure. Of course, all the derived classes that are used in the structure 
must be loaded (of course, I'd like to serialization code to attempt to load 
any that are required but not already loaded), but I don't want the archive to 
depend on any derived classes that are not used. So the question really is: is 
this a solved problem? And if so, what is the solution?
Also, the structures contain pointers to members of other structures (e.g.
class Foo
{
   ....
};
class Bar
{
   Foo foo;
};
class Baz
{
   Foo* fooPtr;
};
...
     shared_ptr<Bar> bar(new Bar);
     shared_ptr<Baz> baz(new Baz);
     baz->fooPtr = &(bar->foo);
)
Will the obvious serialization code
Bar::serialize(...)
{
   ar & foo;
}
Baz::serialize(...)
{
   ar & fooPtr;
}
do the right thing?
thanks to anyone who can shed some light,
Tom

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