4#ifndef __curves_serialization_archive_hpp__
5#define __curves_serialization_archive_hpp__
6#include <boost/archive/binary_iarchive.hpp>
7#include <boost/archive/binary_oarchive.hpp>
8#include <boost/archive/text_iarchive.hpp>
9#include <boost/archive/text_oarchive.hpp>
10#include <boost/archive/xml_iarchive.hpp>
11#include <boost/archive/xml_oarchive.hpp>
12#include <boost/serialization/version.hpp>
23#define SINGLE_ARG(...) \
27#define DEFINE_CLASS_TEMPLATE_VERSION(Template, Type) \
29 namespace serialization { \
31 struct version<Type> { \
32 static constexpr unsigned int value = CURVES_API_VERSION; \
35 constexpr unsigned int version<Type>::value; \
40namespace serialization {
43 template <
class Derived>
45 return *
static_cast<Derived*
>(
this);
47 template <
class Derived>
48 const Derived& derived()
const {
49 return *
static_cast<const Derived*
>(
this);
54 template <
class Derived>
58 boost::archive::text_iarchive
ia(
ifs);
62 " does not seem to be a valid file.");
68 template <
class Derived>
72 boost::archive::text_oarchive
oa(
ofs);
76 " does not seem to be a valid file.");
82 template <
class Derived>
85 throw std::invalid_argument(
"tag_name cannot be empty.");
89 boost::archive::xml_iarchive
ia(
ifs);
94 " does not seem to be a valid file.");
100 template <
class Derived>
102 const std::string&
tag_name)
const {
104 throw std::invalid_argument(
"tag_name cannot be empty.");
108 boost::archive::xml_oarchive
oa(
ofs);
109 oa << boost::serialization::make_nvp(
tag_name.c_str(),
113 " does not seem to be a valid file.");
119 template <
class Derived>
121 std::ifstream
ifs(
filename.c_str(), std::ios::binary);
123 boost::archive::binary_iarchive
ia(
ifs);
127 " does not seem to be a valid file.");
133 template <
class Derived>
135 std::ofstream
ofs(
filename.c_str(), std::ios::binary);
137 boost::archive::binary_oarchive
oa(
ofs);
141 " does not seem to be a valid file.");
const unsigned int CURVES_API_VERSION
Definition archive.hpp:21
Definition bernstein.h:20
bool isApprox(const T a, const T b, const T eps=1e-6)
Definition curve_abc.h:25
Definition archive.hpp:41
void loadFromXML(const std::string &filename, const std::string &tag_name)
Loads a Derived object from an XML file.
Definition archive.hpp:83
void saveAsBinary(const std::string &filename) const
Saved a Derived object as an binary file.
Definition archive.hpp:134
void saveAsText(const std::string &filename) const
Saved a Derived object as a text file.
Definition archive.hpp:69
void loadFromBinary(const std::string &filename)
Loads a Derived object from an binary file.
Definition archive.hpp:120
void saveAsXML(const std::string &filename, const std::string &tag_name) const
Saved a Derived object as an XML file.
Definition archive.hpp:101
void loadFromText(const std::string &filename)
Loads a Derived object from a text file.
Definition archive.hpp:55