26#ifndef TESSERACT_COMMON_SERIALIZATION_H
27#define TESSERACT_COMMON_SERIALIZATION_H
35#include <boost/archive/xml_oarchive.hpp>
36#include <boost/archive/xml_iarchive.hpp>
37#include <boost/archive/binary_oarchive.hpp>
38#include <boost/archive/binary_iarchive.hpp>
39#include <boost/serialization/tracking.hpp>
40#include <boost/serialization/tracking_enum.hpp>
51#define TESSERACT_SERIALIZE_ARCHIVES_INSTANTIATE(Type) \
52 template void Type::serialize(boost::archive::xml_oarchive& ar, const unsigned int version); \
53 template void Type::serialize(boost::archive::xml_iarchive& ar, const unsigned int version); \
54 template void Type::serialize(boost::archive::binary_oarchive& ar, const unsigned int version); \
55 template void Type::serialize(boost::archive::binary_iarchive& ar, const unsigned int version);
58#define TESSERACT_SERIALIZE_SAVE_LOAD_ARCHIVES_INSTANTIATE(Type) \
59 template void Type::serialize(boost::archive::xml_oarchive& ar, const unsigned int version); \
60 template void Type::serialize(boost::archive::xml_iarchive& ar, const unsigned int version); \
61 template void Type::serialize(boost::archive::binary_oarchive& ar, const unsigned int version); \
62 template void Type::serialize(boost::archive::binary_iarchive& ar, const unsigned int version); \
63 template void Type::save(boost::archive::xml_oarchive&, const unsigned int version) const; \
64 template void Type::load(boost::archive::xml_iarchive& ar, const unsigned int version); \
65 template void Type::save(boost::archive::binary_oarchive&, const unsigned int version) const; \
66 template void Type::load(boost::archive::binary_iarchive& ar, const unsigned int version);
69#define TESSERACT_SERIALIZE_SAVE_LOAD_FREE_ARCHIVES_INSTANTIATE(Type) \
70 template void boost::serialization::serialize( \
71 boost::archive::xml_oarchive& ar, Type& g, const unsigned int version); \
72 template void boost::serialization::serialize( \
73 boost::archive::xml_iarchive& ar, Type& g, const unsigned int version); \
74 template void boost::serialization::serialize( \
75 boost::archive::binary_oarchive& ar, Type& g, const unsigned int version); \
76 template void boost::serialization::serialize( \
77 boost::archive::binary_iarchive& ar, Type& g, const unsigned int version); \
78 template void boost::serialization::save( \
79 boost::archive::xml_oarchive&, const Type& g, const unsigned int version); \
80 template void boost::serialization::load( \
81 boost::archive::xml_iarchive& ar, Type& g, const unsigned int version); \
82 template void boost::serialization::save( \
83 boost::archive::binary_oarchive&, const Type& g, const unsigned int version); \
84 template void boost::serialization::load( \
85 boost::archive::binary_iarchive& ar, Type& g, const unsigned int version);
91 template <
typename SerializableType>
96 boost::archive::xml_oarchive
oa(ss);
101 oa << boost::serialization::make_nvp<SerializableType>(
"archive_type",
102 const_cast<SerializableType&
>(archive_type));
104 oa << boost::serialization::make_nvp<SerializableType>(
name.c_str(),
105 const_cast<SerializableType&
>(archive_type));
111 template <
typename SerializableType>
114 const std::string&
name =
"")
117 if (!fp.has_extension())
120 std::ofstream os(fp.string());
122 boost::archive::xml_oarchive
oa(os);
126 oa << boost::serialization::make_nvp<SerializableType>(
"archive_type",
127 const_cast<SerializableType&
>(archive_type));
129 oa << boost::serialization::make_nvp<SerializableType>(
name.c_str(),
130 const_cast<SerializableType&
>(archive_type));
136 template <
typename SerializableType>
139 const std::string&
name =
"")
142 if (!fp.has_extension())
145 std::ofstream os(fp.string(), std::ios_base::binary);
147 boost::archive::binary_oarchive
oa(os);
151 oa << boost::serialization::make_nvp<SerializableType>(
"archive_type",
152 const_cast<SerializableType&
>(archive_type));
154 oa << boost::serialization::make_nvp<SerializableType>(
name.c_str(),
155 const_cast<SerializableType&
>(archive_type));
161 template <
typename SerializableType>
164 SerializableType archive_type;
167 std::stringstream ss(archive_xml);
168 boost::archive::xml_iarchive ia(ss);
175 template <
typename SerializableType>
178 SerializableType archive_type;
183 boost::archive::xml_iarchive ia(ifs);
190 template <
typename SerializableType>
193 SerializableType archive_type;
196 std::ifstream ifs(
file_path, std::ios_base::binary);
198 boost::archive::binary_iarchive ia(ifs);
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Definition: macros.h:71
Definition: create_convex_hull.cpp:36
Definition: allowed_collision_matrix.h:16
tesseract_common::fs::path file_path(__FILE__)
Boost serialization class extension macros and helpers.
Definition: serialization.h:90
static bool toArchiveFileXML(const SerializableType &archive_type, const std::string &file_path, const std::string &name="")
Definition: serialization.h:112
static SerializableType fromArchiveFileBinary(const std::string &file_path)
Definition: serialization.h:191
static SerializableType fromArchiveStringXML(const std::string &archive_xml)
Definition: serialization.h:162
static std::string toArchiveStringXML(const SerializableType &archive_type, const std::string &name="")
Definition: serialization.h:92
static SerializableType fromArchiveFileXML(const std::string &file_path)
Definition: serialization.h:176
static bool toArchiveFileBinary(const SerializableType &archive_type, const std::string &file_path, const std::string &name="")
Definition: serialization.h:137
Definition: serialization_extensions.h:61
Definition: serialization_extensions.h:43
oa<< BOOST_SERIALIZATION_NVP(any_type);} tesseract_common::AnyPoly nany_type;{ std::ifstream ifs(tesseract_common::getTempPath()+"any_type_boost.xml");assert(ifs.good());boost::archive::xml_iarchive ia(ifs);ia > BOOST_SERIALIZATION_NVP(nany_type)
boost::archive::xml_oarchive oa(os)
m name
Definition: tesseract_scene_graph_link_unit.cpp:77