5 #ifndef __pinocchio_serialization_archive_hpp__ 6 #define __pinocchio_serialization_archive_hpp__ 8 #include "pinocchio/serialization/fwd.hpp" 9 #include "pinocchio/serialization/static-buffer.hpp" 15 #include <boost/archive/text_oarchive.hpp> 16 #include <boost/archive/text_iarchive.hpp> 17 #include <boost/archive/xml_iarchive.hpp> 18 #include <boost/archive/xml_oarchive.hpp> 19 #include <boost/archive/binary_iarchive.hpp> 20 #include <boost/archive/binary_oarchive.hpp> 22 #if BOOST_VERSION / 100 % 1000 == 78 && __APPLE__ 25 #ifndef BOOST_ASIO_DISABLE_STD_ALIGNED_ALLOC 26 #define DEFINE_BOOST_ASIO_DISABLE_STD_ALIGNED_ALLOC 27 #define BOOST_ASIO_DISABLE_STD_ALIGNED_ALLOC 30 #include <boost/asio/streambuf.hpp> 32 #ifdef DEFINE_BOOST_ASIO_DISABLE_STD_ALIGNED_ALLOC 33 #undef BOOST_ASIO_DISABLE_STD_ALIGNED_ALLOC 37 #include <boost/asio/streambuf.hpp> 40 #include <boost/iostreams/device/array.hpp> 41 #include <boost/iostreams/stream.hpp> 42 #include <boost/iostreams/stream_buffer.hpp> 45 #include <boost/math/special_functions/nonfinite_num_facets.hpp> 62 const std::string & filename)
64 std::ifstream ifs(filename.c_str());
67 std::locale
const new_loc(ifs.getloc(),
new boost::math::nonfinite_num_get<char>);
69 boost::archive::text_iarchive ia(ifs,boost::archive::no_codecvt);
74 const std::string exception_message(filename +
" does not seem to be a valid file.");
75 throw std::invalid_argument(exception_message);
89 const std::string & filename)
91 std::ofstream ofs(filename.c_str());
94 boost::archive::text_oarchive oa(ofs);
99 const std::string exception_message(filename +
" does not seem to be a valid file.");
100 throw std::invalid_argument(exception_message);
114 std::istringstream & is)
116 boost::archive::text_iarchive ia(is,boost::archive::no_codecvt);
130 std::stringstream & ss)
132 boost::archive::text_oarchive oa(ss);
146 const std::string & str)
148 std::istringstream is(str);
164 std::stringstream ss;
180 const std::string & filename,
181 const std::string & tag_name)
185 std::ifstream ifs(filename.c_str());
188 std::locale
const new_loc(ifs.getloc(),
new boost::math::nonfinite_num_get<char>);
190 boost::archive::xml_iarchive ia(ifs,boost::archive::no_codecvt);
195 const std::string exception_message(filename +
" does not seem to be a valid file.");
196 throw std::invalid_argument(exception_message);
211 const std::string & filename,
212 const std::string & tag_name)
216 std::ofstream ofs(filename.c_str());
219 boost::archive::xml_oarchive oa(ofs);
224 const std::string exception_message(filename +
" does not seem to be a valid file.");
225 throw std::invalid_argument(exception_message);
239 const std::string & filename)
241 std::ifstream ifs(filename.c_str(), std::ios::binary);
244 boost::archive::binary_iarchive ia(ifs);
249 const std::string exception_message(filename +
" does not seem to be a valid file.");
250 throw std::invalid_argument(exception_message);
264 const std::string & filename)
266 std::ofstream ofs(filename.c_str(), std::ios::binary);
269 boost::archive::binary_oarchive oa(ofs);
274 const std::string exception_message(filename +
" does not seem to be a valid file.");
275 throw std::invalid_argument(exception_message);
289 boost::asio::streambuf & buffer)
291 boost::archive::binary_iarchive ia(buffer);
305 boost::asio::streambuf & buffer)
307 boost::archive::binary_oarchive oa(buffer);
324 boost::iostreams::stream_buffer< boost::iostreams::basic_array<char> > stream(buffer.
data(), buffer.
size());
326 boost::archive::binary_iarchive ia(stream);
343 boost::iostreams::stream_buffer< boost::iostreams::basic_array<char> > stream(buffer.
data(), buffer.
size());
345 boost::archive::binary_oarchive oa(stream);
352 #endif // ifndef __pinocchio_serialization_archive_hpp__
void saveToBinary(const T &object, const std::string &filename)
Saves an object inside a binary file.
void loadFromXML(T &object, const std::string &filename, const std::string &tag_name)
Loads an object from a XML file.
void saveToStringStream(const T &object, std::stringstream &ss)
Saves an object inside a std::stringstream.
std::string saveToString(const T &object)
Saves an object inside a std::string.
void saveToText(const T &object, const std::string &filename)
Saves an object inside a TXT file.
char * data()
Returns the pointer on the data.
Static buffer with pre-allocated memory.
size_t size() const
Returns the current size of the buffer.
void loadFromText(T &object, const std::string &filename)
Loads an object from a TXT file.
const nvp< typename pinocchio::container::aligned_vector< T >::vector_base > make_nvp(const char *name, pinocchio::container::aligned_vector< T > &t)
void loadFromString(T &object, const std::string &str)
Loads an object from a std::string.
void loadFromStringStream(T &object, std::istringstream &is)
Loads an object from a std::stringstream.
Main pinocchio namespace.
void saveToXML(const T &object, const std::string &filename, const std::string &tag_name)
Saves an object inside a XML file.
void loadFromBinary(T &object, const std::string &filename)
Loads an object from a binary file.
#define PINOCCHIO_CHECK_INPUT_ARGUMENT(...)
Macro to check an assert-like condition and throw a std::invalid_argument exception (with a message) ...