473,763 Members | 7,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_ABSTRA CT(IBase)
--------------------------------

---------------------------
class derived : public IBase
{
friend class boost::serializ ation::access;

template <class Archive>
void serialize(Archi ve & ar, const unsigned int version )
{
//...
}
}
BOOST_CLASS_EXP ORT_GUID(derive d, "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(dlle xport)
create(IShapesF actory* 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 4460
On Dec 11, 2:51 pm, MindWrapper <ydruga...@gmai l.comwrote:
boost serialization of polymorph classes from DLLs

Folks,

Let's consider following code
--------------------------------
// base.h
// abstract base class
class IBase
{

}

BOOST_IS_ABSTRA CT(IBase)
--------------------------------

---------------------------
class derived : public IBase
{
friend class boost::serializ ation::access;

template <class Archive>
void serialize(Archi ve & ar, const unsigned int version )
{
//...
}

}

BOOST_CLASS_EXP ORT_GUID(derive d, "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(dlle xport)
create(IShapesF actory* 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
982
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 projects: Proj1 and Proj2. Each project compiled to dll.
16
2614
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 years now. The first two postings in this group this morning are addressed almost trivially by using libraries from www.boost.org. IMO, the functionality in boost increases the usability of C++ at least as much as the standard library does. ...
2
2528
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 files only. Although implementing one is easy, I would like to have one that has already been tested... Thanks,
0
1059
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 projects: Proj1 and Proj2. Each project compiled to dll.
6
1763
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 with prior beta releases of boost-1.33.1 or with the VC8.0 beta. You may want to consider whether the crash of a dependent tool should be allowed to cause the entire VC8 IDE to hang or whether this might be a design defect. Given the recent price...
2
6631
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 are not a language-supported structure, they are platform-specific. -mod } I'm trying to use boost serialization to serialize/deserialize data to and from a mmap'd file. I have my own ostream/istream classes that essentially read/write bytes...
0
2110
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: #include <iostream> #include <fstream> #include <string> #include <boost/archive/xml_iarchive.hpp>
1
11100
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
2
5565
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 I am trying to read from a binary archive using Boost serialization. I am new to this, and it is possible that I have not understood the usage. In the code below, the string "faultblock" seems to be causing the problem. The code crashes in the ia...
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9997
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9937
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7366
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.