7 #ifndef HPP_FCL_SERIALIZATION_ARCHIVE_H
8 #define HPP_FCL_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>
53 namespace serialization {
65 std::ifstream ifs(filename.c_str());
67 std::locale
const new_loc(ifs.getloc(),
68 new boost::math::nonfinite_num_get<char>);
70 boost::archive::text_iarchive ia(ifs, boost::archive::no_codecvt);
73 const std::string exception_message(filename +
74 " does not seem to be a valid file.");
75 throw std::invalid_argument(exception_message);
88 inline void saveToText(
const T&
object,
const std::string& filename) {
89 std::ofstream ofs(filename.c_str());
91 boost::archive::text_oarchive oa(ofs);
94 const std::string exception_message(filename +
95 " does not seem to be a valid file.");
96 throw std::invalid_argument(exception_message);
109 template <
typename T>
111 std::locale
const new_loc(is.getloc(),
112 new boost::math::nonfinite_num_get<char>);
114 boost::archive::text_iarchive ia(is, boost::archive::no_codecvt);
127 template <
typename T>
129 boost::archive::text_oarchive oa(ss);
141 template <
typename T>
143 std::istringstream is(str);
156 template <
typename T>
158 std::stringstream ss;
172 template <
typename T>
174 const std::string& tag_name) {
175 if (filename.empty()) {
177 std::invalid_argument);
180 std::ifstream ifs(filename.c_str());
182 std::locale
const new_loc(ifs.getloc(),
183 new boost::math::nonfinite_num_get<char>);
185 boost::archive::xml_iarchive ia(ifs, boost::archive::no_codecvt);
186 ia >> boost::serialization::make_nvp(tag_name.c_str(),
object);
188 const std::string exception_message(filename +
189 " does not seem to be a valid file.");
190 throw std::invalid_argument(exception_message);
203 template <
typename T>
204 inline void saveToXML(
const T&
object,
const std::string& filename,
205 const std::string& tag_name) {
206 if (filename.empty()) {
208 std::invalid_argument);
211 std::ofstream ofs(filename.c_str());
213 boost::archive::xml_oarchive oa(ofs);
214 oa& boost::serialization::make_nvp(tag_name.c_str(),
object);
216 const std::string exception_message(filename +
217 " does not seem to be a valid file.");
218 throw std::invalid_argument(exception_message);
230 template <
typename T>
232 std::ifstream ifs(filename.c_str(), std::ios::binary);
234 boost::archive::binary_iarchive ia(ifs);
237 const std::string exception_message(filename +
238 " does not seem to be a valid file.");
239 throw std::invalid_argument(exception_message);
251 template <
typename T>
253 std::ofstream ofs(filename.c_str(), std::ios::binary);
255 boost::archive::binary_oarchive oa(ofs);
258 const std::string exception_message(filename +
259 " does not seem to be a valid file.");
260 throw std::invalid_argument(exception_message);
272 template <
typename T>
274 boost::archive::binary_iarchive ia(buffer);
286 template <
typename T>
288 boost::archive::binary_oarchive oa(buffer);
#define HPP_FCL_THROW_PRETTY(message, exception)
Definition: fwd.hh:64
std::string saveToString(const T &object)
Saves an object inside a std::string.
Definition: archive.h:157
void saveToXML(const T &object, const std::string &filename, const std::string &tag_name)
Saves an object inside a XML file.
Definition: archive.h:204
void saveToBinary(const T &object, const std::string &filename)
Saves an object inside a binary file.
Definition: archive.h:252
void loadFromText(T &object, const std::string &filename)
Loads an object from a TXT file.
Definition: archive.h:64
void loadFromBinary(T &object, const std::string &filename)
Loads an object from a binary file.
Definition: archive.h:231
void saveToStringStream(const T &object, std::stringstream &ss)
Saves an object inside a std::stringstream.
Definition: archive.h:128
void loadFromString(T &object, const std::string &str)
Loads an object from a std::string.
Definition: archive.h:142
void loadFromXML(T &object, const std::string &filename, const std::string &tag_name)
Loads an object from a XML file.
Definition: archive.h:173
void loadFromBuffer(T &object, boost::asio::streambuf &buffer)
Loads an object from a binary buffer.
Definition: archive.h:273
void saveToText(const T &object, const std::string &filename)
Saves an object inside a TXT file.
Definition: archive.h:88
void saveToBuffer(const T &object, boost::asio::streambuf &buffer)
Saves an object to a binary buffer.
Definition: archive.h:287
void loadFromStringStream(T &object, std::istringstream &is)
Loads an object from a std::stringstream.
Definition: archive.h:110
Main namespace.
Definition: broadphase_bruteforce.h:44