7#ifndef COAL_SERIALIZATION_ARCHIVE_H
8#define COAL_SERIALIZATION_ARCHIVE_H
12#include <boost/serialization/nvp.hpp>
13#include <boost/archive/text_iarchive.hpp>
14#include <boost/archive/text_oarchive.hpp>
15#include <boost/archive/xml_iarchive.hpp>
16#include <boost/archive/xml_oarchive.hpp>
17#include <boost/archive/binary_iarchive.hpp>
18#include <boost/archive/binary_oarchive.hpp>
25#if BOOST_VERSION / 100 % 1000 == 78 && __APPLE__
29#ifndef BOOST_ASIO_DISABLE_STD_ALIGNED_ALLOC
30#define DEFINE_BOOST_ASIO_DISABLE_STD_ALIGNED_ALLOC
31#define BOOST_ASIO_DISABLE_STD_ALIGNED_ALLOC
34#include <boost/asio/streambuf.hpp>
36#ifdef DEFINE_BOOST_ASIO_DISABLE_STD_ALIGNED_ALLOC
37#undef BOOST_ASIO_DISABLE_STD_ALIGNED_ALLOC
41#include <boost/asio/streambuf.hpp>
44#include <boost/iostreams/device/array.hpp>
45#include <boost/iostreams/stream.hpp>
46#include <boost/iostreams/stream_buffer.hpp>
49#include <boost/math/special_functions/nonfinite_num_facets.hpp>
52namespace serialization {
64 std::ifstream ifs(filename.c_str());
66 std::locale
const new_loc(ifs.getloc(),
67 new boost::math::nonfinite_num_get<char>);
69 boost::archive::text_iarchive ia(ifs, boost::archive::no_codecvt);
72 const std::string exception_message(filename +
73 " does not seem to be a valid file.");
74 throw std::invalid_argument(exception_message);
87inline void saveToText(
const T&
object,
const std::string& filename) {
88 std::ofstream ofs(filename.c_str());
90 boost::archive::text_oarchive oa(ofs);
93 const std::string exception_message(filename +
94 " does not seem to be a valid file.");
95 throw std::invalid_argument(exception_message);
110 std::locale
const new_loc(is.getloc(),
111 new boost::math::nonfinite_num_get<char>);
113 boost::archive::text_iarchive ia(is, boost::archive::no_codecvt);
128 boost::archive::text_oarchive oa(ss);
142 std::istringstream is(str);
157 std::stringstream ss;
173 const std::string& tag_name) {
174 if (filename.empty()) {
178 std::ifstream ifs(filename.c_str());
180 std::locale
const new_loc(ifs.getloc(),
181 new boost::math::nonfinite_num_get<char>);
183 boost::archive::xml_iarchive ia(ifs, boost::archive::no_codecvt);
184 ia >> boost::serialization::make_nvp(tag_name.c_str(),
object);
186 const std::string exception_message(filename +
187 " does not seem to be a valid file.");
188 throw std::invalid_argument(exception_message);
202inline void saveToXML(
const T&
object,
const std::string& filename,
203 const std::string& tag_name) {
204 if (filename.empty()) {
208 std::ofstream ofs(filename.c_str());
210 boost::archive::xml_oarchive oa(ofs);
211 oa& boost::serialization::make_nvp(tag_name.c_str(),
object);
213 const std::string exception_message(filename +
214 " does not seem to be a valid file.");
215 throw std::invalid_argument(exception_message);
229 std::ifstream ifs(filename.c_str(), std::ios::binary);
231 boost::archive::binary_iarchive ia(ifs);
234 const std::string exception_message(filename +
235 " does not seem to be a valid file.");
236 throw std::invalid_argument(exception_message);
250 std::ofstream ofs(filename.c_str(), std::ios::binary);
252 boost::archive::binary_oarchive oa(ofs);
255 const std::string exception_message(filename +
256 " does not seem to be a valid file.");
257 throw std::invalid_argument(exception_message);
271 boost::archive::binary_iarchive ia(buffer);
285 boost::archive::binary_oarchive oa(buffer);
#define COAL_THROW_PRETTY(message, exception)
Definition fwd.hh:64
void loadFromBuffer(T &object, boost::asio::streambuf &buffer)
Loads an object from a binary buffer.
Definition archive.h:270
void loadFromBinary(T &object, const std::string &filename)
Loads an object from a binary file.
Definition archive.h:228
void loadFromText(T &object, const std::string &filename)
Loads an object from a TXT file.
Definition archive.h:63
void loadFromXML(T &object, const std::string &filename, const std::string &tag_name)
Loads an object from a XML file.
Definition archive.h:172
void loadFromString(T &object, const std::string &str)
Loads an object from a std::string.
Definition archive.h:141
void saveToXML(const T &object, const std::string &filename, const std::string &tag_name)
Saves an object inside a XML file.
Definition archive.h:202
void loadFromStringStream(T &object, std::istringstream &is)
Loads an object from a std::stringstream.
Definition archive.h:109
void saveToText(const T &object, const std::string &filename)
Saves an object inside a TXT file.
Definition archive.h:87
void saveToStringStream(const T &object, std::stringstream &ss)
Saves an object inside a std::stringstream.
Definition archive.h:127
void saveToBinary(const T &object, const std::string &filename)
Saves an object inside a binary file.
Definition archive.h:249
std::string saveToString(const T &object)
Saves an object inside a std::string.
Definition archive.h:156
void saveToBuffer(const T &object, boost::asio::streambuf &buffer)
Saves an object to a binary buffer.
Definition archive.h:284
Main namespace.
Definition broadphase_bruteforce.h:44