12 #ifndef __UT_SERIALIZATION_H_INCLUDED__
13 #define __UT_SERIALIZATION_H_INCLUDED__
101 #include <type_traits>
112 template <
typename ARCHIVER_T,
typename OBJ_T>
116 return obj.serialize(archiver);
123 template <
typename ARCHIVER_T,
typename OBJ_T>
131 template <
typename ARCHIVER_T,
typename OBJ_T>
145 template <
typename OBJ_T>
148 template <
typename ARCHIVER_T>
149 static bool invoke(ARCHIVER_T &archiver, OBJ_T &obj)
154 template <
typename OBJ_T>
157 template <
typename ARCHIVER_T>
158 static bool invoke(ARCHIVER_T &archiver, OBJ_T &obj)
166 #define UT_DECLARE_SERIALIZABLE(OBJ_T) \
167 template <typename ARCHIVER_T> \
168 bool UTserialize(ARCHIVER_T &archiver, OBJ_T &obj) \
170 return archiver.serializeValue(obj); \
181 #undef UT_DECLARE_SERIALIZABLE
184 template <
typename ARCHIVER_T>
188 return archiver.serializeStringValue(str);
190 template <
typename ARCHIVER_T>
195 if (!archiver.serializeStringValue(buf))
200 template <
typename ARCHIVER_T>
204 return archiver.serializeStringValue(str.
buffer());
206 template <
typename ARCHIVER_T>
210 return archiver.serializeStringValue(str);
212 template <
typename ARCHIVER_T>
216 return archiver.serializeStringValue(str.
c_str());
218 template <
typename ARCHIVER_T>
223 if (!archiver.serializeStringValue(buf))
233 template <
typename T,
template <
typename>
class ARRAY>
236 template <
typename ARCHIVER_T>
237 static bool invoke(ARCHIVER_T &archiver, ARRAY<T> &vec)
239 if (!archiver.serializeArrayBegin(vec.entries()))
241 if (!archiver.serializeArray(vec.array(), vec.entries()))
243 if (!archiver.serializeArrayEnd())
248 template <
typename T,
template <
typename>
class ARRAY>
251 template <
typename ARCHIVER_T>
252 static bool invoke(ARCHIVER_T &archiver, ARRAY<T> &vec)
255 if (!archiver.serializeArrayBegin(count))
258 if (!archiver.serializeArray(vec.array(), vec.entries()))
260 if (!archiver.serializeArrayEnd())
265 #define UT_DECLARE_ARRAY_SERIALIZABLE(ARRAY_T) \
266 template <typename T> \
267 struct UT_SaveSerializable< ARRAY_T<T> > \
268 : public UT_ArraySaveSerializable<T, ARRAY_T> { }; \
269 template <typename T> \
270 struct UT_LoadSerializable< ARRAY_T<T> > \
271 : public UT_ArrayLoadSerializable<T, ARRAY_T> { }; \
275 #undef UT_DECLARE_ARRAY_SERIALIZABLE
279 template <
typename ARCHIVER_T>
286 SaveKeyValue(ARCHIVER_T &archiver)
287 : myArchiver(archiver)
291 template <
typename PAIR_T>
298 if (!myArchiver.serializeKey(get<0>(p)))
307 ARCHIVER_T & myArchiver;
314 template <
typename T>
317 ARCHIVER_T *subclass =
static_cast<ARCHIVER_T *
>(
this);
330 template <
typename SEQ_T>
333 ARCHIVER_T *subclass =
static_cast<ARCHIVER_T *
>(
this);
334 if (!subclass->serializeMapBegin())
336 SaveKeyValue saver(*subclass);
339 if (!subclass->serializeMapEnd())
346 template <
typename ARCHIVER_T>
353 LoadKeyValue(ARCHIVER_T &archiver,
const char *key,
bool &ok)
354 : myArchiver(archiver)
361 template <
typename PAIR_T>
368 if (::strcmp(myKey, get<0>(p)) != 0)
380 ARCHIVER_T & myArchiver;
390 template <
typename T>
393 ARCHIVER_T *subclass =
static_cast<ARCHIVER_T *
>(
this);
406 template <
typename SEQ_T>
410 ARCHIVER_T * subclass =
static_cast<ARCHIVER_T *
>(
this);
414 for (keep_going = subclass->serializeMapBegin();
416 keep_going = !subclass->serializeMapEnd())
418 if (!subclass->serializeKey(key))
420 LoadKeyValue loader(*subclass, key.
buffer(), ok);
434 template <
typename OBJ_T,
typename ARCHIVER_T>
452 template <
typename OBJ_T,
typename ARCHIVER_T>
462 typename ARCHIVER_T::Input archiver(in);
473 template <
typename OBJ_T,
typename ARCHIVER_T>
475 operator<<(UT_OStream &out, UT_SaveArchiverManip<OBJ_T,ARCHIVER_T> manip)
480 template <
typename OBJ_T,
typename ARCHIVER_T>
487 #endif // __UT_SERIALIZATION_H_INCLUDED__
GLenum GLuint GLenum GLsizei const GLchar * buf
bool operator()(const SEQ_T &pair_seq)
bool operator()(const SEQ_T &pair_seq)
static bool invoke(ARCHIVER_T &archiver, OBJ_T &obj)
SYS_FORCE_INLINE const char * buffer() const
bool serializeArray(T *vec, int64 count)
bool serializeArray(T *vec, int64 count)
UT_IStream & operator>>(UT_IStream &in, UT_LoadArchiverManip< OBJ_T, ARCHIVER_T > manip)
UT_IStream manipulator >> overload.
bool UTtupleAnyOf(T &&tuple, F &&f)
Base class for archivers.
static bool invoke(ARCHIVER_T &archiver, ARRAY< T > &vec)
void harden()
Take shallow copy and make it deep.
#define UT_DECLARE_ARRAY_SERIALIZABLE(ARRAY_T)
SYS_FORCE_INLINE const char * c_str() const
#define UT_DECLARE_SERIALIZABLE(OBJ_T)
UT_LoadArchiverManip(OBJ_T &obj)
UT_OStream & operator()(UT_OStream &out)
void setError(bool is_error)
static bool invoke(ARCHIVER_T &archiver, ARRAY< T > &vec)
bool UTserializeSave(ARCHIVER_T &archiver, OBJ_T &obj)
bool UTserialize(ARCHIVER_T &archiver, OBJ_T &obj)
UT_SaveArchiverManip(OBJ_T &obj)
static bool invoke(ARCHIVER_T &archiver, OBJ_T &obj)
Manipulators for streaming archivers.
UT_IStream & operator()(UT_IStream &in)
bool UTserializeLoad(ARCHIVER_T &archiver, OBJ_T &obj)
void setstate(std::ios::iostate state)