1 #ifndef __parametric_curves_serialization_archive_hpp__
2 #define __parametric_curves_serialization_archive_hpp__
4 #include <boost/archive/binary_iarchive.hpp>
5 #include <boost/archive/binary_oarchive.hpp>
6 #include <boost/archive/text_iarchive.hpp>
7 #include <boost/archive/text_oarchive.hpp>
8 #include <boost/archive/xml_iarchive.hpp>
9 #include <boost/archive/xml_oarchive.hpp>
15 template <
class Derived>
18 Derived& derived() {
return *
static_cast<Derived*
>(
this); }
19 const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
24 std::ifstream ifs(filename.c_str());
26 boost::archive::text_iarchive ia(ifs);
29 const std::string exception_message(filename +
30 " does not seem to be a valid file.");
31 throw std::invalid_argument(exception_message);
37 std::ofstream ofs(filename.c_str());
39 boost::archive::text_oarchive oa(ofs);
42 const std::string exception_message(filename +
43 " does not seem to be a valid file.");
44 throw std::invalid_argument(exception_message);
49 void loadFromXML(
const std::string& filename,
const std::string& tag_name) {
50 assert(!tag_name.empty());
51 std::ifstream ifs(filename.c_str());
53 boost::archive::xml_iarchive ia(ifs);
54 ia >> boost::serialization::make_nvp(tag_name.c_str(), derived());
56 const std::string exception_message(filename +
57 " does not seem to be a valid file.");
58 throw std::invalid_argument(exception_message);
64 const std::string& tag_name)
const {
65 assert(!tag_name.empty());
66 std::ofstream ofs(filename.c_str());
68 boost::archive::xml_oarchive oa(ofs);
69 oa << boost::serialization::make_nvp(tag_name.c_str(), derived());
71 const std::string exception_message(filename +
72 " does not seem to be a valid file.");
73 throw std::invalid_argument(exception_message);
79 std::ifstream ifs(filename.c_str());
81 boost::archive::binary_iarchive ia(ifs);
84 const std::string exception_message(filename +
85 " does not seem to be a valid file.");
86 throw std::invalid_argument(exception_message);
92 std::ofstream ofs(filename.c_str());
94 boost::archive::binary_oarchive oa(ofs);
97 const std::string exception_message(filename +
98 " does not seem to be a valid file.");
99 throw std::invalid_argument(exception_message);
106 #endif // ifndef __parametric_curves_serialization_archive_hpp__