Boost logo

Boost Users :

From: Jeshua Bratman (bratman_at_[hidden])
Date: 2007-08-27 18:09:46


I already sent a message on this topic a few weeks ago, however, my problem
has a changed a bit so I decided to post a new message.

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* const to_serialize = obj;
  std::ofstream ofs("filename");
  boost::archive::text_oarchive oa(ofs);
  try
    {
      oa << (to_serialize);
    }
  catch(exception &e)
    {
      cout << "Exception: " << e.what() << "\n";
    }

It compiles fine and I got past the "unregisterd class" problem, but now
when I try to serialize the pointer an exception is caught:
"Unregistered void cast"

This appears to be a problem with registering the derived pointer type from
the base type when dynamically loaded from a shared library.

However, I do register the derived-base relationship as suggested in the
documentation. The serialize method in derived.hpp is as follows:

  template<class Archive>
  void serialize(Archive & ar, const unsigned int version)
  {

    ar.template register_type(static_cast<derived *>(NULL));
    //ar & boost::serialization::base_object<base>(*this);
    ar & data;
    boost::serialization::void_cast_register(
                                             static_cast<derived *>(NULL),
                                             static_cast<base *>(NULL)
                                             );
  }

If anyone knows the cause of this and/or a solution I would be very
appreciative. I've been working at this for a long time now and I'm almost
ready to write my own simple serialization for my specific purpose.

Thank you for your help,
Jeshua Bratman

-- 
View this message in context: http://www.nabble.com/-boost%3A%3Aserialization--Serializing-Dynamically-Loaded-Libraries---%22Unregistered-Void-Cast%22-tf4338680.html#a12358781
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