SerializationInfo Class Reference

#include <Pt/SerializationInfo.h>

Represents arbitrary types during serialization.

Inherited by Settings [private].

Classes

class  Iterator
 Forward Iterator for child elements. More...
class  ConstIterator
 Const forward iterator for child elements. More...

Public Types

enum  Type {
  Void = 0 ,
  Context = 1 ,
  Reference = 2 ,
  Boolean = 3 ,
  Char = 4 ,
  Str = 5 ,
  Int8 = 6 ,
  Int16 = 7 ,
  Int32 = 8 ,
  Int64 = 9 ,
  UInt8 = 10 ,
  UInt16 = 11 ,
  UInt32 = 12 ,
  UInt64 = 13 ,
  Float = 14 ,
  Double = 15 ,
  LongDouble = 16 ,
  Binary = 17 ,
  Struct = 18 ,
  Sequence = 19 ,
  Dict = 20 ,
  DictElement = 21
}
 Type identifier. More...

Public Member Functions

 SerializationInfo ()
 Default constructor.
 SerializationInfo (SerializationContext *context)
 Construct with context.
 ~SerializationInfo ()
 Destructor.
void clear ()
 Clears all content.
Type type () const
 Returns the type identifier.
bool isVoid () const
 Returns true if not set to a type.
void setVoid ()
 Set to void type.
bool isScalar () const
 Returns true if scalar type.
bool isStruct () const
 Returns true if struct type.
bool isDict () const
 Returns true if dictionary type.
bool isSequence () const
 Returns true if sequence type.
bool isReference () const
 Returns true if reference.
void setSequence ()
 Set to sequence type.
void setDict ()
 Set to dictionary type.
void setStruct ()
 Set to struct type.
SerializationContextcontext () const
 Returns the used context.
template<typename T>
bool compose (T &type) const
 Returns true if the type could be composed with a surrogate.
template<typename T>
bool decompose (const T &type)
 Returns true if the type could be decomposed with a surrogate.
void rebind (void *obj) const
 Rebind to new address.
void rebindFixup (void *obj) const
 Rebind to new fixup address.
SerializationInfoparent ()
 Returns the parent node.
const SerializationInfoparent () const
 Returns the parent node.
const char * typeName () const
 Returns the type name.
void setTypeName (const std::string &type)
 Sets the type name.
void setTypeName (const char *type)
 Sets the type name.
void setTypeName (const char *type, std::size_t len)
 Sets the type name.
void setTypeName (const LiteralPtr< char > &type)
 Sets the type name.
const char * name () const
 Returns the instance name.
void setName (const std::string &name)
 Sets the instance name.
void setName (const char *name)
 Sets the instance name.
void setName (const char *type, std::size_t len)
 Sets the instance name.
void setName (const LiteralPtr< char > &type)
 Sets the instance name.
const char * id () const
 Returns the reference ID.
void setId (const std::string &id)
 Sets the reference ID.
void setId (const char *id)
 Sets the reference ID.
void setId (const char *id, std::size_t len)
 Sets the reference ID.
void getString (std::string &s, const TextCodec< Pt::Char, char > &codec) const
 Get value as a string.
void getString (std::string &s) const
 Get value as a string.
void getString (Pt::String &s) const
 Get value as a string.
void setString (const char *s)
 Set to string value.
void setString (const char *s, std::size_t len, const TextCodec< Pt::Char, char > &codec)
 Set to string value.
void setString (const std::string &s)
 Set to string value.
void setString (const std::string &str, const TextCodec< Pt::Char, char > &codec)
 Set to string value.
void setString (const Pt::String &s)
 Set to string value.
void setString (const Pt::Char *s, std::size_t len)
 Set to string value.
const char * getBinary (std::size_t &length) const
 Get value as a binary object.
void setBinary (const char *data, std::size_t length)
 Set to binary value.
void getChar (char &c) const
 Get value as a character.
void setChar (char c)
 Set to character value.
void getChar (Pt::Char &c) const
 Get value as a character.
void setChar (const Pt::Char &c)
 Set to character value.
void getBool (bool &b) const
 Get value as a bool.
void setBool (bool b)
 Set to bool value.
void getInt8 (Pt::int8_t &n) const
 Get value as a 8-bit integer.
void setInt8 (Pt::int8_t n)
 Set to 8-bit integer value.
void getInt16 (Pt::int16_t &n) const
 Get value as a 16-bit integer.
