Re: [Boost-users] Deriving Serialization classes
Hi Miguel, you can find what you seek in the documentation under Reference, Serializable Concept, Pointers, Pointers to Objects of Derived Classes. Two possibilities: * eiter call ar.register_class<A>() * or use the macro BOOST_CLASS_EXPORT(A) Have fun, Christian Pfligersdorffer Software Engineering EOS GmbH
-----Ursprüngliche Nachricht----- Von: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org]Im Auftrag von Miguel Silvestre Gesendet: Montag, 15. Januar 2007 16:30 An: boost-users@lists.boost.org Betreff: Re: [Boost-users] Deriving Serialization classes
Anyone???
In the boost code I found this comment:
// note:if this exception is thrown, be sure that derived pointer // is either regsitered or exported.
How can I register a class????????
Just make the test without a pointer ant it works just fine.
I've looked at the documentation and it only refers to this
On 1/15/07, Miguel Silvestre
wrote: problem on derivated classes! But I'm not deriving any class. I'm just including the ponter of a class :(
On 1/15/07, Miguel Silvestre
wrote: Ok!!!
Now I'm getting unregistered_class exceptions when trying to seryalize a class that has another class. Like:
class C : public Serializer { typedef Serializer Parent; public: std::string text; A* m_owner; int32 dasse; C():m_owner(0) { text = "Ola sua puta rabeta!"; dasse = 69; }
void Serialize(IArchive& ar, const unsigned int version) { ar.Serialize(dasse); ar.Serialize(text); //ar.Serialize(m_owner); } };
class A : public Serializer { typedef Serializer Parent; public:
void Serialize(IArchive& ar, const unsigned int version) { ar.Serialize(dumbi); ar.Serialize(vectorTest); ar.Serialize(matrix); ar.Serialize(testing); ar.Serialize((void*)test_void, sizeof(Vector3f)); }
int dumbi; float dumbf; Vector2f vectorTest; Matrix33 matrix; C* testing; Vector3f* test_void;
A():dumbi(12), dumbf(69.69f) { testing = new C(); testing->m_owner = this; matrix.SetIdentity(); test_void = new Vector3f(1,2,3); }
A(int dumb1, float dumb2) : dumbi(dumb1), dumbf(dumb2) { testing = new C(); testing->m_owner = this; matrix.SetIdentity(); test_void = new Vector3f(1,2,3); } };
If I comment the line that serializes C object from A (ar.Serialize(testing);) everything works fine. I can serialize Object A. And I can serialiaze the Object C to. But when I have apoibter to C on object A It throws the unregistered_class exception?
Why?
How can I avoid this??? On 1/12/07, Robert Ramey
wrote: Use binary_object.
Robert Ramey
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Miguel Silvestre
-- Miguel Silvestre
-- Miguel Silvestre _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Now I have the Unregister_cast exception :S.
On 1/15/07, Pfligersdorffer, Christian
Hi Miguel,
you can find what you seek in the documentation under Reference, Serializable Concept, Pointers, Pointers to Objects of Derived Classes.
Two possibilities: * eiter call ar.register_class<A>() * or use the macro BOOST_CLASS_EXPORT(A)
Have fun,
Christian Pfligersdorffer Software Engineering EOS GmbH
-----Ursprüngliche Nachricht----- Von: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org]Im Auftrag von Miguel Silvestre Gesendet: Montag, 15. Januar 2007 16:30 An: boost-users@lists.boost.org Betreff: Re: [Boost-users] Deriving Serialization classes
Anyone???
In the boost code I found this comment:
// note:if this exception is thrown, be sure that derived pointer // is either regsitered or exported.
How can I register a class????????
Just make the test without a pointer ant it works just fine.
I've looked at the documentation and it only refers to this
On 1/15/07, Miguel Silvestre
wrote: problem on derivated classes! But I'm not deriving any class. I'm just including the ponter of a class :(
On 1/15/07, Miguel Silvestre
wrote: Ok!!!
Now I'm getting unregistered_class exceptions when trying to seryalize a class that has another class. Like:
class C : public Serializer { typedef Serializer Parent; public: std::string text; A* m_owner; int32 dasse; C():m_owner(0) { text = "Ola sua puta rabeta!"; dasse = 69; }
void Serialize(IArchive& ar, const unsigned int version) { ar.Serialize(dasse); ar.Serialize(text); //ar.Serialize(m_owner); } };
class A : public Serializer { typedef Serializer Parent; public:
void Serialize(IArchive& ar, const unsigned int version) { ar.Serialize(dumbi); ar.Serialize(vectorTest); ar.Serialize(matrix); ar.Serialize(testing); ar.Serialize((void*)test_void, sizeof(Vector3f)); }
int dumbi; float dumbf; Vector2f vectorTest; Matrix33 matrix; C* testing; Vector3f* test_void;
A():dumbi(12), dumbf(69.69f) { testing = new C(); testing->m_owner = this; matrix.SetIdentity(); test_void = new Vector3f(1,2,3); }
A(int dumb1, float dumb2) : dumbi(dumb1), dumbf(dumb2) { testing = new C(); testing->m_owner = this; matrix.SetIdentity(); test_void = new Vector3f(1,2,3); } };
If I comment the line that serializes C object from A (ar.Serialize(testing);) everything works fine. I can serialize Object A. And I can serialiaze the Object C to. But when I have apoibter to C on object A It throws the unregistered_class exception?
Why?
How can I avoid this??? On 1/12/07, Robert Ramey
wrote: Use binary_object.
Robert Ramey
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Miguel Silvestre
-- Miguel Silvestre
-- Miguel Silvestre _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Miguel Silvestre
Could it be the RTTI?
I'm must use RTTI Disabled for my project. I'm reading the
documentation, and trying to use the
BOOST_CLASS_TYPE_INFO
BOOST_CLASS_EXPORT
now, but without any sucess either :S
On 1/15/07, Miguel Silvestre
Now I have the Unregister_cast exception :S.
On 1/15/07, Pfligersdorffer, Christian
wrote: Hi Miguel,
you can find what you seek in the documentation under Reference, Serializable Concept, Pointers, Pointers to Objects of Derived Classes.
Two possibilities: * eiter call ar.register_class<A>() * or use the macro BOOST_CLASS_EXPORT(A)
Have fun,
Christian Pfligersdorffer Software Engineering EOS GmbH
-----Ursprüngliche Nachricht----- Von: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org]Im Auftrag von Miguel Silvestre Gesendet: Montag, 15. Januar 2007 16:30 An: boost-users@lists.boost.org Betreff: Re: [Boost-users] Deriving Serialization classes
Anyone???
In the boost code I found this comment:
// note:if this exception is thrown, be sure that derived pointer // is either regsitered or exported.
How can I register a class????????
Just make the test without a pointer ant it works just fine.
I've looked at the documentation and it only refers to this
On 1/15/07, Miguel Silvestre
wrote: problem on derivated classes! But I'm not deriving any class. I'm just including the ponter of a class :(
On 1/15/07, Miguel Silvestre
wrote: Ok!!!
Now I'm getting unregistered_class exceptions when trying to seryalize a class that has another class. Like:
class C : public Serializer { typedef Serializer Parent; public: std::string text; A* m_owner; int32 dasse; C():m_owner(0) { text = "Ola sua puta rabeta!"; dasse = 69; }
void Serialize(IArchive& ar, const unsigned int version) { ar.Serialize(dasse); ar.Serialize(text); //ar.Serialize(m_owner); } };
class A : public Serializer { typedef Serializer Parent; public:
void Serialize(IArchive& ar, const unsigned int version) { ar.Serialize(dumbi); ar.Serialize(vectorTest); ar.Serialize(matrix); ar.Serialize(testing); ar.Serialize((void*)test_void, sizeof(Vector3f)); }
int dumbi; float dumbf; Vector2f vectorTest; Matrix33 matrix; C* testing; Vector3f* test_void;
A():dumbi(12), dumbf(69.69f) { testing = new C(); testing->m_owner = this; matrix.SetIdentity(); test_void = new Vector3f(1,2,3); }
A(int dumb1, float dumb2) : dumbi(dumb1), dumbf(dumb2) { testing = new C(); testing->m_owner = this; matrix.SetIdentity(); test_void = new Vector3f(1,2,3); } };
If I comment the line that serializes C object from A (ar.Serialize(testing);) everything works fine. I can serialize Object A. And I can serialiaze the Object C to. But when I have apoibter to C on object A It throws the unregistered_class exception?
Why?
How can I avoid this??? On 1/12/07, Robert Ramey
wrote: Use binary_object.
Robert Ramey
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Miguel Silvestre
-- Miguel Silvestre
-- Miguel Silvestre _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Miguel Silvestre
-- Miguel Silvestre
Try the following:
class A : public Serializer { typedef Serializer Parent; public:
void Serialize(IArchive& ar, const unsigned int version) { ar.template register_type<C>(); ar.Serialize(dumbi); ar.Serialize(vectorTest); ar.Serialize(matrix); ar.Serialize(testing); ar.Serialize((void*)test_void, sizeof(Vector3f)); }
I can't do that.
It gives me a compilation error. My IArchive class is pure virtual and
without templates..
I just don't now how to turn around this mess :P.
Running out of ideas. Recapitulating:
I have a pure virtual class IArchive with the funtions:
virtual void Serialize(int & t) = 0;
...
virtual void Serialize(Serializer& t) = 0;
virtual void Serialize(Serializer* t) = 0;
And my BinaryOArchive extends the IArchive Class and the
binary_oarchive_impl like:
class BinaryArchiveO : public IArchive,
// don't derive from binary_oarchive !!!
public boost::archive::binary_oarchive_impl<BinaryArchiveO>
{
public:
BinaryArchiveO(std::ostream & os, unsigned flags = 0) :
boost::archive::binary_oarchive_impl<BinaryArchiveO>(os, flags)
{}
FE_SERIALIZATION_SERIALIZE;
virtual void Serialize(void * data, size_t size)
{
save_binary(data, size);
}
};
the macro FE_SERIALIZATION_SERIALIZE; is the implementation of the
Serialize basic type functions:
virtual void Serialize(Quaternion& t) { *this & BOOST_SERIALIZATION_NVP(t.q); }\
virtual void Serialize(Serializer* t){*this & BOOST_SERIALIZATION_NVP(t);}
...
And I have the classes I want to serialize derived by the Serializer class:
like:
class C : public Serializer
{
typedef Serializer Parent;
public:
std::string text;
A* m_owner;
int32 dasse;
Vector<float> vector_test;
C():m_owner(0)
{
text = "Ola sua puta rabeta!";
dasse = 69;
vector_test.push_back(1);
vector_test.push_back(1.2f);
vector_test.push_back(1.3f);
vector_test.push_back(1.4f);
}
void Serialize(IArchive& ar, const unsigned int version)
{
//ar.template register_type<C>();
ar.Serialize(dasse);
ar.Serialize(text);
//ar.Serialize(m_owner);
//ar.Serialize(vector_test);
}
};
but if I do something like:
int SilvTask::WriteObject()
{
Serializer* testC = new C();
std::ofstream ofs(m_filename.c_str());
TextArchiveO oa(ofs);
oa & BOOST_SERIALIZATION_NVP(testC);
return FE_OK;
}
It gives me a cast_exception or a class_exception as I said.
:S
On 1/15/07, Robert Ramey
Try the following:
class A : public Serializer { typedef Serializer Parent; public:
void Serialize(IArchive& ar, const unsigned int version) { ar.template register_type<C>(); ar.Serialize(dumbi); ar.Serialize(vectorTest); ar.Serialize(matrix); ar.Serialize(testing); ar.Serialize((void*)test_void, sizeof(Vector3f)); }
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Miguel Silvestre
And here is my Serializer class:
class Serializer : public Object
{
//RTTI_DECLARE;
typedef Object Parent;
public:
virtual void Serialize(IArchive& ar, const unsigned int version) { };
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
Serialize((IArchive&)ar, version);
}
};
On 1/16/07, Miguel Silvestre
I can't do that.
It gives me a compilation error. My IArchive class is pure virtual and without templates..
I just don't now how to turn around this mess :P.
Running out of ideas. Recapitulating:
I have a pure virtual class IArchive with the funtions: virtual void Serialize(int & t) = 0; ... virtual void Serialize(Serializer& t) = 0; virtual void Serialize(Serializer* t) = 0;
And my BinaryOArchive extends the IArchive Class and the binary_oarchive_impl like:
class BinaryArchiveO : public IArchive, // don't derive from binary_oarchive !!! public boost::archive::binary_oarchive_impl<BinaryArchiveO> { public: BinaryArchiveO(std::ostream & os, unsigned flags = 0) : boost::archive::binary_oarchive_impl<BinaryArchiveO>(os, flags) {}
FE_SERIALIZATION_SERIALIZE;
virtual void Serialize(void * data, size_t size) { save_binary(data, size); } };
the macro FE_SERIALIZATION_SERIALIZE; is the implementation of the Serialize basic type functions: virtual void Serialize(Quaternion& t) { *this & BOOST_SERIALIZATION_NVP(t.q); }\ virtual void Serialize(Serializer* t){*this & BOOST_SERIALIZATION_NVP(t);} ...
And I have the classes I want to serialize derived by the Serializer class: like:
class C : public Serializer { typedef Serializer Parent; public: std::string text; A* m_owner; int32 dasse; Vector<float> vector_test;
C():m_owner(0) { text = "Ola sua puta rabeta!"; dasse = 69; vector_test.push_back(1); vector_test.push_back(1.2f); vector_test.push_back(1.3f); vector_test.push_back(1.4f); }
void Serialize(IArchive& ar, const unsigned int version) { //ar.template register_type<C>(); ar.Serialize(dasse); ar.Serialize(text); //ar.Serialize(m_owner); //ar.Serialize(vector_test); } };
but if I do something like:
int SilvTask::WriteObject() { Serializer* testC = new C();
std::ofstream ofs(m_filename.c_str()); TextArchiveO oa(ofs);
oa & BOOST_SERIALIZATION_NVP(testC);
return FE_OK; }
It gives me a cast_exception or a class_exception as I said.
:S
On 1/15/07, Robert Ramey
wrote: Try the following:
> class A : public Serializer > { > typedef Serializer Parent; > public: > > void Serialize(IArchive& ar, const unsigned int version) > { ar.template register_type<C>(); > ar.Serialize(dumbi); > ar.Serialize(vectorTest); > ar.Serialize(matrix); > ar.Serialize(testing); > ar.Serialize((void*)test_void, sizeof(Vector3f)); > } >
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Miguel Silvestre
-- Miguel Silvestre
The following changes would make your classes compatible with all archive types and might well fix your problem. class C : public Serializer { typedef Serializer Parent; public: std::string text; A* m_owner; int32 dasse; Vector<float> vector_test; C():m_owner(0) { text = "Ola sua puta rabeta!"; dasse = 69; vector_test.push_back(1); vector_test.push_back(1.2f); vector_test.push_back(1.3f); vector_test.push_back(1.4f); } // standard way of specifying serialization for a class template<class Archive> serialize(Archive & ar, const unsigned int version){ ar.template register_type<C>(); ar.Serialize(dasse); ar.Serialize(text); //ar.Serialize(m_owner); //ar.Serialize(vector_test); } void Serialize(IArchive& ar, const unsigned int version) { // forward to correct function from virtual call serialize(ar, version); } }; BTW - if you want a virtual function interface to the serialization system you might want to check out "polymorphic archives" in the documentation. Robert Ramey
I've just tried that!
Now I have this compiling warnings:
d:\flow project\flowengine\3rdparty\include\boost\serialization\extended_type_info_typeid.hpp(92)
: warning C4541: 'typeid' used on polymorphic type
'FlowEngine::Serializer' with /GR-; unpredictable behavior may result
d:\flow
project\flowengine\3rdparty\include\boost\serialization\extended_type_info_typeid.hpp(86)
: while compiling class template member function 'const
boost::serialization::extended_type_info
*boost::serialization::detail::extended_type_info_typeid_1<T>::get_derived_extended_type_info(const
FlowEngine::Serializer &)'
with
[
T=const FlowEngine::Serializer
]
d:\flow
project\flowengine\3rdparty\include\boost\serialization\extended_type_info_typeid.hpp(111)
: see reference to class template instantiation
'boost::serialization::detail::extended_type_info_typeid_1<T>' being
compiled
with
[
T=const FlowEngine::Serializer
]
d:\flow
project\flowengine\3rdparty\include\boost\archive\detail\oserializer.hpp(131)
: see reference to class template instantiation
'boost::serialization::extended_type_info_typeid<T>' being compiled
with
[
T=const FlowEngine::Serializer
]
d:\flow
project\flowengine\3rdparty\include\boost\archive\detail\oserializer.hpp(128)
: while compiling class template member function 'bool
boost::archive::detail::oserializer
The following changes would make your classes compatible with all archive types and might well fix your problem.
class C : public Serializer { typedef Serializer Parent; public: std::string text; A* m_owner; int32 dasse; Vector<float> vector_test;
C():m_owner(0) { text = "Ola sua puta rabeta!"; dasse = 69; vector_test.push_back(1); vector_test.push_back(1.2f); vector_test.push_back(1.3f); vector_test.push_back(1.4f); }
// standard way of specifying serialization for a class template<class Archive> serialize(Archive & ar, const unsigned int version){ ar.template register_type<C>(); ar.Serialize(dasse); ar.Serialize(text); //ar.Serialize(m_owner); //ar.Serialize(vector_test); }
void Serialize(IArchive& ar, const unsigned int version) { // forward to correct function from virtual call serialize(ar, version); }
};
BTW - if you want a virtual function interface to the serialization system you might want to check out "polymorphic archives" in the documentation.
Robert Ramey
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Miguel Silvestre
I've looked at your code and the purpose and motivation are totally
incomprehensible to me. I cannot follow it. I see no reason for
a lot of the stuff you do here and a thorough analysis of the compile
time error is really beyond me.
I did take a little bit of time with your main program and recast it
in a form which I believe reflects your intention as well as the way
I would expect most people to find the serialization library useful.
I started out with your main program and comment out parts
which were irrelevant to our question here. I added some
#defines and typedefs for constants and types presumably
specified in other headers.
I've attached my amended copy of your code. I compiles on MSVC 7.1.
I think a more careful study of the documentation demos and tests would
be of value.
I hope this is helpful.
Robert Ramey
begin 666 test_zmisc.cpp
M(VEF(# -"B-I;F-L=61E(")C;W)E+W-Y