32 #ifndef _CNC_SERIALIZER_H_ 33 #define _CNC_SERIALIZER_H_ 35 #include <cnc/internal/cnc_api.h> 36 #include <cnc/internal/scalable_object.h> 40 #include <cnc/internal/cnc_stddef.h> 46 class CNC_API serializer;
212 template<
class T >
inline 213 void serialize( serializer & buf, T & obj ) {
214 obj.serialize( buf );
224 template<
class T >
inline 238 # define CNC_BITWISE_SERIALIZABLE( T ) \ 239 static inline CnC::bitwise_serializable serializer_category( const T * ) { \ 240 return CnC::bitwise_serializable(); \ 245 template<
class A,
class B >
inline 247 buf & obj.first & obj.second;
282 template<
class T,
class Allocator = std::allocator< T > >
285 chunk( T *& arr, size_type len ) : m_arrVar( arr ), m_len( len ) {}
286 template<
template<
class I >
class Range,
class J >
287 chunk( T *& arr,
const Range< J > & range )
288 : m_arrVar( arr ), m_len( range.size() )
290 CNC_ASSERT( range.begin() == 0 );
302 # define CNC_POINTER_SERIALIZABLE( T ) \ 304 static inline void serialize( serializer & ser, T *& t ) { \ 305 ser & chunk< T >(t, 1); \ 358 inline serializer(
bool addCRC =
false,
bool addSize =
false );
362 inline void resize( size_type len );
367 inline void set_mode_packed_size();
368 inline void set_mode_pack();
369 inline void set_mode_unpack();
370 inline void set_mode_cleanup();
371 inline void set_mode_pack(
bool addCRC,
bool addSize );
372 inline void set_mode_unpack(
bool addCRC,
bool addSize );
373 bool is_packing()
const {
return m_mode == MODE_PACK; }
374 bool is_unpacking()
const {
return m_mode == MODE_UNPACK; }
375 bool is_cleaning_up()
const {
return m_mode == MODE_CLEANUP; }
376 size_type get_size()
const {
return m_packedSize; }
378 inline size_type get_header_size()
const;
380 inline size_type get_body_size()
const;
382 inline size_type get_total_size()
const;
384 inline void * get_header()
const;
386 inline void * get_body()
const;
388 inline size_type unpack_header()
const;
397 template<
class T >
serializer & operator&( T & var );
398 template<
class T >
serializer & operator&(
const T & var );
400 template<
class T,
class Allocator >
406 template<
class T > reserved reserve(
const T & _obj );
410 template<
class T >
void complete(
const reserved & r,
const T & _obj );
413 template<
class T >
inline size_type packed_size(
const T * arr, size_type len )
const {
416 template<
class T >
inline void pack(
const T * arr, size_type len ) {
419 template<
class T >
inline void unpack( T * arr, size_type len ) {
422 template<
class T >
inline void cleanup( T * arr, size_type len ) {
425 template<
class T >
inline size_type packed_size(
const T & var )
const {
return packed_size( &var, 1 ); }
426 template<
class T >
inline void pack(
const T & var ) {
return pack( &var, 1 ); }
427 template<
class T >
inline void unpack( T & var ) {
return unpack( &var, 1 ); }
428 template<
class T >
inline void cleanup( T & var ) {
return cleanup( &var, 1 ); }
433 template<
class T,
class Allocator = std::allocator< T > >
439 template<
class T,
class Allocator = std::allocator< T > >
457 template<
class T >
inline size_type packed_size(
const T * arr, size_type len,
bitwise_serializable )
const;
461 template<
class T >
inline size_type packed_size(
const T * arr, size_type len,
explicitly_serializable )
const;
471 size_type remaining_capacity()
const;
473 Internal::Buffer * m_buf;
474 size_type m_packedSize;
477 friend class Internal::BufferAccess;
484 #include <cnc/internal/dist/Serializer.impl.h> 486 #endif // _CNC_SERIALIZER_H_ explicitly_serializable serializer_category(const T *)
Serialization of arrays with and without automatic memory handling.
CNC_BITWISE_SERIALIZABLE(bool)
bool is bitwise serializable
simple structs/classes are bitwise serializable.
Specifies serialization category: explicit serialization via a "serialize" function.
Handles serilialization of data-objects.
Allocates an array of type T and size num in pointer variable arrVar.
destructs the array of type T and isze num at arrVar and resets arrVar to NULL.