
Andy Tompkins wrote:
Hi,
If I create a new class, my_class, am I allowed to mark it as follows:
BOOST_CLASS_IMPLEMENTATION ( my_class , boost::serialization::primitive_type )
The comments in level.hpp say that it won't call serialization code, thus I believe (and experience) that I don't need to provide either:
template<class Archive> void my_class::serialize(Archive &ar, const unsigned int version) or template<class Archive> void serialize(Archive &ar, my_class &t, const unsigned int version)
correct.
The comments also say that 'It presumes a member function or template in the archive class that can handle this type.'
correct.
Does this mean that current archives (text, xml, and binary) are not able to use new primitive types without altering the archive to handle the new primitive?
My first answer was "correct"
As I try it, both the text and xml archives use stream operators to convert my_class to a string and archive that. The binary archive casts my_class to a void* and outputs sizeof(my_class) bytes to the archive. It this expected behavior?
But now you make me think about it, It turns out that all the archives mentioned have a default "fallback" for anything marked "primitive". So, a) You could mark anything primitive. b) In binary archives it will still work just by copying/restoring the bitstream c) In text based archives it will work if and only if there are stream << and >> operators for the type. Robert Ramey