void setInt16 (Pt::int16_t n)
 Set to 16-bit integer value.
void getInt32 (Pt::int32_t &i) const
 Get value as a 32-bit integer.
void setInt32 (Pt::int32_t n)
 Set to 32-bit integer value.
void getInt64 (Pt::int64_t &l) const
 Get value as a 64-bit integer.
void setInt64 (Pt::int64_t l)
 Set to 64-bit integer value.
void getUInt8 (Pt::uint8_t &n) const
 Get value as a 8-bit unsigned integer.
void setUInt8 (Pt::uint8_t n)
 Set to 8-bit unsigned integer value.
void getUInt16 (Pt::uint16_t &n) const
 Get value as a 16-bit unsigned integer.
void setUInt16 (Pt::uint16_t n)
 Set to 16-bit unsigned integer value.
void getUInt32 (Pt::uint32_t &n) const
 Get value as a 32-bit unsigned integer.
void setUInt32 (Pt::uint32_t n)
 Set to 32-bit unsigned integer value.
void getUInt64 (Pt::uint64_t &n) const
 Get value as a 64-bit unsigned integer.
void setUInt64 (Pt::uint64_t n)
 Set to 64-bit unsigned integer value.
void getFloat (float &f) const
 Get value as a float.
void setFloat (float f)
 Set to float value.
void getDouble (double &f) const
 Get value as a double.
void setDouble (double f)
 Set to double value.
void getLongDouble (long double &d) const
 Get value as a long double.
void setLongDouble (long double d)
 Set to long double value.
bool beginSave (const void *p)
 Begin saving.
void finishSave ()
 Finish saving.
void beginLoad (void *p, const std::type_info &ti) const
 Begin loading.
void finishLoad () const
 Finish loading.
SerializationInfoaddMember (const std::string &name)
 Add a struct member.
SerializationInfoaddMember (const char *name)
 Add a struct member.
SerializationInfoaddMember (const char *name, std::size_t len)
 Add a struct member.
SerializationInfoaddMember (const LiteralPtr< char > &name)
 Add a struct member.
void removeMember (const std::string &name)
 Remove a struct member.
void removeMember (const char *name)
 Remove a struct member.
void removeMember (const SerializationInfo &si)
 Remove a struct member.
SerializationInfoaddElement ()
 Add a sequence element.
SerializationInfoaddDictElement ()
 Add a dict element.
SerializationInfoaddDictKey ()
 Add a dict key.
SerializationInfoaddDictValue ()
 Add a dict value.
const SerializationInfogetMember (const std::string &name) const
 Get a struct member.
const SerializationInfogetMember (const char *name) const
 Get a struct member.
const SerializationInfofindMember (const std::string &name) const
 Find a struct member.
const SerializationInfofindMember (const char *name) const
 Find a struct member.
SerializationInfofindMember (const std::string &name)
 Find a struct member.
SerializationInfofindMember (const char *name)
 Find a struct member.
std::size_t memberCount () const
 Returns the number of members.
Iterator begin ()
 Returns an iterator to the begin of child elements.
Iterator end ()
 Returns an iterator to the end of child elements.
ConstIterator begin () const
 Returns an iterator to the begin of child elements.
ConstIterator end () const
 Returns an iterator to the end of child elements.
void setReference (const void *ref)
 Set to reference for which to create an ID.
void setReference (const std::string &id)
 Set to reference with ID to fixup.
void setReference (const char *id, std::size_t idlen)
 Set to reference with ID to fixup.
template<typename T>
void loadReference (T &fixme, unsigned mid=0) const
 Load a reference during deserialization.
template<typename T>
void loadPointer (T *&fixme, unsigned mid=0) const
 Load a reference during deserialization.
Iterator beginFormat (Formatter &formatter)
 Begin formatting.
void endFormat (Formatter &formatter)
 End formatting.
void format (Formatter &formatter) const
 Format complete value or all members.

(Note that these are not member symbols.)

template<typename T>
void operator>>= (const SerializationInfo &si, T *&ptr)
 Deserializes a pointer reference.
template<typename T>
void operator<<= (SerializationInfo &si, const T *ptr)
 Serializes a pointer reference.
void operator>>= (const SerializationInfo &si, bool &n)
 Deserializes a bool.
void operator<<= (SerializationInfo &si, bool n)
 Serializes a bool.
void operator>>= (const SerializationInfo &si, Pt::int8_t &n)
 Deserializes an 8-bit integer.
