Boost logo

Boost Users :

From: Jeshua Bratman (bratman_at_[hidden])
Date: 2007-08-09 15:07:06


I've been trying to get Boost serialization working for dynamically loaded
shared libraries. Here's my basic structure simplified:

1. base.hpp - includes an abstract base class called base
2. derived.hpp - includes a derived class from base. includes base.hpp.
3. derived.cpp - includes code for derived class and for dynamically loading
it
4. main.cpp - includes base.hpp but NOT derived.hpp. dynamically loads
instantiates a base * which points to a derived object from derived.so

Now in main I want to be able to serialize my pointer to the loaded derived
class:

  base *obj = create_func(); //obj now points to a derived object
  obj->test(); //when test is run it correctly outputs the message from
derived.cpp

  const base *to_serialize = obj; //it seems to want a const pointer in
order to serialize
  std::ofstream ofs("filename");
  boost::archive::text_oarchive oa(ofs);
  oa << (*to_serialize);

main.cpp compiles fine, but when it gets to the last line there, the
serialize method in base is called, not the one in derived.

I read
http://www.boost.org/libs/serialization/doc/serialization.html#derivedpointers
http://www.boost.org/libs/serialization/doc/serialization.html#derivedpointers
but it doesn't seem to address this problem (unless I missed something?). I
can't use the BOOST_CLASS_EXPORT_GUID(derived, "derived") macro discussed on
that page because main does not know what a derived object is (this is the
whole point of having this plugin system).

Is there any way I can make boost serialization correctly serialize the
derived class from the base pointer when the derived object is known only to
a dynamically loaded library?

Thank you for your help,
Jeshua Bratman

-- 
View this message in context: http://www.nabble.com/Boost-Serialization-with-a-dynamically-loaded-shared-library-tf4238910.html#a12061401
Sent from the Boost - Users mailing list archive at Nabble.com.

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