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);
Definition: archive.hpp:14
Definition: archive.hpp:16
void loadFromBinary(const std::string &filename)
Loads a Derived object from an binary file.
Definition: archive.hpp:78
void saveAsBinary(const std::string &filename) const
Saved a Derived object as an binary file.
Definition: archive.hpp:91
void loadFromXML(const std::string &filename, const std::string &tag_name)
Loads a Derived object from an XML file.
Definition: archive.hpp:49
void saveAsText(const std::string &filename) const
Saved a Derived object as a text file.
Definition: archive.hpp:36
void loadFromText(const std::string &filename)
Loads a Derived object from a text file.
Definition: archive.hpp:23
void saveAsXML(const std::string &filename, const std::string &tag_name) const
Saved a Derived object as an XML file.
Definition: archive.hpp:63