void operator<<= (SerializationInfo &si, Pt::int8_t n)
 Serializes a 8-bit integer.
void operator>>= (const SerializationInfo &si, Pt::int16_t &n)
 Deserializes a 16-bit integer.
void operator<<= (SerializationInfo &si, Pt::int16_t n)
 Serializes a 16-bit integer.
void operator>>= (const SerializationInfo &si, Pt::int32_t &n)
 Deserializes a 32-bit integer.
void operator<<= (SerializationInfo &si, Pt::int32_t n)
 Serializes a 32-bit integer.
void operator>>= (const SerializationInfo &si, Pt::int64_t &n)
 Deserializes a 64-bit integer.
void operator<<= (SerializationInfo &si, Pt::int64_t n)
 Serializes a 64-bit integer.
void operator>>= (const SerializationInfo &si, Pt::uint8_t &n)
 Deserializes a 8-bit unsigned integer.
void operator<<= (SerializationInfo &si, Pt::uint8_t n)
 Serializes a 8-bit unsigned integer.
void operator>>= (const SerializationInfo &si, Pt::uint16_t &n)
 Deserializes a 16-bit unsigned integer.
void operator<<= (SerializationInfo &si, Pt::uint16_t n)
 Serializes a 16-bit unsigned integer.
void operator>>= (const SerializationInfo &si, Pt::uint32_t &n)
 Deserializes a 32-bit unsigned integer.
void operator<<= (SerializationInfo &si, Pt::uint32_t n)
 Serializes a 32-bit unsigned integer.
void operator>>= (const SerializationInfo &si, Pt::uint64_t &n)
 Deserializes a 64-bit unsigned integer.
void operator<<= (SerializationInfo &si, Pt::uint64_t n)
 Serializes a 64-bit unsigned integer.
void operator>>= (const SerializationInfo &si, float &n)
 Deserializes a float value.
void operator<<= (SerializationInfo &si, float n)
 Serializes a float value.
void operator>>= (const SerializationInfo &si, double &n)
 Deserializes a double value.
void operator<<= (SerializationInfo &si, double n)
 Serializes a double value.
void operator>>= (const SerializationInfo &si, long double &n)
 Deserializes a long double value.
void operator<<= (SerializationInfo &si, long double n)
 Serializes a long double value.
void operator>>= (const SerializationInfo &si, char &ch)
 Deserializes a character value.
void operator<<= (SerializationInfo &si, char ch)
 Serializes a character value.
void operator<<= (SerializationInfo &si, const char *str)
 Serializes a string.
void operator>>= (const SerializationInfo &si, std::string &str)
 Deserializes a std::string.
void operator<<= (SerializationInfo &si, const std::string &str)
 Serializes a std::string.
void operator>>= (const SerializationInfo &si, Pt::String &str)
 Deserializes a string.
void operator<<= (SerializationInfo &si, const Pt::String &str)
 Serializes a string.
template<typename T, typename A>
void operator>>= (const SerializationInfo &si, std::vector< T, A > &vec)
 Deserializes a std::vector.
template<typename T, typename A>
void operator<<= (SerializationInfo &si, const std::vector< T, A > &vec)
 Serializes a std::vector.
template<typename T, typename A>
void operator>>= (const SerializationInfo &si, std::list< T, A > &list)
 Deserializes a std::list.
template<typename T, typename A>
void operator<<= (SerializationInfo &si, const std::list< T, A > &list)
 Serializes a std::list.
template<typename T, typename A>
void operator>>= (const SerializationInfo &si, std::deque< T, A > &deque)
 Deserializes a std::deque.
template<typename T, typename A>
void operator<<= (SerializationInfo &si, const std::deque< T, A > &deque)
 Serializes a std::deque.
template<typename T, typename C, typename A>
void operator>>= (const SerializationInfo &si, std::set< T, C, A > &set)
 Deserializes a std::set.
template<typename T, typename C, typename A>
void operator<<= (SerializationInfo &si, const std::set< T, C, A > &set)
 Serializes a std::set.
template<typename T, typename C, typename A>
void operator>>= (const SerializationInfo &si, std::multiset< T, C, A > &multiset)
 Deserializes a std::multiset.
template<typename T, typename C, typename A>
void operator<<= (SerializationInfo &si, const std::multiset< T, C, A > &multiset)
 Serializes a std::multiset.
