473,398 Members | 2,404 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,398 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 4430
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.