serialization question

Hello..
I have a derived class serialization:
for instance:
class client_request_base {
public:
client_request_base() : _type( 0 ) {}
private:
friend boost::serialization::access;
template< class ARCHIVE >
void serialize( ARCHIVE& ar, const unsigned int version ) {
ar & _type;
}
unsigned int _type;
};
class calc_skip_images_request : public client_request_base {
public:
calc_skip_images_request() : client_request_base( 1 ), _images_client(
0 ) {}
private:
friend boost::serialization::access;
template< class ARCHIVE >
void serialize( ARCHIVE& ar, const unsigned int version ) {
ar & boost::serialization::base_object

I don't know the serialization lib in such details. All I know is that
the code works. But you need the virtual foo() function in the class
declaration and you need to have the BOOST_CLASS_EXPORT macros.
Christian
On 2/6/07, Aljaz
Hello.. I have a derived class serialization: for instance:
class client_request_base { public: client_request_base() : _type( 0 ) {} private: friend boost::serialization::access; template< class ARCHIVE > void serialize( ARCHIVE& ar, const unsigned int version ) { ar & _type; } unsigned int _type; };
class calc_skip_images_request : public client_request_base { public: calc_skip_images_request() : client_request_base( 1 ), _images_client( 0 ) {} private: friend boost::serialization::access; template< class ARCHIVE > void serialize( ARCHIVE& ar, const unsigned int version ) { ar & boost::serialization::base_object
( *this ); ar & _images_client; } unsigned int _images_client; }; Now I wonder.. If I want to use serialization do I have do EXPORT second class? Or set first class to abstract? Like:
BOOST_IS_ABSTRACT( client_request_base ) BOOST_CLASS_EXPORT(calc_skip_images_request)
Im confused which of these two things is needed? When should I use export and when is abstract macro?
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

BOOST_IS_ABSTRACT( client_request_base )
This is used to indicate that client_request_base is an abstract function. Its only necessary for those compilers which can't implement is_abstract type trait correctly. In your case, it might be a problem because client_request_base is in fact NOT an abstract base class. In order to be one, it has to have at least one function of the from = 0. You could remedy this by specifing ~client_request_base() = 0;
BOOST_CLASS_EXPORT(calc_skip_images_request)
This is required to ensure that code for the derived classes is in fact instantiated even though its not otherwise to referred to in the program. It also assigns an external name which is used to communicate which of the derived class must be created when loading.
Im confused which of these two things is needed? When should I use export and when is abstract macro?
Robert Ramey

I have another question.. When I want to export serialized data (derived class) do I have to use pointer or can I use 'referenced object'? std::istringstream archive_stream(data); boost::archive::text_iarchive archive(archive_stream); baseclass *t; archive & t; or can I do: baseclass t; archive & t;

Hello.. Do I have to use pointer when restoring derived class? For instance: std::istringstream archive_stream( archive_data ); boost::archive::binary_iarchive archive( archive_stream ); client_request_base* base; archive & base; Or can I do: client_request_base base; archive & base; Instead?

It needs to be symmetrical. Meaning when you serialize a pointer use a
pointer for the deserialization.
Christian
On 2/7/07, Aljaz
Hello..
Do I have to use pointer when restoring derived class? For instance:
std::istringstream archive_stream( archive_data ); boost::archive::binary_iarchive archive( archive_stream ); client_request_base* base; archive & base;
Or can I do:
client_request_base base; archive & base;
Instead?
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Aljaz
-
Christian Henning
-
Robert Ramey