Boost logo

Boost :

Subject: Re: [boost] Details on boost::serialization
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-08-03 13:02:08


Look into the documention for "no_header" switch on the
archive constructor.

Robert Ramey

Per Nordlöw wrote:
> I haven't found any documentation on the header bits of the archive
> formats supported by boost::serialization. These are added as default
> when I construct binary and text formats. I am especially interested
> in skipping these headers completely in my application, that is
> serializing a char
> should only result in one byte outputted to stream.
>
> Does the headers basic_binary_[io]archive.hpp play any roles in this
> case? I have tried to use them instead by I got some strange error
> messages so these are commented out here.
>
> Thanks in advance,
> Nordlöw
>
> Compileable sample code follows:
>
> #include <fstream>
>
> // #include <boost/archive/basic_text_iarchive.hpp>
> // #include <boost/archive/basic_text_oarchive.hpp>
>
> #include <boost/archive/text_iarchive.hpp>
> #include <boost/archive/text_oarchive.hpp>
>
> #include <boost/archive/binary_iarchive.hpp>
> #include <boost/archive/binary_oarchive.hpp>
>
> class gps_position
> {
> public:
> gps_position() {};
> gps_position(int d, size_t m, float s) : degrees(d), minutes(m),
> seconds(s) {}
> private:
> friend class boost::serialization::access;
> template<class Archive>
> void serialize(Archive & ar, const unsigned int version) { ar &
> degrees & minutes & seconds; }
> int degrees;
> size_t minutes;
> float seconds;
> };
>
> template<class OA, class IA>
> static void test(const gps_position & pos, const char * filename)
> {
> std::ofstream ofs(filename); // create and open a character
> archive for output
> {
> OA oa(ofs);
> oa << pos;
> }
>
> gps_position newg;
> {
> std::ifstream ifs(filename); // create and open an archive for
> input IA ia(ifs);
> ia >> newg;
> }
> }
>
> int main() {
> const gps_position p(35, 59, 24.567f);
>
> // test<boost::archive::basic_text_oarchive,
> // boost::archive::basic_text_iarchive>(p,
> "boost_serialization_basic_text_archive");
>
> test<boost::archive::text_oarchive,
> boost::archive::text_iarchive>(p,
> "boost_serialization_text_archive");
>
> test<boost::archive::binary_oarchive,
> boost::archive::binary_iarchive>(p,
> "boost_serialization_binary_archive");
>
> return 0;
> }
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk