28 #define MRPTSTL_SERIALIZABLE_SEQ_CONTAINER(CONTAINER) \ 30 template <class T, class _Ax> \ 31 CStream& operator<<( \ 32 mrpt::utils::CStream& out, const CONTAINER<T, _Ax>& obj) \ 34 out << std::string(#CONTAINER) << mrpt::utils::TTypeName<T>::get(); \ 35 out << static_cast<uint32_t>(obj.size()); \ 37 obj.begin(), obj.end(), \ 38 mrpt::utils::metaprogramming::ObjectWriteToStream(&out)); \ 42 template <class T, class _Ax> \ 43 CStream& operator>>(mrpt::utils::CStream& in, CONTAINER<T, _Ax>& obj) \ 46 std::string pref, stored_T; \ 48 if (pref != #CONTAINER) \ 49 THROW_EXCEPTION_FMT( \ 50 "Error: serialized container %s<%s>'s preambles is wrong: " \ 52 #CONTAINER, TTypeName<T>::get().c_str(), pref.c_str()) \ 54 if (stored_T != mrpt::utils::TTypeName<T>::get()) \ 55 THROW_EXCEPTION_FMT( \ 56 "Error: serialized container %s< %s != %s >", #CONTAINER, \ 57 stored_T.c_str(), TTypeName<T>::get().c_str()) \ 62 obj.begin(), obj.end(), \ 63 mrpt::utils::metaprogramming::ObjectReadFromStream(&in)); \ 67 #define MRPTSTL_SERIALIZABLE_ASSOC_CONTAINER(CONTAINER) \ 69 template <class K, class V, class _Pr, class _Alloc> \ 70 CStream& operator<<( \ 71 mrpt::utils::CStream& out, const CONTAINER<K, V, _Pr, _Alloc>& obj) \ 73 out << std::string(#CONTAINER) << TTypeName<K>::get() \ 74 << 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 CStream& operator>>( \ 85 mrpt::utils::CStream& in, CONTAINER<K, V, _Pr, _Alloc>& obj) \ 88 std::string pref, stored_K, stored_V; \ 90 if (pref != #CONTAINER) \ 93 "Error: serialized container %s<%s,%s>'s preamble is " \ 95 #CONTAINER, TTypeName<K>::get().c_str(), \ 96 TTypeName<V>::get().c_str(), pref.c_str())) \ 98 if (stored_K != TTypeName<K>::get()) \ 101 "Error: serialized container %s key type %s != %s", \ 102 #CONTAINER, stored_K.c_str(), \ 103 TTypeName<K>::get().c_str())) \ 105 if (stored_V != TTypeName<V>::get()) \ 108 "Error: serialized container %s value type %s != %s", \ 109 #CONTAINER, stored_V.c_str(), \ 110 TTypeName<V>::get().c_str())) \ 113 for (uint32_t i = 0; i < n; i++) \ 119 typename CONTAINER<K, V, _Pr, _Alloc>::iterator it_new = \ 120 obj.insert(obj.end(), std::make_pair(key_obj, V())); \ 121 in >> it_new->second; \ 135 #define MRPTSTL_SERIALIZABLE_SIMPLE_ASSOC_CONTAINER(CONTAINER) \ 137 template <class K, class _Pr, class _Alloc> \ 138 CStream& operator<<( \ 139 mrpt::utils::CStream& out, const CONTAINER<K, _Pr, _Alloc>& obj) \ 141 out << std::string(#CONTAINER) << TTypeName<K>::get(); \ 142 out << static_cast<uint32_t>(obj.size()); \ 143 for (typename CONTAINER<K, _Pr, _Alloc>::const_iterator it = \ 145 it != obj.end(); ++it) \ 150 template <class K, class _Pr, class _Alloc> \ 151 CStream& operator>>( \ 152 mrpt::utils::CStream& in, CONTAINER<K, _Pr, _Alloc>& obj) \ 155 std::string pref, stored_K; \ 157 if (pref != #CONTAINER) \ 160 "Error: serialized container %s<%s>'s preamble is wrong: " \ 162 #CONTAINER, TTypeName<K>::get().c_str(), pref.c_str())) \ 164 if (stored_K != TTypeName<K>::get()) \ 167 "Error: serialized container %s key type %s != %s", \ 168 #CONTAINER, stored_K.c_str(), \ 169 TTypeName<K>::get().c_str())) \ 172 for (uint32_t i = 0; i < n; i++) \ 176 obj.insert(key_obj); \ 187 template <
class T1,
class T2>
188 CStream& operator<<(mrpt::utils::CStream& out, const std::pair<T1, T2>&
obj)
192 out <<
obj.first <<
obj.second;
196 template <
class T1,
class T2>
201 if (pref !=
"std::pair")
204 "Error: serialized std::pair<%s,%s>'s preamble is wrong: '%s'",
211 "Error: serialized std::pair first type %s != %s",
217 "Error: serialized std::pair second type %s != %s",
A template to obtain the type of its argument as a string at compile time.
#define THROW_EXCEPTION(msg)
#define MRPTSTL_SERIALIZABLE_SIMPLE_ASSOC_CONTAINER(CONTAINER)
GLsizei GLsizei GLuint * obj
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
GLsizei const GLchar ** string
MRPTSTL_SERIALIZABLE_SEQ_CONTAINER(std::vector) MRPTSTL_SERIALIZABLE_SEQ_CONTAINER(std
Template method to serialize a STL pair.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define MRPTSTL_SERIALIZABLE_ASSOC_CONTAINER(CONTAINER)
CStream & operator>>(mrpt::utils::CStream &in, char *a)