473,287 Members | 1,399 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

boost serialization of polymorph classes from DLLs

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::ofstream 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!
Dec 11 '07 #1
1 4424
On Dec 11, 2:51 pm, MindWrapper <ydruga...@gmail.comwrote:
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::ofstream 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?
You would be better off posting this to the boost mailing lists.

But, you are right. For your main application, the template function
serialize will not be available because the class and its own
serialization infrastructure lies in the dll loaded dynamically. And
that DLL does not know what archive is to be used because the
serialization would be invoked from the main app.

Since you say that the main application has no knowledge of the
various derived classes, the only option that I see is the DLL
providing the serialization functionality on its own. Can you have
serialize/deserialize functions exported from the DLL that use one (or
as many you wish to support) of the archive types (text/xml/binary)
and the dll has the complete responsibility thereon for the
serialization/deserialization? I am not very sure if that would be
possible but if yes, it still would suffer from the limitation on the
set of supported archive types.
Dec 11 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Yevgeny | last post by:
Hi folks! I have some XML Serialization problem. I searched Internet and found some good info but still can't resolve the problem. I have next situation: I have solution contains 2...
16
by: Jeff Flinn | last post by:
At the risk of raising the OT ire of some here, I'd like to know what might be done to raise the awareness of the boost libraries. I've found boost and it's libraries invaluable in my work for ~5...
2
by: eyal.susser | last post by:
Hi, I'm using the Boost serialization library. Iwant to serialize classes into simple buffers on RAM. There doesn't seem to be a suitable archiver. Am I missing it? The ones I saw were for...
0
by: Yevgeny | last post by:
Hi folks! I have some XML Serialization problem. I searched Internet and found some good info but still can't resolve the problem. I have next situation: I have solution contains 2...
6
by: George M. Garner Jr. | last post by:
VC8.0 crashes while compiling boost-1.33.1 serialization library (or any other library that includes the serialization headers) if code analysis (/analyze) is enabled. This problem did not occur...
2
by: smith4894 | last post by:
{ not sure you're aware of that but there are the newsgroups for all major operating systems. you might want to try asking in the forum 'comp.os.linux.development.apps', since memory-mapped files...
0
by: Abhishek Padmanabh | last post by:
I have been trying out boost's serialization library for the past few days. And I have come across a problem serializing a class that has a reference member. The code is posted as below: ...
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.