Verified Commit 208535da authored by Justin Carpentier's avatar Justin Carpentier
Browse files

serialization: load and save streamsteam

parent 4be4d0d1
......@@ -77,6 +77,38 @@ namespace pinocchio
throw std::invalid_argument(exception_message);
}
}
///
/// \brief Loads an object from std::stringstream.
///
/// \tparam T Type of the object to deserialize.
///
/// \param[out] object Object in which the loaded data are copied.
/// \param[in] is string stream constaining the serialized content of the object.
///
template<typename T>
inline void loadFromStringStream(T & object,
std::istringstream & is)
{
boost::archive::text_iarchive ia(is,boost::archive::no_codecvt);
ia >> object;
}
///
/// \brief Saves an object inside a std::stringstream.
///
/// \tparam T Type of the object to deserialize.
///
/// \param[in] object Object in which the loaded data are copied.
/// \param[out] ss String stream constaining the serialized content of the object.
///
template<typename T>
inline void saveToStringStream(const T & object,
std::stringstream & ss)
{
boost::archive::text_oarchive oa(ss);
oa & object;
}
///
/// \brief Loads an object from a XML file.
......
......@@ -38,6 +38,19 @@ void generic_test(const T & object,
BOOST_CHECK(object_loaded == object);
}
// Load and save as string stream
std::stringstream ss_out;
saveToStringStream(object,ss_out);
{
T object_loaded;
std::istringstream is(ss_out.str());
loadFromStringStream(object_loaded,is);
// Check
BOOST_CHECK(object_loaded == object);
}
// Load and save as XML
const std::string xml_filename = filename + ".xml";
saveToXML(object,xml_filename,tag_name);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment