Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stack Of Tasks
pinocchio
Commits
41c9cbd1
Verified
Commit
41c9cbd1
authored
Nov 16, 2019
by
Justin Carpentier
Browse files
serialization: load and save from and to string
parent
208535da
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/serialization/archive.hpp
View file @
41c9cbd1
...
...
@@ -79,7 +79,7 @@ namespace pinocchio
}
///
/// \brief Loads an object from std::stringstream.
/// \brief Loads an object from
a
std::stringstream.
///
/// \tparam T Type of the object to deserialize.
///
...
...
@@ -109,6 +109,39 @@ namespace pinocchio
boost
::
archive
::
text_oarchive
oa
(
ss
);
oa
&
object
;
}
///
/// \brief Loads an object from a std::string
///
/// \tparam T Type of the object to deserialize.
///
/// \param[out] object Object in which the loaded data are copied.
/// \param[in] str string constaining the serialized content of the object.
///
template
<
typename
T
>
inline
void
loadFromString
(
T
&
object
,
const
std
::
string
&
str
)
{
std
::
istringstream
is
(
str
);
loadFromStringStream
(
object
,
is
);
}
///
/// \brief Saves an object inside a std::string
///
/// \tparam T Type of the object to deserialize.
///
/// \param[in] object Object in which the loaded data are copied.
/// \param[out] str String constaining the serialized content of the object.
///
template
<
typename
T
>
inline
void
saveToString
(
const
T
&
object
,
std
::
string
&
str
)
{
std
::
stringstream
ss
;
saveToStringStream
(
object
,
ss
);
str
=
ss
.
str
();
}
///
/// \brief Loads an object from a XML file.
...
...
unittest/serialization.cpp
View file @
41c9cbd1
...
...
@@ -51,6 +51,19 @@ void generic_test(const T & object,
BOOST_CHECK
(
object_loaded
==
object
);
}
// Load and save as string
std
::
string
str_out
;
saveToString
(
object
,
str_out
);
{
T
object_loaded
;
std
::
string
str_in
(
str_out
);
loadFromString
(
object_loaded
,
str_in
);
// Check
BOOST_CHECK
(
object_loaded
==
object
);
}
// Load and save as XML
const
std
::
string
xml_filename
=
filename
+
".xml"
;
saveToXML
(
object
,
xml_filename
,
tag_name
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment