What is BOOST_SERIALIZATION_NVP ? I use a lot the serialization with all STL containers possible and much more complex example than that, i have no pb... (perhaps too complex for the Vc7.1 compiler..) But i never use this macro.... - VDB - "LNK1210: exceeded internal ILK size limit" -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Robert Ramey Sent: 8 juin 2005 12:39 To: boost-users@lists.boost.org Subject: [Boost-users] Re: Boost.Serialization 1.32 trouble reading back an object first serialized in an std::vector then by pointer I'll look at this. Give me a couple of days. Robert Ramey James Conrad wrote:
I'm evaluating the Boost.Serialization for use internal use as an interchange format between a number of loose knit projects, and I've run into a bit of trouble.
I'm using Vc 7.1 in Visual Studio .NET 2003.
It seems to me that, if I serialize an object first in an std::vector, and then serialize it later by pointer, that there is trouble reading it back.
I boiled down the reproduction case to as little code as possible below.
When newPolygon (below) is loaded from the archive, I get a bogus pointer for m_pLastVertex. If I serialize using a binary archive, I hit an assert in basic_iarchive.cpp line 371:
assert(new_cid == cid);
Where cid is 576 and new_cid is 2.
Any help with this would be appriciated,
Thanks in advance, -james conrad
#include <fstream>
#define BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
#include
#include #include
#include class Vector3 { public: Vector3() {} Vector3( float x, float y, float z ) : _x(x), _y(y), _z(z) {}
friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & BOOST_SERIALIZATION_NVP(_x); ar & BOOST_SERIALIZATION_NVP(_y); ar & BOOST_SERIALIZATION_NVP(_z); }
float _x,_y,_z; };
BOOST_CLASS_EXPORT_GUID(Vector3, "Vector3")
class Polygon { public: Polygon() : m_pLastVertex( NULL ) {}
friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & BOOST_SERIALIZATION_NVP(m_vertices); ar & BOOST_SERIALIZATION_NVP(m_pLastVertex); }
void addVertex( const Vector3& vert ) { m_vertices.push_back( vert ); m_pLastVertex = &m_vertices.back(); }
std::vector<Vector3> m_vertices; Vector3* m_pLastVertex; };
BOOST_CLASS_EXPORT_GUID(Polygon, "Polygon")
int main( int argc, char* argv[] ) { // create class instance Polygon poly; poly.addVertex( Vector3( 0.0f, 1.0f, 0.0f ) ); poly.addVertex( Vector3( 1.0f, 0.12565f, 0.2f ) ); poly.addVertex( Vector3( 15.0f, 1.22f, 6.7f ) ); poly.addVertex( Vector3( 1.43f, 1.55f, 2.5f ) );
// create and open a character archive for output std::ofstream ofsx( "testout.xml" ); boost::archive::xml_oarchive oax( ofsx );
// write class instance to archive oax << BOOST_SERIALIZATION_NVP(poly);
// close archive ofsx.close();
Polygon newPoly;
// create and open an archive for input std::ifstream ifs("testout.xml", std::ios::binary); boost::archive::xml_iarchive ia(ifs); // read class state from archive ia >> BOOST_SERIALIZATION_NVP( newPoly ); // close archive ifs.close();
return 0; }
Here is an example of the .xml output:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <!DOCTYPE boost_serialization>
<poly class_id="0" tracking_level="1" version="0" object_id="_0"> <count>4</count> <item class_id="2" tracking_level="1" version="0" object_id="_1"> <_x>0 <_y>1 <_z>0 </item> <item object_id="_2"> <_x>1 <_y>0.12565 <_z>0.2 </item> <item object_id="_3"> <_x>15 <_y>1.22 <_z>6.6999998 </item> <item object_id="_4"> <_x>1.4299999 <_y>1.55 <_z>2.5 </item> </poly>
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users