M
MindWrapper
boost serialization of polymorph classes from DLLs
Folks,
Let's consider following code
--------------------------------
// base.h
// abstract base class
class IBase
{
}
BOOST_IS_ABSTRACT(IBase)
--------------------------------
---------------------------
class derived : public IBase
{
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive & ar, const unsigned int version )
{
//...
}
}
BOOST_CLASS_EXPORT_GUID(derived, "derived ");
---------------------------
Main application knows only about IBase and it dynamically loads dll
where class derived is defined. Dll exports some method to create
instance of derived :
---------------------------
IBase* extern "C" __declspec(dllexport)
create(IShapesFactory* pfactory)
{
return new Derived;
};
---------------------------
What I want to figure out is that possible to serialize polymorphic
pointer received in such way
Something like that:
std:fstream ofs("file");
boost::archive::text_oarchive oa(ofs);
IBase* p;
// initialize p using above exported method. So, p points to derived
instance.
oa & p; // ???
As I understood this is in principle impossible, because for each
combination of type and archive following template declared in boost
library must be instantiated
template<class Archive, class T>
inline void serialize(
Archive & ar,
T & t,
const unsigned int file_version
){
// invoke member function for class T
t.serialize(ar, file_version);
}
So for main application template instantiation is not available?
Does anyone have another opinion?
Thank you!
Folks,
Let's consider following code
--------------------------------
// base.h
// abstract base class
class IBase
{
}
BOOST_IS_ABSTRACT(IBase)
--------------------------------
---------------------------
class derived : public IBase
{
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive & ar, const unsigned int version )
{
//...
}
}
BOOST_CLASS_EXPORT_GUID(derived, "derived ");
---------------------------
Main application knows only about IBase and it dynamically loads dll
where class derived is defined. Dll exports some method to create
instance of derived :
---------------------------
IBase* extern "C" __declspec(dllexport)
create(IShapesFactory* pfactory)
{
return new Derived;
};
---------------------------
What I want to figure out is that possible to serialize polymorphic
pointer received in such way
Something like that:
std:fstream ofs("file");
boost::archive::text_oarchive oa(ofs);
IBase* p;
// initialize p using above exported method. So, p points to derived
instance.
oa & p; // ???
As I understood this is in principle impossible, because for each
combination of type and archive following template declared in boost
library must be instantiated
template<class Archive, class T>
inline void serialize(
Archive & ar,
T & t,
const unsigned int file_version
){
// invoke member function for class T
t.serialize(ar, file_version);
}
So for main application template instantiation is not available?
Does anyone have another opinion?
Thank you!