Re: [Boost-users] Deriving Serialization classes

????
a) But I'm deriving it from text_archive_imp
b) what? I didn't understand.. As I said the binary serialization is
working fine
c) Onde again what do you mean?? How can I derivate the serialization classes??
I've tried the following code to, but with the same error:
class TextArchiveO : public IArchive,
// don't derive from text_oarchive !!!
public boost::archive::text_oarchive_impl<TextArchiveO>
{
public:
TextArchiveO(std::ostream & os, unsigned flags = 0) :
boost::archive::text_oarchive_impl<TextArchiveO>(os, flags)
{}
~TextArchiveO(){}
virtual void Serialize(int& t) { *this & BOOST_SERIALIZATION_NVP(t); }
virtual void Serialize(bool& t) { *this & BOOST_SERIALIZATION_NVP(t); }
};
class TextArchiveI : public IArchive,
// don't derive from text_oarchive !!!
public boost::archive::text_iarchive_impl<TextArchiveI>
{
public:
TextArchiveI(std::istream & is, unsigned flags = 0) :
boost::archive::text_iarchive_impl<TextArchiveI>(is,flags)
{}
~TextArchiveI(){}
virtual void Serialize(int& t) { *this & BOOST_SERIALIZATION_NVP(t); }
virtual void Serialize(bool& t) { *this & BOOST_SERIALIZATION_NVP(t); }
};
On 1/10/07, Robert Ramey
-- Miguel Silvestre -- Miguel Silvestre

Miguel Silvestre wrote:
a) But I'm deriving it from text_archive_imp
Sorry, I didn't see that - the IArchive threw me for a loop. Look for the explicit instantiation at the bottom of text_oarchive.cpp. Include something similar in your own code. Robert Ramey

Hummm.. good point.
But now I'm getting these compilation errors:
IT says that the functions template are already defined :S.
I wonder where.....
d:\flow project\flowengine\3rdparty\include\boost\archive\impl\basic_text_oarchive.ipp(48)
: error C2995: 'void
boost::archive::basic_text_oarchive<Archive>::newtoken(void)' :
function template has already been defined
d:\flow
project\flowengine\3rdparty\include\boost\archive\basic_text_oarchive.hpp(72)
: see declaration of
'boost::archive::basic_text_oarchive<Archive>::newtoken'
d:\flow project\flowengine\3rdparty\include\boost\archive\impl\basic_text_oarchive.ipp(59)
: error C2995: 'void
boost::archive::basic_text_oarchive<Archive>::init(void)' : function
template has already been defined
d:\flow
project\flowengine\3rdparty\include\boost\archive\basic_text_oarchive.hpp(103)
: see declaration of
'boost::archive::basic_text_oarchive<Archive>::init'
d:\flow project\flowengine\3rdparty\include\boost\archive\impl\archive_pointer_oserializer.ipp(26)
: error C2995: 'boost::archive::detail::basic_serializer_map
*boost::archive::detail::oserializer_map(void)' : function template
has already been defined
d:\flow
project\flowengine\3rdparty\include\boost\archive\impl\archive_pointer_oserializer.ipp(22)
: see declaration of 'boost::archive::detail::oserializer_map'
d:\flow project\flowengine\3rdparty\include\boost\archive\impl\archive_pointer_oserializer.ipp(38)
: error C2995: 'boost::archive::detail::archive_pointer_oserializer<Archive>::archive_pointer_oserializer(const
boost::serialization::extended_type_info &)' : function template has
already been defined
d:\flow
project\flowengine\3rdparty\include\boost\archive\detail\archive_pointer_oserializer.hpp(40)
: see declaration of
'boost::archive::detail::archive_pointer_oserializer<Archive>::archive_pointer_oserializer'
d:\flow project\flowengine\3rdparty\include\boost\archive\impl\archive_pointer_oserializer.ipp(48)
: error C2995: 'const
boost::archive::detail::basic_pointer_oserializer
*boost::archive::detail::archive_pointer_oserializer<Archive>::find(const
boost::serialization::extended_type_info &)' : function template has
already been defined
d:\flow
project\flowengine\3rdparty\include\boost\archive\detail\archive_pointer_oserializer.hpp(56)
: see declaration of
'boost::archive::detail::archive_pointer_oserializer<Archive>::find'
d:\flow project\flowengine\3rdparty\include\boost\archive\impl\archive_pointer_oserializer.ipp(59)
: error C2995: 'boost::archive::detail::archive_pointer_oserializer<Archive>::~archive_pointer_oserializer(void)'
: function template has already been defined
d:\flow
project\flowengine\3rdparty\include\boost\archive\detail\archive_pointer_oserializer.hpp(48)
: see declaration of
'boost::archive::detail::archive_pointer_oserializer<Archive>::~archive_pointer_oserializer'
On 1/11/07, Robert Ramey
-- Miguel Silvestre

Here is my cpp file
#if (defined _MSC_VER) && (_MSC_VER == 1200)
# pragma warning (disable : 4786) // too long name, harmless warning
#endif
#define BOOST_ARCHIVE_SOURCE
#include "core/system/Precompiled.h"
#include "core/serialization/TextSerializer.h"
// explicitly instantiate for this type of text stream
#include
-- Miguel Silvestre

you've included *.ipp files twice. Once in TextSerializer.h and again in in your instantiation. The *.ipp files shouldn't be in the TextSerializer.h header Robert Ramey

So true! And so stupid of me.... LOL
Ok! It's compiling and running..
But with 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
-- Miguel Silvestre

Another thing!
I've settled that for text binary and xml archives.
Now I want a method that just saves data (binary to the file).
like
void Serialize(void* data, size_t size);
I mean I'm serializing an object but I want to store some data, just store it.
How can I make that? If it is a text or a xml file it's ok. You see
the other members of the object and the void * you see it but just
strange characters.
Thanks
On 1/12/07, Miguel Silvestre
-- Miguel Silvestre

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
-- Miguel Silvestre

Just make the test without a pointer ant it works just fine.
I've looked at the documentation and it only refers to this 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
-- Miguel Silvestre

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????????
On 1/15/07, Miguel Silvestre
-- Miguel Silvestre

Hello,
http://www.boost.org/libs/serialization/doc/serialization.html#registration
I hope this helps.
Regards,
Leon Mergen
http://www.solatis.com
On 1/15/07, Miguel Silvestre
-- Leon Mergen http://www.solatis.com
participants (4)
-
Leon Mergen
-
Matthias Troyer
-
Miguel Silvestre
-
Robert Ramey