27 #define MRPTSTL_SERIALIZABLE_SEQ_CONTAINER(CONTAINER) \ 29 template <class T, class _Ax> \ 30 CArchive& operator<<(CArchive& out, const CONTAINER<T, _Ax>& obj) \ 32 out << std::string(#CONTAINER) << mrpt::typemeta::TTypeName<T>::get(); \ 33 out << static_cast<uint32_t>(obj.size()); \ 35 obj.begin(), obj.end(), \ 36 metaprogramming::ObjectWriteToStream(&out)); \ 40 template <class T, class _Ax> \ 41 CArchive& operator>>(CArchive& in, CONTAINER<T, _Ax>& obj) \ 44 std::string pref, stored_T; \ 46 if (pref != #CONTAINER) \ 47 THROW_EXCEPTION_FMT( \ 48 "Error: serialized container %s<%s>'s preambles is wrong: " \ 50 #CONTAINER, mrpt::typemeta::TTypeName<T>::get().c_str(), \ 54 std::string(mrpt::typemeta::TTypeName<T>::get().c_str())) \ 55 THROW_EXCEPTION_FMT( \ 56 "Error: serialized container %s< %s != %s >", #CONTAINER, \ 57 stored_T.c_str(), mrpt::typemeta::TTypeName<T>::get().c_str()) \ 62 obj.begin(), obj.end(), \ 63 metaprogramming::ObjectReadFromStream(&in)); \ 67 #define MRPTSTL_SERIALIZABLE_ASSOC_CONTAINER(CONTAINER) \ 69 template <class K, class V, class _Pr, class _Alloc> \ 70 CArchive& operator<<( \ 71 CArchive& out, const CONTAINER<K, V, _Pr, _Alloc>& obj) \ 73 out << std::string(#CONTAINER) << mrpt::typemeta::TTypeName<K>::get() \ 74 << mrpt::typemeta::TTypeName<V>::get(); \ 75 out << static_cast<uint32_t>(obj.size()); \ 76 for (typename CONTAINER<K, V, _Pr, _Alloc>::const_iterator it = \ 78 it != obj.end(); ++it) \ 79 out << it->first << it->second; \ 83 template <class K, class V, class _Pr, class _Alloc> \ 84 CArchive& operator>>(CArchive& in, CONTAINER<K, V, _Pr, _Alloc>& obj) \ 87 std::string pref, stored_K, stored_V; \ 89 if (pref != #CONTAINER) \ 92 "Error: serialized container %s<%s,%s>'s preamble is " \ 94 #CONTAINER, mrpt::typemeta::TTypeName<K>::get().c_str(), \ 95 mrpt::typemeta::TTypeName<V>::get().c_str(), \ 99 std::string(mrpt::typemeta::TTypeName<K>::get().c_str())) \ 102 "Error: serialized container %s key type %s != %s", \ 103 #CONTAINER, stored_K.c_str(), \ 104 mrpt::typemeta::TTypeName<K>::get().c_str())) \ 107 std::string(mrpt::typemeta::TTypeName<V>::get().c_str())) \ 110 "Error: serialized container %s value type %s != %s", \ 111 #CONTAINER, stored_V.c_str(), \ 112 mrpt::typemeta::TTypeName<V>::get().c_str())) \ 115 for (uint32_t i = 0; i < n; i++) \ 121 typename CONTAINER<K, V, _Pr, _Alloc>::iterator it_new = \ 122 obj.insert(obj.end(), std::make_pair(key_obj, V())); \ 123 in >> it_new->second; \ 128 #define MRPTSTL_SERIALIZABLE_SIMPLE_ASSOC_CONTAINER(CONTAINER) \ 130 template <class K, class _Pr, class _Alloc> \ 131 CArchive& operator<<(CArchive& out, const CONTAINER<K, _Pr, _Alloc>& obj) \ 133 out << std::string(#CONTAINER) << mrpt::typemeta::TTypeName<K>::get(); \ 134 out << static_cast<uint32_t>(obj.size()); \ 135 for (typename CONTAINER<K, _Pr, _Alloc>::const_iterator it = \ 137 it != obj.end(); ++it) \ 142 template <class K, class _Pr, class _Alloc> \ 143 CArchive& operator>>(CArchive& in, CONTAINER<K, _Pr, _Alloc>& obj) \ 146 std::string pref, stored_K; \ 148 if (pref != #CONTAINER) \ 151 "Error: serialized container %s<%s>'s preamble is wrong: " \ 153 #CONTAINER, mrpt::typemeta::TTypeName<K>::get().c_str(), \ 157 std::string(mrpt::typemeta::TTypeName<K>::get().c_str())) \ 160 "Error: serialized container %s key type %s != %s", \ 161 #CONTAINER, stored_K.c_str(), \ 162 mrpt::typemeta::TTypeName<K>::get().c_str())) \ 165 for (uint32_t i = 0; i < n; i++) \ 169 obj.insert(key_obj); \ 185 template <
class T,
size_t N>
196 template <
class T,
size_t N>
201 in >> pref >> stored_N;
202 if (pref !=
"std::array" || stored_N != N)
204 "Error: serialized container %s's preambles is wrong: " 211 "Error: serialized container std::array< %s != %s >",
219 template <
class T1,
class T2>
224 out <<
obj.first <<
obj.second;
228 template <
class T1,
class T2>
233 if (pref !=
"std::pair")
236 "Error: serialized std::pair<%s,%s>'s preamble is wrong: '%s'",
243 "Error: serialized std::pair first type %s != %s",
249 "Error: serialized std::pair second type %s != %s",
#define THROW_EXCEPTION(msg)
GLsizei GLsizei GLuint * obj
#define MRPTSTL_SERIALIZABLE_SEQ_CONTAINER(CONTAINER)
GLsizei const GLchar ** string
CArchive & operator>>(CArchive &s, mrpt::aligned_std_vector< float > &a)
Virtual base class for "archives": classes abstracting I/O streams.
#define MRPTSTL_SERIALIZABLE_ASSOC_CONTAINER(CONTAINER)
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
#define MRPTSTL_SERIALIZABLE_SIMPLE_ASSOC_CONTAINER(CONTAINER)
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
unsigned __int32 uint32_t