[serialization] Difficulty getting serialization to work.
Hi,
I am experiencing difficulties in getting the Boost serialization
library to work. There seems to be an error related to object tracking,
as I am getting BOOST_STATIC_ASSERTION_FAILURE<x>. I am trying to figure
it out using the attached test code. The documentation claims I should
be putting a BOOST_SERIALIZATION_TRACKING() macro in my file (presumably
directly after my class definition). I did a full text search over the
entire source of the library and nowhere did this preprocessor macro
exist. There is a BOOST_CLASS_TRACKING() macro, which I tried putting in
my source with tracking_never. That seems to have made no appreciable
difference.
I have absolutely no idea what I am supposed to do. :(
Any help would be appreciated.
Thanks,
~ Dieter Buys
#include <fstream>
#include
The change I've suggested below should do it. This is explained in the "rationale" section of the manual. Robert Ramey Dieter Buys wrote:
Hi,
I am experiencing difficulties in getting the Boost serialization library to work. There seems to be an error related to object tracking, as I am getting BOOST_STATIC_ASSERTION_FAILURE<x>. I am trying to figure it out using the attached test code. The documentation claims I should be putting a BOOST_SERIALIZATION_TRACKING() macro in my file (presumably directly after my class definition). I did a full text search over the entire source of the library and nowhere did this preprocessor macro exist. There is a BOOST_CLASS_TRACKING() macro, which I tried putting in my source with tracking_never. That seems to have made no appreciable difference.
I have absolutely no idea what I am supposed to do. :( Any help would be appreciated.
Thanks, ~ Dieter Buys
#include <fstream>
#include
#include
#include #include #include class gps_position { private: friend class boost::serialization::access;
template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & degrees; ar & minutes; ar & seconds; }
int degrees; int minutes; float seconds;
public: gps_position() {}; gps_position(int d, int m, float s) : degrees(d), minutes(m), seconds(s) {} }; // BOOST_CLASS_TRACKING(gps_position, track_never)
int main(void) { std::ofstream ofs("serial.txt");
gps_position *g = new gps_position(35, 59, 24.567f); // const gps_position g(35, 59, 24.567f);
const gps_position * const g = new gps_position(35, 59, 24.567f);
{ boost::archive::text_oarchive oa(ofs); oa << g; } delete g;
gps_position *newg; // gps_position newg; { std::ifstream ifs("serial.txt", std::ios::binary); boost::archive::text_iarchive ia(ifs); ia >> newg; } delete newg;
return 0; }
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Thanks Robert,
This is the error I get when I change that line to exactly what you
suggested:
------ Build started: Project: Test, Configuration: Debug Win32 ------
Compiling...
test_serial.cpp
c:\documents and settings\dieter buys\my
documents\libraries\boost_1_33_1\boost\archive\detail\oserializer.hpp(435)
: error C2027: use of undefined type
'boost::serialization::extended_type_info_null<T>'
with
[
T=gps_position
]
c:\documents and settings\dieter buys\my
documents\libraries\boost_1_33_1\boost\archive\detail\oserializer.hpp(467)
: see reference to function template instantiation 'void
boost::archive::detail::save_pointer_type
The change I've suggested below should do it. This is explained in the "rationale" section of the manual.
Robert Ramey
Dieter Buys wrote:
Hi,
I am experiencing difficulties in getting the Boost serialization library to work. There seems to be an error related to object tracking, as I am getting BOOST_STATIC_ASSERTION_FAILURE<x>. I am trying to figure it out using the attached test code. The documentation claims I should be putting a BOOST_SERIALIZATION_TRACKING() macro in my file (presumably directly after my class definition). I did a full text search over the entire source of the library and nowhere did this preprocessor macro exist. There is a BOOST_CLASS_TRACKING() macro, which I tried putting in my source with tracking_never. That seems to have made no appreciable difference.
I have absolutely no idea what I am supposed to do. :( Any help would be appreciated.
Thanks, ~ Dieter Buys
#include <fstream>
#include
#include
#include #include #include class gps_position { private: friend class boost::serialization::access;
template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & degrees; ar & minutes; ar & seconds; }
int degrees; int minutes; float seconds;
public: gps_position() {}; gps_position(int d, int m, float s) : degrees(d), minutes(m), seconds(s) {} }; // BOOST_CLASS_TRACKING(gps_position, track_never)
int main(void) { std::ofstream ofs("serial.txt");
gps_position *g = new gps_position(35, 59, 24.567f); // const gps_position g(35, 59, 24.567f);
const gps_position * const g = new gps_position(35, 59, 24.567f);
{ boost::archive::text_oarchive oa(ofs); oa << g; } delete g;
gps_position *newg; // gps_position newg; { std::ifstream ifs("serial.txt", std::ios::binary); boost::archive::text_iarchive ia(ifs); ia >> newg; } delete newg;
return 0; }
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I just compiled, linked and ran your example on my VC 7.1 one system and it worked just fine. Robert Ramey
Robert Ramey wrote:
I just compiled, linked and ran your example on my VC 7.1 one system and it worked just fine.
Robert Ramey
Hi Robert,
I found a forum thread on GameDev.net
(http://www.gamedev.net/community/forums/topic.asp?topic_id=380003)
which advised me to rearrange the header files so that the archives are
included before the serialization ones, thus:
#include
Ahh - the explains it - I was building with 1.34 to be released "real soon now" Robert Ramey Dieter Buys wrote:
Robert Ramey wrote:
I just compiled, linked and ran your example on my VC 7.1 one system and it worked just fine.
Robert Ramey
Hi Robert,
I found a forum thread on GameDev.net (http://www.gamedev.net/community/forums/topic.asp?topic_id=380003) which advised me to rearrange the header files so that the archives are included before the serialization ones, thus:
#include
#include #include #include
#include #include This solved the problem.
Thanks for your help, ~ Dieter Buys
participants (2)
-
Dieter Buys
-
Robert Ramey