template<typename K, typename V, typename P, typename A>
void operator>>= (const SerializationInfo &si, std::map< K, V, P, A > &map)
 Deserializes a std::map.
template<typename K, typename V, typename P, typename A>
void operator<<= (SerializationInfo &si, const std::map< K, V, P, A > &map)
 Serializes a std::map.
template<typename K, typename V, typename P, typename A>
void operator>>= (const SerializationInfo &si, std::multimap< K, V, P, A > &multimap)
 Deserializes a std::multimap.
template<typename T, typename C, typename P, typename A>
void operator<<= (SerializationInfo &si, const std::multimap< T, C, P, A > &multimap)
 Serializes a std::multimap.

Member Enumeration Documentation

◆ Type

enum Type
Enumerator
Void 

Void.

Context 

Contextual.

Reference 

Reference.

Boolean 

Boolean.

Char 

Char.

Str 

Str.

Int8 

8-bit integer

Int16 

16-bit integer

Int32 

32-bit integer

Int64 

64-bit integer

UInt8 

8-bit unsigned integer

UInt16 

16-bit unsigned integer

UInt32 

32-bit unsigned integer

UInt64 

64-bit unsigned integer

Float 

Floating point.

Double 

Double floating point.

LongDouble 

Long double floating point.

Binary 

Binary.

Struct 

Structural compound type.

Sequence 

Sequence compound type.

Dict 

Dictionary compound type.

DictElement 

Dictionary element.

Member Function Documentation

◆ findMember() [1/4]

const SerializationInfo * findMember ( const std::string & name) const

This method returns the data for a member with the name name. or null if it is not present.

◆ findMember() [2/4]

const SerializationInfo * findMember ( const char * name) const

This method returns the data for a member with the name name. or null if it is not present.

◆ findMember() [3/4]

SerializationInfo * findMember ( const std::string & name)

This method returns the data for a member with the name name. or null if it is not present.

◆ findMember() [4/4]

SerializationInfo * findMember ( const char * name)

This method returns the data for a member with the name name. or null if it is not present.

◆ operator>>=() [1/3]

template<typename T>
void operator>>= ( const SerializationInfo & si,
T *& ptr )
related

The serialization of pointers is identical to the serialization of values if the object pointed to is owned by the pointer: the pointer can simply be dereferenced and the object it points to passed to the serialization operator. Any pointer serialized or deserialized through this overload is instead treated as a weak reference to another object in the same object graph. Depending on the format, this parses a reference id pointing to another object in the object stream. It does not matter in which order weak pointers and the objects they point to are serialized; both forward and backward references work.

◆ operator<<=() [1/2]

template<typename T>
void operator<<= ( SerializationInfo & si,
const T * ptr )
related

Any pointer serialized through this overload is treated as a weak reference to another object in the same object graph, and formatted as a reference id instead of the pointed-to value. See the deserialization overload of operator>>=() for T* for details.

◆ operator<<=() [2/2]

template<typename T, typename A>
void operator<<= ( SerializationInfo & si,
const std::vector< T, A > & vec )
related

Each element of the vector is added to the parent SerializationInfo using Pt::SerializationInfo::addElement(). The modifier Pt::save() marks the element as a type that is potentially referenceable by a weak pointer in another object; this improves performance, because the serializer only has to consider reachable objects when pointers are also serialized. At the end, a type name is set and the parent SerializationInfo is marked as a sequence, which is necessary to allow empty vectors. Deserialization reserves the vector's memory upfront and then deserializes each child SerializationInfo into the back of the vector, using the Pt::load() modifier to mark the element as referenceable by a pointer in another object.

Building the complete tree of SerializationInfo objects for a container consumes memory proportional to its element count and cannot work incrementally. An alternative for large or performance sensitive container types is to specialize Pt::BasicComposer and Pt::BasicDecomposer instead of relying on these operators; see their class documentation for the std::vector specialization example.

◆ operator>>=() [2/3]

template<typename T, typename C, typename A>
void operator>>= ( const SerializationInfo & si,
std::set< T, C, A > & set )
related

Deserialization of references to or from set elements is not reliably possible, due to some of std::set's constraints. However you may overload this operator for your type.

◆ operator>>=() [3/3]

template<typename T, typename C, typename A>
void operator>>= ( const SerializationInfo & si,
std::multiset< T, C, A > & multiset )
related

Deserialization of references to or from set elements is not reliably possible, due to some of std::set's constraints. However you may overload this operator for your type.