PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > boost serialization of polymorph classes from DLLs
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
boost serialization of polymorph classes from DLLs

Réponse
 
LinkBack Outils de la discussion
Vieux 11/12/2007, 09h51   #1
MindWrapper
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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: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!
  Réponse avec citation
Vieux 11/12/2007, 15h28   #2
Abhishek Padmanabh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: boost serialization of polymorph classes from DLLs

On Dec 11, 2:51 pm, MindWrapper <ydruga...@gmail.com> wrote:
> 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?


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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h57.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09138 seconds with 10 queries