29#ifndef Pt_SerializationInfo_h
30#define Pt_SerializationInfo_h
35#include <Pt/LiteralPtr.h>
36#include <Pt/FixupInfo.h>
37#include <Pt/TextCodec.h>
38#include <Pt/SerializationError.h>
39#include <Pt/SerializationSurrogate.h>
135 {
return static_cast<Type>(_type); }
140 {
return _type ==
Void; }
149 {
return _isCompound ==
false; }
154 {
return _type ==
Struct; }
159 {
return _type ==
Dict; }
189 template <
typename T>
190 bool compose(T& type)
const;
193 template <
typename T>
194 bool decompose(
const T& type);
217 {
return _TypeName; }
258 const char*
id()
const
271 void setId(
const char*
id, std::size_t len);
300 {
setString(str.c_str(), str.size(), codec); }
441 void beginLoad(
void* p,
const std::type_info& ti)
const;
578 template <
typename T>
581 this->load(&fixme, FixupThunk<T>::fixupReference, mid);
586 template <
typename T>
589 this->load(&fixme, FixupThunk<T>::fixupPointer, mid);
609 template <
typename T>
610 const BasicSerializationSurrogate<T>* getSurrogate()
const;
613 template <
typename T>
617 const SerializationSurrogate* getSurrogate(
const std::type_info& ti)
const;
620 void load(
void* fixme, FixupInfo::FixupHandler fh,
unsigned mid)
const;
656 SerializationInfo* first;
657 SerializationInfo* last;
666 unsigned long long ul;
675 mutable Variant _value;
676 SerializationContext* _context;
677 SerializationInfo* _parent;
678 SerializationInfo* _next;
680 const char* _TypeName;
701inline const BasicSerializationSurrogate<T>* SerializationInfo::getSurrogate()
const
703 const SerializationSurrogate* surr = this->getSurrogate(
typeid(T) );
707 return static_cast<const BasicSerializationSurrogate<T>*
>(surr);
714 const BasicSerializationSurrogate<T>* surr = this->getSurrogate<T>();
718 surr->compose(*
this,
type);
726 const BasicSerializationSurrogate<T>* surr = this->getSurrogate<T>();
730 surr->decompose(*
this,
type);
744 Iterator(
const Iterator& other)
752 Iterator& operator=(
const Iterator& other)
758 Iterator& operator++()
760 _si = _si->sibling();
770 bool operator!=(
const Iterator& other)
const
771 {
return _si != other._si; }
773 bool operator==(
const Iterator& other)
const
774 {
return _si == other._si; }
789 ConstIterator(
const ConstIterator& other)
797 ConstIterator& operator=(
const ConstIterator& other)
803 ConstIterator& operator++()
805 _si = _si->sibling();
815 bool operator!=(
const ConstIterator& other)
const
816 {
return _si != other._si; }
818 bool operator==(
const ConstIterator& other)
const
819 {
return _si == other._si; }
857 template <
typename T>
860 bool first = si->beginSave( &type );
891inline void operator <<=(
SaveInfo info,
const T& type)
902inline void save(SaveInfo& si,
const T& type)
904 if( ! si.save(type) )
930 template <
typename T>
935 si->beginLoad( tp,
typeid(T) );
962inline void operator >>=(
const LoadInfo& li, T& type)
973inline void load(
const LoadInfo& li, T& type)
1008template <
typename T>
1239 ch =
static_cast<char>( tmp.
value() );
1300template <
typename T,
typename A>
1310 vec.push_back(elem);
1311 *it >> Pt::load() >>= vec.back();
1338template <
typename T,
typename A>
1341 typename std::vector<T, A>::const_iterator it;
1343 for(it = vec.begin(); it != vec.end(); ++it)
1356template <
typename T,
typename A>
1362 list.resize( list.size() + 1 );
1363 *it >> Pt::load() >>= list.back();
1371template <
typename T,
typename A>
1374 typename std::list<T, A>::const_iterator it;
1376 for(it = list.begin(); it != list.end(); ++it)
1389template <
typename T,
typename A>
1396 deque.push_back( T() );
1397 *it >> Pt::load() >>= deque.back();
1405template <
typename T,
typename A>
1408 typename std::deque<T, A>::const_iterator it;
1410 for(it = deque.begin(); it != deque.end(); ++it)
1428template <
typename T,
typename C,
typename A>
1454template <
typename T,
typename C,
typename A>
1457 typename std::set<T, C, A>::const_iterator it;
1459 for(it = set.begin(); it != set.end(); ++it)
1476template <
typename T,
typename C,
typename A>
1501template <
typename T,
typename C,
typename A>
1504 typename std::multiset<T, C, A>::const_iterator it;
1506 for(it = multiset.begin(); it != multiset.end(); ++it)
1516template <
typename A,
typename B>
1524template <
typename A,
typename B>
1525inline void operator <<=(SerializationInfo& si,
const std::pair<A, B>& p)
1536template <
typename K,
typename V,
typename P,
typename A>
1539 typedef typename std::map<K, V, P, A>::iterator MapIterator;
1540 std::pair<MapIterator, bool> pos;
1548 if( kv != it->
end() )
1551 std::pair<K, V> elem( k, V() );
1552 pos = map.insert(elem);
1554 if( pos.second && ++kv != it->
end() )
1555 *kv >> Pt::load() >>= pos.first->second;
1563template <
typename K,
typename V,
typename P,
typename A>
1566 typename std::map<K, V, P, A>::const_iterator it;
1568 for(it = map.begin(); it != map.end(); ++it)
1583template <
typename K,
typename V,
typename P,
typename A>
1586 typename std::multimap<K, V, P, A>::iterator mit;
1594 if( kv != it->
end() )
1597 std::pair<K, V> elem( k, V() );
1598 mit = multimap.insert(elem);
1600 if( ++kv != it->
end() )
1601 *kv >> Pt::load() >>= mit->second;
1609template <
typename T,
typename C,
typename P,
typename A>
1612 typename std::multimap<T, C, P, A>::const_iterator it;
1614 for(it = multimap.begin(); it != multimap.end(); ++it)
Represents a pointer to a literal.
Definition LiteralPtr.h:40
Loads referencable types.
Definition SerializationInfo.h:916
const SerializationInfo & in() const
Returns the SerializationInfo to load from.
Definition SerializationInfo.h:925
void load(T &type) const
Loads the type.
Definition SerializationInfo.h:931
Saves referencable types.
Definition SerializationInfo.h:843
SerializationInfo & out() const
Returns the SerializationInfo to save to.
Definition SerializationInfo.h:852
bool save(const T &type)
Returns true if type was saved, false if type was already saved.
Definition SerializationInfo.h:858
Context for the serialization of types.
Definition Api-SerializationContext.h:26
Const forward iterator for child elements.
Definition SerializationInfo.h:783
Forward Iterator for child elements.
Definition SerializationInfo.h:738
Represents arbitrary types during serialization.
Definition SerializationInfo.h:59
SerializationInfo & addMember(const char *name)
Add a struct member.
Definition SerializationInfo.h:454
SerializationInfo & addElement()
Add a sequence element.
void setChar(char c)
Set to character value.
void getUInt64(Pt::uint64_t &n) const
Get value as a 64-bit unsigned integer.
void setString(const char *s, std::size_t len, const TextCodec< Pt::Char, char > &codec)
Set to string value.
void endFormat(Formatter &formatter)
End formatting.
void setReference(const char *id, std::size_t idlen)
Set to reference with ID to fixup.
void setLongDouble(long double d)
Set to long double value.
void setInt8(Pt::int8_t n)
Set to 8-bit integer value.
const SerializationInfo * findMember(const std::string &name) const
Find a struct member.
Definition SerializationInfo.h:508
bool isDict() const
Returns true if dictionary type.
Definition SerializationInfo.h:158
Type
Type identifier.
Definition SerializationInfo.h:65
@ UInt64
64-bit unsigned integer
Definition SerializationInfo.h:79
@ UInt8
8-bit unsigned integer
Definition SerializationInfo.h:76
@ Int16
16-bit integer
Definition SerializationInfo.h:73
@ Sequence
Sequence compound type.
Definition SerializationInfo.h:85
@ Context
Contextual.
Definition SerializationInfo.h:67
@ Boolean
Boolean.
Definition SerializationInfo.h:69
@ Str
Str.
Definition SerializationInfo.h:71
@ UInt32
32-bit unsigned integer
Definition SerializationInfo.h:78
@ Dict
Dictionary compound type.
Definition SerializationInfo.h:86
@ Struct
Structural compound type.
Definition SerializationInfo.h:84
@ Int32
32-bit integer
Definition SerializationInfo.h:74
@ Void
Void.
Definition SerializationInfo.h:66
@ Int8
8-bit integer
Definition SerializationInfo.h:72
@ UInt16
16-bit unsigned integer
Definition SerializationInfo.h:77
@ DictElement
Dictionary element.
Definition SerializationInfo.h:87
@ Reference
Reference.
Definition SerializationInfo.h:68
@ LongDouble
Long double floating point.
Definition SerializationInfo.h:82
@ Float
Floating point.
Definition SerializationInfo.h:80
@ Int64
64-bit integer
Definition SerializationInfo.h:75
@ Char
Char.
Definition SerializationInfo.h:70
@ Binary
Binary.
Definition SerializationInfo.h:83
@ Double
Double floating point.
Definition SerializationInfo.h:81
const char * getBinary(std::size_t &length) const
Get value as a binary object.
void getUInt32(Pt::uint32_t &n) const
Get value as a 32-bit unsigned integer.
Iterator begin()
Returns an iterator to the begin of child elements.
void getInt64(Pt::int64_t &l) const
Get value as a 64-bit integer.
void setStruct()
Set to struct type.
void setId(const std::string &id)
Sets the reference ID.
void getString(std::string &s) const
Get value as a string.
void setReference(const void *ref)
Set to reference for which to create an ID.
void setId(const char *id, std::size_t len)
Sets the reference ID.
void format(Formatter &formatter) const
Format complete value or all members.
void setTypeName(const std::string &type)
Sets the type name.
SerializationInfo & addMember(const LiteralPtr< char > &name)
Add a struct member.
void setFloat(float f)
Set to float value.
void setDict()
Set to dictionary type.
void setInt16(Pt::int16_t n)
Set to 16-bit integer value.
void setString(const Pt::String &s)
Set to string value.
Definition SerializationInfo.h:304
void setDouble(double f)
Set to double value.
SerializationContext * context() const
Returns the used context.
Definition SerializationInfo.h:185
const char * typeName() const
Returns the type name.
Definition SerializationInfo.h:216
void getChar(char &c) const
Get value as a character.
void setBinary(const char *data, std::size_t length)
Set to binary value.
void getInt8(Pt::int8_t &n) const
Get value as a 8-bit integer.
bool isReference() const
Returns true if reference.
Definition SerializationInfo.h:168
SerializationInfo & addMember(const char *name, std::size_t len)
Add a struct member.
void getInt32(Pt::int32_t &i) const
Get value as a 32-bit integer.
SerializationInfo & addDictValue()
Add a dict value.
SerializationInfo(SerializationContext *context)
Construct with context.
Definition SerializationInfo.h:109
void removeMember(const SerializationInfo &si)
Remove a struct member.
SerializationInfo * findMember(const char *name)
Find a struct member.
void loadReference(T &fixme, unsigned mid=0) const
Load a reference during deserialization.
Definition SerializationInfo.h:579
void setInt64(Pt::int64_t l)
Set to 64-bit integer value.
void rebindFixup(void *obj) const
Rebind to new fixup address.
void getInt16(Pt::int16_t &n) const
Get value as a 16-bit integer.
const SerializationInfo * parent() const
Returns the parent node.
Definition SerializationInfo.h:211
Iterator end()
Returns an iterator to the end of child elements.
Definition SerializationInfo.h:826
bool isStruct() const
Returns true if struct type.
Definition SerializationInfo.h:153
void setString(const std::string &str, const TextCodec< Pt::Char, char > &codec)
Set to string value.
Definition SerializationInfo.h:299
void setBool(bool b)
Set to bool value.
void getDouble(double &f) const
Get value as a double.
void setString(const char *s)
Set to string value.
void getBool(bool &b) const
Get value as a bool.
const char * name() const
Returns the instance name.
Definition SerializationInfo.h:237
void setInt32(Pt::int32_t n)
Set to 32-bit integer value.
void beginLoad(void *p, const std::type_info &ti) const
Begin loading.
void finishSave()
Finish saving.
void setTypeName(const char *type)
Sets the type name.
SerializationInfo * parent()
Returns the parent node.
Definition SerializationInfo.h:206
void removeMember(const std::string &name)
Remove a struct member.
Definition SerializationInfo.h:467
void setName(const char *type, std::size_t len)
Sets the instance name.
bool isScalar() const
Returns true if scalar type.
Definition SerializationInfo.h:148
void getChar(Pt::Char &c) const
Get value as a character.
void setTypeName(const LiteralPtr< char > &type)
Sets the type name.
const char * id() const
Returns the reference ID.
Definition SerializationInfo.h:258
SerializationInfo & addDictKey()
Add a dict key.
std::size_t memberCount() const
Returns the number of members.
void setName(const std::string &name)
Sets the instance name.
void getString(std::string &s, const TextCodec< Pt::Char, char > &codec) const
Get value as a string.
void finishLoad() const
Finish loading.
void setChar(const Pt::Char &c)
Set to character value.
void setUInt64(Pt::uint64_t n)
Set to 64-bit unsigned integer value.
void getLongDouble(long double &d) const
Get value as a long double.
void setUInt32(Pt::uint32_t n)
Set to 32-bit unsigned integer value.
~SerializationInfo()
Destructor.
void setName(const LiteralPtr< char > &type)
Sets the instance name.
void setName(const char *name)
Sets the instance name.
SerializationInfo & addDictElement()
Add a dict element.
void getFloat(float &f) const
Get value as a float.
void setUInt16(Pt::uint16_t n)
Set to 16-bit unsigned integer value.
void setString(const std::string &s)
Set to string value.
void getUInt8(Pt::uint8_t &n) const
Get value as a 8-bit unsigned integer.
SerializationInfo()
Default constructor.
Definition SerializationInfo.h:93
const SerializationInfo & getMember(const char *name) const
Get a struct member.
void clear()
Clears all content.
bool compose(T &type) const
Returns true if the type could be composed with a surrogate.
Definition SerializationInfo.h:712
SerializationInfo * findMember(const std::string &name)
Find a struct member.
Definition SerializationInfo.h:523
void setString(const Pt::Char *s, std::size_t len)
Set to string value.
ConstIterator begin() const
Returns an iterator to the begin of child elements.
Iterator beginFormat(Formatter &formatter)
Begin formatting.
void setTypeName(const char *type, std::size_t len)
Sets the type name.
bool beginSave(const void *p)
Begin saving.
void setReference(const std::string &id)
Set to reference with ID to fixup.
Definition SerializationInfo.h:569
Type type() const
Returns the type identifier.
Definition SerializationInfo.h:134
bool isSequence() const
Returns true if sequence type.
Definition SerializationInfo.h:163
bool isVoid() const
Returns true if not set to a type.
Definition SerializationInfo.h:139
void getString(Pt::String &s) const
Get value as a string.
void setVoid()
Set to void type.
void setId(const char *id)
Sets the reference ID.
void setSequence()
Set to sequence type.
void setUInt8(Pt::uint8_t n)
Set to 8-bit unsigned integer value.
void loadPointer(T *&fixme, unsigned mid=0) const
Load a reference during deserialization.
Definition SerializationInfo.h:587
void getUInt16(Pt::uint16_t &n) const
Get value as a 16-bit unsigned integer.
void removeMember(const char *name)
Remove a struct member.
SerializationInfo & addMember(const std::string &name)
Add a struct member.
Definition SerializationInfo.h:449
bool decompose(const T &type)
Returns true if the type could be decomposed with a surrogate.
Definition SerializationInfo.h:724
const SerializationInfo & getMember(const std::string &name) const
Get a struct member.
Definition SerializationInfo.h:496
void rebind(void *obj) const
Rebind to new address.
const SerializationInfo * findMember(const char *name) const
Find a struct member.
Unicode capable basic_string.
Definition Api-String.h:67
size_type length() const
Returns the length of the string.
Definition Api-String.h:258
const Pt::Char * c_str() const
Returns a null terminated C string.
Definition Api-String.h:288
Converts between character encodings.
Definition Api-TextCodec.h:44
uint_type uint16_t
Unsigned 16-bit integer type.
Definition Api-Types.h:38
int_type int64_t
Signed 64-bit integer type.
Definition Api-Types.h:59
int_type int32_t
Signed 32-bit integer type.
Definition Api-Types.h:45
uint_type uint32_t
Unsigned 32-bit integer type.
Definition Api-Types.h:52
uint_type uint64_t
Unsigned 64-bit integer type.
Definition Api-Types.h:66
int_type int16_t
Signed 16-bit integer type.
Definition Api-Types.h:31
uint_type uint8_t
Unsigned 8-bit integer type.
Definition Api-Types.h:24
int_type int8_t
Signed 8-bit integer type.
Definition Api-Types.h:17
void load(const LoadInfo &li, T &type)
Loads referencable types.
Definition SerializationInfo.h:973
void save(SaveInfo &si, const T &type)
Saves referencable types.
Definition SerializationInfo.h:902
Core module.
Definition Allocator.h:33
Unicode character type.
Definition String.h:67
uint32_t value() const
Returns the unicode value.
Definition String.h:94