27 #include <boost/serialization/optional.hpp> 28 #include <boost/serialization/shared_ptr.hpp> 29 #include <boost/serialization/vector.hpp> 30 #include <boost/serialization/map.hpp> 31 #include <boost/serialization/list.hpp> 32 #include <boost/serialization/deque.hpp> 33 #include <boost/serialization/weak_ptr.hpp> 35 #include <boost/archive/text_oarchive.hpp> 36 #include <boost/archive/text_iarchive.hpp> 37 #include <boost/archive/xml_iarchive.hpp> 38 #include <boost/archive/xml_oarchive.hpp> 39 #include <boost/archive/binary_iarchive.hpp> 40 #include <boost/archive/binary_oarchive.hpp> 41 #include <boost/serialization/export.hpp> 47 std::string serialize(
const T& input) {
48 std::ostringstream out_archive_stream;
49 boost::archive::text_oarchive out_archive(out_archive_stream);
51 return out_archive_stream.str();
55 void deserialize(
const std::string& serialized, T& output) {
56 std::istringstream in_archive_stream(serialized);
57 boost::archive::text_iarchive in_archive(in_archive_stream);
62 bool serializeToFile(
const T& input,
const std::string& filename) {
63 std::ofstream out_archive_stream(filename.c_str());
64 if (!out_archive_stream.is_open())
66 boost::archive::text_oarchive out_archive(out_archive_stream);
68 out_archive_stream.close();
73 bool deserializeFromFile(
const std::string& filename, T& output) {
74 std::ifstream in_archive_stream(filename.c_str());
75 if (!in_archive_stream.is_open())
77 boost::archive::text_iarchive in_archive(in_archive_stream);
79 in_archive_stream.close();
85 std::string serializeXML(
const T& input,
const std::string& name=
"data") {
86 std::ostringstream out_archive_stream;
91 boost::archive::xml_oarchive out_archive(out_archive_stream);
92 out_archive << boost::serialization::make_nvp(name.c_str(), input);
94 return out_archive_stream.str();
98 void deserializeXML(
const std::string& serialized, T& output,
const std::string& name=
"data") {
99 std::istringstream in_archive_stream(serialized);
100 boost::archive::xml_iarchive in_archive(in_archive_stream);
101 in_archive >> boost::serialization::make_nvp(name.c_str(), output);
105 bool serializeToXMLFile(
const T& input,
const std::string& filename,
const std::string& name=
"data") {
106 std::ofstream out_archive_stream(filename.c_str());
107 if (!out_archive_stream.is_open())
109 boost::archive::xml_oarchive out_archive(out_archive_stream);
110 out_archive << boost::serialization::make_nvp(name.c_str(), input);;
111 out_archive_stream.close();
116 bool deserializeFromXMLFile(
const std::string& filename, T& output,
const std::string& name=
"data") {
117 std::ifstream in_archive_stream(filename.c_str());
118 if (!in_archive_stream.is_open())
120 boost::archive::xml_iarchive in_archive(in_archive_stream);
121 in_archive >> boost::serialization::make_nvp(name.c_str(), output);
122 in_archive_stream.close();
128 std::string serializeBinary(
const T& input,
const std::string& name=
"data") {
129 std::ostringstream out_archive_stream;
130 boost::archive::binary_oarchive out_archive(out_archive_stream);
131 out_archive << boost::serialization::make_nvp(name.c_str(), input);
132 return out_archive_stream.str();
136 void deserializeBinary(
const std::string& serialized, T& output,
const std::string& name=
"data") {
137 std::istringstream in_archive_stream(serialized);
138 boost::archive::binary_iarchive in_archive(in_archive_stream);
139 in_archive >> boost::serialization::make_nvp(name.c_str(), output);
143 bool serializeToBinaryFile(
const T& input,
const std::string& filename,
const std::string& name=
"data") {
144 std::ofstream out_archive_stream(filename.c_str());
145 if (!out_archive_stream.is_open())
147 boost::archive::binary_oarchive out_archive(out_archive_stream);
148 out_archive << boost::serialization::make_nvp(name.c_str(), input);
149 out_archive_stream.close();
154 bool deserializeFromBinaryFile(
const std::string& filename, T& output,
const std::string& name=
"data") {
155 std::ifstream in_archive_stream(filename.c_str());
156 if (!in_archive_stream.is_open())
158 boost::archive::binary_iarchive in_archive(in_archive_stream);
159 in_archive >> boost::serialization::make_nvp(name.c_str(), output);
160 in_archive_stream.close();
Global functions in a separate testing namespace.
Definition: chartTesting.h:28