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 #include <boost/asio/streambuf.hpp> 23 #include <boost/iostreams/device/array.hpp> 24 #include <boost/iostreams/stream.hpp> 25 #include <boost/iostreams/stream_buffer.hpp> 28 #include <boost/math/special_functions/nonfinite_num_facets.hpp> 45 const std::string & filename)
47 std::ifstream ifs(filename.c_str());
50 std::locale
const new_loc(ifs.getloc(),
new boost::math::nonfinite_num_get<char>);
52 boost::archive::text_iarchive ia(ifs,boost::archive::no_codecvt);
57 const std::string exception_message(filename +
" does not seem to be a valid file.");
58 throw std::invalid_argument(exception_message);
72 const std::string & filename)
74 std::ofstream ofs(filename.c_str());
77 boost::archive::text_oarchive oa(ofs);
82 const std::string exception_message(filename +
" does not seem to be a valid file.");
83 throw std::invalid_argument(exception_message);
97 std::istringstream & is)
99 boost::archive::text_iarchive ia(is,boost::archive::no_codecvt);
113 std::stringstream & ss)
115 boost::archive::text_oarchive oa(ss);
129 const std::string & str)
131 std::istringstream is(str);
147 std::stringstream ss;
163 const std::string & filename,
164 const std::string & tag_name)
168 std::ifstream ifs(filename.c_str());
171 std::locale
const new_loc(ifs.getloc(),
new boost::math::nonfinite_num_get<char>);
173 boost::archive::xml_iarchive ia(ifs,boost::archive::no_codecvt);
178 const std::string exception_message(filename +
" does not seem to be a valid file.");
179 throw std::invalid_argument(exception_message);
194 const std::string & filename,
195 const std::string & tag_name)
199 std::ofstream ofs(filename.c_str());
202 boost::archive::xml_oarchive oa(ofs);
207 const std::string exception_message(filename +
" does not seem to be a valid file.");
208 throw std::invalid_argument(exception_message);
222 const std::string & filename)
224 std::ifstream ifs(filename.c_str(), std::ios::binary);
227 boost::archive::binary_iarchive ia(ifs);
232 const std::string exception_message(filename +
" does not seem to be a valid file.");
233 throw std::invalid_argument(exception_message);
247 const std::string & filename)
249 std::ofstream ofs(filename.c_str(), std::ios::binary);
252 boost::archive::binary_oarchive oa(ofs);
257 const std::string exception_message(filename +
" does not seem to be a valid file.");
258 throw std::invalid_argument(exception_message);
272 boost::asio::streambuf & buffer)
274 boost::archive::binary_iarchive ia(buffer);
288 boost::asio::streambuf & buffer)
290 boost::archive::binary_oarchive oa(buffer);
307 boost::iostreams::stream_buffer< boost::iostreams::basic_array<char> > stream(buffer.
data(), buffer.
size());
309 boost::archive::binary_iarchive ia(stream);
326 boost::iostreams::stream_buffer< boost::iostreams::basic_array<char> > stream(buffer.
data(), buffer.
size());
328 boost::archive::binary_oarchive oa(stream);
335 #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.
size_t size() const
Returns the current size of the buffer.
char * data()
Returns the pointer on the data.
Static buffer with pre-allocated memory.
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) ...