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, \ 58 mrpt::typemeta::TTypeName<T>::get().c_str()); \ 63 obj.begin(), obj.end(), \ 64 metaprogramming::ObjectReadFromStream(&in)); \ 70 typename T::value_type,
71 std::pair<const typename T::key_type, typename T::mapped_type>>;
74 using is_map = std::is_same<
76 typename T::key_type,
typename T::mapped_type,
77 typename T::key_compare,
typename T::allocator_type>>;
81 T,
typename std::multimap<
82 typename T::key_type,
typename T::mapped_type,
83 typename T::key_compare,
typename T::allocator_type>>;
93 return "std::multimap";
100 out << containerName<T>()
103 std::decay_t<typename T::mapped_type>>::get();
104 out << static_cast<uint32_t>(
obj.size());
105 for (
typename T::const_iterator it =
obj.begin(); it !=
obj.end(); ++it)
106 out << it->first << it->second;
116 if (pref != containerName<T>())
118 "Error: serialized container %s<%s,%s>'s preamble is " 120 containerName<T>().c_str(),
129 "Error: serialized container %s key type %s != %s",
130 containerName<T>().c_str(), stored_K.c_str(),
137 "Error: serialized container %s value type %s != %s",
138 containerName<T>().c_str(), stored_V.c_str(),
144 typename T::key_type key_obj;
148 typename T::iterator it_new =
obj.insert(
149 obj.end(), std::make_pair(key_obj,
typename T::mapped_type()));
150 in >> it_new->second;
155 #define MRPTSTL_SERIALIZABLE_SIMPLE_ASSOC_CONTAINER(CONTAINER) \ 157 template <class K, class _Pr, class _Alloc> \ 158 CArchive& operator<<(CArchive& out, const CONTAINER<K, _Pr, _Alloc>& obj) \ 160 out << std::string(#CONTAINER) << mrpt::typemeta::TTypeName<K>::get(); \ 161 out << static_cast<uint32_t>(obj.size()); \ 162 for (typename CONTAINER<K, _Pr, _Alloc>::const_iterator it = \ 164 it != obj.end(); ++it) \ 169 template <class K, class _Pr, class _Alloc> \ 170 CArchive& operator>>(CArchive& in, CONTAINER<K, _Pr, _Alloc>& obj) \ 173 std::string pref, stored_K; \ 175 if (pref != #CONTAINER) \ 176 THROW_EXCEPTION(format( \ 177 "Error: serialized container %s<%s>'s preamble is wrong: " \ 179 #CONTAINER, mrpt::typemeta::TTypeName<K>::get().c_str(), \ 183 std::string(mrpt::typemeta::TTypeName<K>::get().c_str())) \ 184 THROW_EXCEPTION(format( \ 185 "Error: serialized container %s key type %s != %s", \ 186 #CONTAINER, stored_K.c_str(), \ 187 mrpt::typemeta::TTypeName<K>::get().c_str())); \ 190 for (uint32_t i = 0; i < n; i++) \ 194 obj.insert(key_obj); \ 207 template <
class T,
size_t N>
218 template <
class T,
size_t N>
223 in >> pref >> stored_N;
224 if (pref !=
"std::array" || stored_N != N)
226 "Error: serialized container %s's preambles is wrong: " 233 "Error: serialized container std::array< %s != %s >",
241 template <
class T1,
class T2>
246 out <<
obj.first <<
obj.second;
250 template <
class T1,
class T2>
255 if (pref !=
"std::pair")
257 "Error: serialized std::pair<%s,%s>'s preamble is wrong: '%s'",
263 "Error: serialized std::pair first type %s != %s", stored_K.c_str(),
268 "Error: serialized std::pair second type %s != %s",
std::string containerName()
#define THROW_EXCEPTION(msg)
GLsizei GLsizei GLuint * obj
std::is_same< T, typename std::multimap< typename T::key_type, typename T::mapped_type, typename T::key_compare, typename T::allocator_type > > is_multimap
std::is_same< typename T::value_type, std::pair< const typename T::key_type, typename T::mapped_type > > is_map_like
#define MRPTSTL_SERIALIZABLE_SEQ_CONTAINER(CONTAINER)
GLsizei const GLchar ** string
CArchive & operator>>(CArchive &s, mrpt::aligned_std_vector< float > &a)
std::is_same< T, typename std::map< typename T::key_type, typename T::mapped_type, typename T::key_compare, typename T::allocator_type > > is_map
Virtual base class for "archives": classes abstracting I/O streams.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
CArchive & operator<<(CArchive &s, const mrpt::aligned_std_vector< float > &a)
GLsizei const GLfloat * value
#define MRPTSTL_SERIALIZABLE_SIMPLE_ASSOC_CONTAINER(CONTAINER)
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
unsigned __int32 uint32_t