4#ifndef __multicontact_api_serialization_archive_hpp__
5#define __multicontact_api_serialization_archive_hpp__
7#include <boost/archive/binary_iarchive.hpp>
8#include <boost/archive/binary_oarchive.hpp>
9#include <boost/archive/text_iarchive.hpp>
10#include <boost/archive/text_oarchive.hpp>
11#include <boost/archive/xml_iarchive.hpp>
12#include <boost/archive/xml_oarchive.hpp>
13#include <boost/serialization/version.hpp>
22#define MULTICONTACT_API_DEFINE_CLASS_TEMPLATE_VERSION(Template, Type) \
24 namespace serialization { \
26 struct version<Type> { \
27 static constexpr unsigned int value = API_VERSION; \
30 constexpr unsigned int version<Type>::value; \
35namespace serialization {
37template <
class Derived>
40 Derived& derived() {
return *
static_cast<Derived*
>(
this); }
41 const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
46 std::ifstream ifs(filename.c_str());
48 boost::archive::text_iarchive ia(ifs);
51 const std::string exception_message(filename +
52 " does not seem to be a valid file.");
53 throw std::invalid_argument(exception_message);
59 std::ofstream ofs(filename.c_str());
61 boost::archive::text_oarchive oa(ofs);
64 const std::string exception_message(filename +
65 " does not seem to be a valid file.");
66 throw std::invalid_argument(exception_message);
71 void loadFromXML(
const std::string& filename,
const std::string& tag_name) {
72 assert(!tag_name.empty());
73 std::ifstream ifs(filename.c_str());
75 boost::archive::xml_iarchive ia(ifs);
76 ia >> boost::serialization::make_nvp(tag_name.c_str(), derived());
78 const std::string exception_message(filename +
79 " does not seem to be a valid file.");
80 throw std::invalid_argument(exception_message);
86 const std::string& tag_name)
const {
87 assert(!tag_name.empty());
88 std::ofstream ofs(filename.c_str());
90 boost::archive::xml_oarchive oa(ofs);
91 oa << boost::serialization::make_nvp(tag_name.c_str(), derived());
93 const std::string exception_message(filename +
94 " does not seem to be a valid file.");
95 throw std::invalid_argument(exception_message);
101 std::ifstream ifs(filename.c_str());
103 boost::archive::binary_iarchive ia(ifs);
106 const std::string exception_message(filename +
107 " does not seem to be a valid file.");
108 throw std::invalid_argument(exception_message);
114 std::ofstream ofs(filename.c_str());
116 boost::archive::binary_oarchive oa(ofs);
119 const std::string exception_message(filename +
120 " does not seem to be a valid file.");
121 throw std::invalid_argument(exception_message);
const unsigned int API_VERSION
Definition archive.hpp:18