29 #ifndef Pt_SerializationInfo_h
30 #define Pt_SerializationInfo_h
33 #include <Pt/String.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>
51 class SerializationContext;
135 {
return static_cast<Type>(_type); }
140 {
return _type ==
Void; }
149 {
return _isCompound ==
false; }
154 {
return _type == Struct; }
159 {
return _type == Dict; }
164 {
return _type == Sequence; }
169 {
return _type == Reference; }
189 template <
typename T>
190 bool compose(T& type)
const;
193 template <
typename T>
194 bool decompose(
const T& type);
217 {
return _TypeName; }
250 void setName(
const char* type, std::size_t len);
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;
450 {
return this->addMember( name.c_str(), name.length() ); }
455 {
return this->addMember(name, std::strlen(name)); }
468 {
return this->removeMember( name.c_str() ); }
497 {
return this->getMember( name.c_str() ); }
509 {
return this->findMember( name.c_str() ); }
524 {
return this->findMember( name.c_str() ); }
570 { setReference(
id.c_str(),
id.length() ); }
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;
700 template <
typename T>
701 inline const BasicSerializationSurrogate<T>* SerializationInfo::getSurrogate()
const
703 const SerializationSurrogate* surr = this->getSurrogate(
typeid(T) );
707 return static_cast<const BasicSerializationSurrogate<T>*
>(surr);
711 template <
typename T>
714 const BasicSerializationSurrogate<T>* surr = this->getSurrogate<T>();
718 surr->compose(*
this,
type);
723 template <
typename T>
726 const BasicSerializationSurrogate<T>* surr = this->getSurrogate<T>();
730 surr->decompose(*
this,
type);
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; }
805 _si = _si->sibling();
816 {
return _si != other._si; }
819 {
return _si == other._si; }
857 template <
typename T>
884 inline SaveInfo operator <<(SerializationInfo& si,
const Save&)
890 template <
typename T>
891 inline void operator <<=(SaveInfo info,
const T& type)
901 template <
typename T>
904 if( ! si.
save(type) )
930 template <
typename T>
955 inline LoadInfo operator >>(
const SerializationInfo& si,
const Load&)
961 template <
typename T>
962 inline void operator >>=(
const LoadInfo& li, T& type)
972 template <
typename T>
983 template <
typename T>
993 template <
typename T>
1224 ch =
static_cast<char>( tmp.
value() );
1285 template <
typename T,
typename A>
1295 vec.push_back(elem);
1296 *it >> Pt::load() >>= vec.back();
1304 template <
typename T,
typename A>
1307 typename std::vector<T, A>::const_iterator it;
1309 for(it = vec.begin(); it != vec.end(); ++it)
1322 template <
typename T,
typename A>
1328 list.resize( list.size() + 1 );
1329 *it >> Pt::load() >>= list.back();
1337 template <
typename T,
typename A>
1340 typename std::list<T, A>::const_iterator it;
1342 for(it = list.begin(); it != list.end(); ++it)
1355 template <
typename T,
typename A>
1362 deque.push_back( T() );
1363 *it >> Pt::load() >>= deque.back();
1371 template <
typename T,
typename A>
1374 typename std::deque<T, A>::const_iterator it;
1376 for(it = deque.begin(); it != deque.end(); ++it)
1394 template <
typename T,
typename C,
typename A>
1420 template <
typename T,
typename C,
typename A>
1423 typename std::set<T, C, A>::const_iterator it;
1425 for(it = set.begin(); it != set.end(); ++it)
1442 template <
typename T,
typename C,
typename A>
1467 template <
typename T,
typename C,
typename A>
1470 typename std::multiset<T, C, A>::const_iterator it;
1472 for(it = multiset.begin(); it != multiset.end(); ++it)
1482 template <
typename A,
typename B>
1490 template <
typename A,
typename B>
1491 inline void operator <<=(SerializationInfo& si,
const std::pair<A, B>& p)
1502 template <
typename K,
typename V,
typename P,
typename A>
1505 typedef typename std::map<K, V, P, A>::iterator MapIterator;
1506 std::pair<MapIterator, bool> pos;
1514 if( kv != it->
end() )
1517 std::pair<K, V> elem( k, V() );
1518 pos = map.insert(elem);
1520 if( pos.second && ++kv != it->
end() )
1521 *kv >> Pt::load() >>= pos.first->second;
1529 template <
typename K,
typename V,
typename P,
typename A>
1532 typename std::map<K, V, P, A>::const_iterator it;
1534 for(it = map.begin(); it != map.end(); ++it)
1549 template <
typename K,
typename V,
typename P,
typename A>
1552 typename std::multimap<K, V, P, A>::iterator mit;
1560 if( kv != it->
end() )
1563 std::pair<K, V> elem( k, V() );
1564 mit = multimap.insert(elem);
1566 if( ++kv != it->
end() )
1567 *kv >> Pt::load() >>= mit->second;
1575 template <
typename T,
typename C,
typename P,
typename A>
1578 typename std::multimap<T, C, P, A>::const_iterator it;
1580 for(it = multimap.begin(); it != multimap.end(); ++it)
1593 #endif // Pt_SerializationInfo_h
bool isStruct() const
Returns true if struct type.
Definition: SerializationInfo.h:153
Core module.
Definition: pt-gfx-images.dox:14
void setChar(const Pt::Char &c)
Set to character value.
void setStruct()
Set to struct type.
void setString(const Pt::String &s)
Set to string value.
Definition: SerializationInfo.h:304
Void type.
Definition: Void.h:44
void setUInt8(Pt::uint8_t n)
Set to 8-bit unsigned integer value.
void setString(const char *s, std::size_t len, const TextCodec< Pt::Char, char > &codec)
Set to string value.
bool isSequence() const
Returns true if sequence type.
Definition: SerializationInfo.h:163
Iterator end()
Returns an iterator to the end of child elements.
Definition: SerializationInfo.h:826
void beginLoad(void *p, const std::type_info &ti) const
Begin loading.
void load(T &type) const
Loads the type.
Definition: SerializationInfo.h:931
bool save(const T &type)
Returns true if type was saved, false if type was already saved.
Definition: SerializationInfo.h:858
Saves referencable types.
Definition: SerializationInfo.h:843
void load(const LoadInfo &li, T &type)
Loads referencable types.
Definition: SerializationInfo.h:973
void endFormat(Formatter &formatter)
End formatting.
void finishSave()
Finish saving.
SerializationContext * context() const
Returns the used context.
Definition: SerializationInfo.h:185
void setUInt16(Pt::uint16_t n)
Set to 16-bit unsigned integer value.
SerializationInfo & out() const
Returns the SerializationInfo to save to.
Definition: SerializationInfo.h:852
void setTypeName(const std::string &type)
Sets the type name.
void getUInt64(Pt::uint64_t &n) const
Get value as a 64-bit unsigned integer.
Loads referencable types.
Definition: SerializationInfo.h:916
size_type length() const
Returns the length of the string.
Definition: String.h:234
SerializationInfo & addDictValue()
Add a dict value.
void getInt8(Pt::int8_t &n) const
Get value as a 8-bit integer.
bool beginSave(const void *p)
Begin saving.
const Pt::Char * c_str() const
Returns a null terminated C string.
Definition: String.h:264
void setReference(const void *ref)
Set to reference for which to create an ID.
void save(SaveInfo &si, const T &type)
Saves referencable types.
Definition: SerializationInfo.h:902
uint32_t value() const
Returns the unicode value.
Definition: String.h:94
void getUInt16(Pt::uint16_t &n) const
Get value as a 16-bit unsigned integer.
Iterator beginFormat(Formatter &formatter)
Begin formatting.
void setId(const char *id, std::size_t len)
Sets the reference ID.
void setInt64(Pt::int64_t l)
Set to 64-bit integer value.
Type
Type identifier.
Definition: SerializationInfo.h:65
void setString(const std::string &str, const TextCodec< Pt::Char, char > &codec)
Set to string value.
Definition: SerializationInfo.h:299
SerializationInfo & addMember(const std::string &name)
Add a struct member.
Definition: SerializationInfo.h:449
SerializationInfo()
Default constructor.
Definition: SerializationInfo.h:93
Type type() const
Returns the type identifier.
Definition: SerializationInfo.h:134
const char * getBinary(std::size_t &length) const
Get value as a binary object.
void getChar(Pt::Char &c) const
Get value as a character.
SerializationInfo * parent()
Returns the parent node.
Definition: SerializationInfo.h:206
void setLongDouble(long double d)
Set to long double value.
void setInt32(Pt::int32_t n)
Set to 32-bit integer value.
const SerializationInfo & getMember(const char *name) const
Get a struct member.
const char * name() const
Returns the instance name.
Definition: SerializationInfo.h:237
void loadReference(T &fixme, unsigned mid=0) const
Load a reference during deserialization.
Definition: SerializationInfo.h:579
void setName(const char *name)
Sets the instance name.
void setReference(const char *id, std::size_t idlen)
Set to reference with ID to fixup.
SerializationInfo(SerializationContext *context)
Construct with context.
Definition: SerializationInfo.h:109
bool isVoid() const
Returns true if not set to a type.
Definition: SerializationInfo.h:139
void getString(std::string &s, const TextCodec< Pt::Char, char > &codec) const
Get value as a string.
bool isDict() const
Returns true if dictionary type.
Definition: SerializationInfo.h:158
SerializationInfo & addElement()
Add a sequence element.
void setTypeName(const char *type, std::size_t len)
Sets the type name.
void setDouble(double f)
Set to double value.
void getDouble(double &f) const
Get value as a double.
void setName(const LiteralPtr< char > &type)
Sets the instance name.
const SerializationInfo * findMember(const char *name) const
Find a struct member.
void setName(const std::string &name)
Sets the instance name.
void setBool(bool b)
Set to bool value.
Context for the serialization of types.
Definition: SerializationContext.h:21
uint_type uint64_t
Unsigned 64-bit integer type.
Definition: Types.h:54
int_type int64_t
Signed 64-bit integer type.
Definition: Types.h:48
const SerializationInfo * parent() const
Returns the parent node.
Definition: SerializationInfo.h:211
void clear()
Clears all content.
void getUInt8(Pt::uint8_t &n) const
Get value as a 8-bit unsigned integer.
Unicode character type.
Definition: String.h:67
void finishLoad() const
Finish loading.
void setBinary(const char *data, std::size_t length)
Set to binary value.
void setChar(char c)
Set to character value.
ConstIterator begin() const
Returns an iterator to the begin of child elements.
void getLongDouble(long double &d) const
Get value as a long double.
const SerializationInfo & getMember(const std::string &name) const
Get a struct member.
Definition: SerializationInfo.h:496
SerializationInfo & addMember(const char *name, std::size_t len)
Add a struct member.
SerializationInfo & addDictElement()
Add a dict element.
void loadPointer(T *&fixme, unsigned mid=0) const
Load a reference during deserialization.
Definition: SerializationInfo.h:587
Const forward iterator for child elements.
Definition: SerializationInfo.h:783
void setUInt64(Pt::uint64_t n)
Set to 64-bit unsigned integer value.
void setName(const char *type, std::size_t len)
Sets the instance name.
SerializationInfo & addMember(const LiteralPtr< char > &name)
Add a struct member.
void setString(const char *s)
Set to string value.
void getInt64(Pt::int64_t &l) const
Get value as a 64-bit integer.
const SerializationInfo * findMember(const std::string &name) const
Find a struct member.
Definition: SerializationInfo.h:508
const SerializationInfo & in() const
Returns the SerializationInfo to load from.
Definition: SerializationInfo.h:925
bool isReference() const
Returns true if reference.
Definition: SerializationInfo.h:168
void removeMember(const char *name)
Remove a struct member.
const char * typeName() const
Returns the type name.
Definition: SerializationInfo.h:216
void getString(std::string &s) const
Get value as a string.
void setFloat(float f)
Set to float value.
Forward Iterator for child elements.
Definition: SerializationInfo.h:738
void setUInt32(Pt::uint32_t n)
Set to 32-bit unsigned integer value.
void rebind(void *obj) const
Rebind to new address.
void setInt8(Pt::int8_t n)
Set to 8-bit integer value.
void setDict()
Set to dictionary type.
void setVoid()
Set to void type.
Represents a pointer to a literal.
Definition: LiteralPtr.h:40
void getInt16(Pt::int16_t &n) const
Get value as a 16-bit integer.
void setTypeName(const LiteralPtr< char > &type)
Sets the type name.
void setId(const std::string &id)
Sets the reference ID.
void setId(const char *id)
Sets the reference ID.
void setString(const Pt::Char *s, std::size_t len)
Set to string value.
bool decompose(const T &type)
Returns true if the type could be decomposed with a surrogate.
Definition: SerializationInfo.h:724
bool compose(T &type) const
Returns true if the type could be composed with a surrogate.
Definition: SerializationInfo.h:712
uint_type uint8_t
Unsigned 8-bit integer type.
Definition: Types.h:18
std::size_t memberCount() const
Returns the number of members.
void setTypeName(const char *type)
Sets the type name.
void format(Formatter &formatter) const
Format complete value or all members.
uint_type uint32_t
Unsigned 32-bit integer type.
Definition: Types.h:42
void getString(Pt::String &s) const
Get value as a string.
void getInt32(Pt::int32_t &i) const
Get value as a 32-bit integer.
int_type int32_t
Signed 32-bit integer type.
Definition: Types.h:36
void removeMember(const std::string &name)
Remove a struct member.
Definition: SerializationInfo.h:467
void removeMember(const SerializationInfo &si)
Remove a struct member.
Unicode capable basic_string.
Definition: String.h:43
SerializationInfo & addMember(const char *name)
Add a struct member.
Definition: SerializationInfo.h:454
SerializationInfo * findMember(const char *name)
Find a struct member.
void getBool(bool &b) const
Get value as a bool.
int_type int8_t
Signed 8-bit integer type.
Definition: Types.h:12
void setString(const std::string &s)
Set to string value.
const char * id() const
Returns the reference ID.
Definition: SerializationInfo.h:258
void getUInt32(Pt::uint32_t &n) const
Get value as a 32-bit unsigned integer.
void setReference(const std::string &id)
Set to reference with ID to fixup.
Definition: SerializationInfo.h:569
void setSequence()
Set to sequence type.
void setInt16(Pt::int16_t n)
Set to 16-bit integer value.
uint_type uint16_t
Unsigned 16-bit integer type.
Definition: Types.h:30
Represents arbitrary types during serialization.
Definition: SerializationInfo.h:59
int_type int16_t
Signed 16-bit integer type.
Definition: Types.h:24
Iterator begin()
Returns an iterator to the begin of child elements.
void rebindFixup(void *obj) const
Rebind to new fixup address.
void getChar(char &c) const
Get value as a character.
bool isScalar() const
Returns true if scalar type.
Definition: SerializationInfo.h:148
SerializationInfo & addDictKey()
Add a dict key.
SerializationInfo * findMember(const std::string &name)
Find a struct member.
Definition: SerializationInfo.h:523
void getFloat(float &f) const
Get value as a float.
~SerializationInfo()
Destructor.