1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| #include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/serialization/list.hpp>
BOOST_STRONG_TYPEDEF( int, tracked_int )
BOOST_CLASS_IS_WRAPPER( int )
template <class T>
void serialize( T& ar, tracked_int& my_int, unsigned int const )
{ ar & (int&)my_int; }
class gps_position
{
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int)
{
ar & BOOST_SERIALIZATION_NVP( degrees );
ar & BOOST_SERIALIZATION_NVP( minutes );
ar & BOOST_SERIALIZATION_NVP( seconds );
ar & BOOST_SERIALIZATION_NVP( list );
}
int degrees;
int minutes;
float seconds;
typedef std::list<tracked_int*> list_type;
list_type list;
public:
gps_position(void) {};
gps_position(int d, int m, float s, list_type v) :
degrees(d), minutes(m), seconds(s), list(v) {}
};
int main(void)
{
std::ofstream ofs("/home/ether/a/temp");
std::list<tracked_int*> v;
v.push_back( new tracked_int( 1 ) );
v.push_back( new tracked_int( 2 ) );
gps_position g(35, 59, 24.567f, v);
{
boost::archive::xml_oarchive oa(ofs);
oa << BOOST_SERIALIZATION_NVP( g );
}
gps_position newg;
{
std::ifstream ifs("/home/ether/a/temp");
boost::archive::xml_iarchive ia(ifs);
ia >> BOOST_SERIALIZATION_NVP( newg );
}
return 0;
} |
Partager