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);
198 void rebind(
void* obj)
const;
202 void rebindFixup(
void* obj)
const;
217 {
return _TypeName; }
221 void setTypeName(
const std::string& type);
225 void setTypeName(
const char* type);
229 void setTypeName(
const char* type, std::size_t len);
242 void setName(
const std::string& name);
246 void setName(
const char* name);
250 void setName(
const char* type, std::size_t len);
258 const char*
id()
const
263 void setId(
const std::string&
id);
267 void setId(
const char*
id);
271 void setId(
const char*
id, std::size_t len);
279 void getString(std::string& s)
const;
287 void setString(
const char* s);
295 void setString(
const std::string& s);
300 { setString(str.c_str(), str.size(), codec); }
309 void setString(
const Pt::Char* s, std::size_t len);
313 const char* getBinary(std::size_t& length)
const;
317 void setBinary(
const char* data, std::size_t length);
321 void getChar(
char c)
const;
325 void setChar(
char c);
337 void getBool(
bool& b)
const;
341 void setBool(
bool b);
409 void getFloat(
float& f)
const;
413 void setFloat(
float f);
417 void getDouble(
double& f)
const;
421 void setDouble(
double f);
425 void getLongDouble(
long double& d)
const;
429 void setLongDouble(
long double d);
433 bool beginSave(
const void* p);
441 void beginLoad(
void* p,
const std::type_info& ti)
const;
445 void finishLoad()
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() ); }
472 void removeMember(
const char* name);
493 {
return this->getMember( name.c_str() ); }
505 {
return this->findMember( name.c_str() ); }
520 {
return this->findMember( name.c_str() ); }
531 std::size_t memberCount()
const;
540 void setSibling(SerializationInfo* si)
553 ConstIterator begin()
const;
557 ConstIterator end()
const;
561 void setReference(
const void* ref);
566 { setReference(
id.c_str(),
id.length() ); }
570 void setReference(
const char*
id, std::size_t idlen);
574 template <
typename T>
577 this->load(&fixme, FixupThunk<T>::fixupReference, mid);
582 template <
typename T>
585 this->load(&fixme, FixupThunk<T>::fixupPointer, mid);
590 Iterator beginFormat(
Formatter& formatter);
605 template <
typename T>
606 const BasicSerializationSurrogate<T>* getSurrogate()
const;
609 template <
typename T>
613 const SerializationSurrogate* getSurrogate(
const std::type_info& ti)
const;
616 void load(
void* fixme, FixupInfo::FixupHandler fh,
unsigned mid)
const;
628 SerializationInfo& operator=(
const SerializationInfo&)
652 SerializationInfo* first;
653 SerializationInfo* last;
662 unsigned long long ul;
671 mutable Variant _value;
672 SerializationContext* _context;
673 SerializationInfo* _parent;
674 SerializationInfo* _next;
676 const char* _TypeName;
696 template <
typename T>
697 inline const BasicSerializationSurrogate<T>* SerializationInfo::getSurrogate()
const
699 const SerializationSurrogate* surr = this->getSurrogate(
typeid(T) );
703 return static_cast<const BasicSerializationSurrogate<T>*
>(surr);
707 template <
typename T>
710 const BasicSerializationSurrogate<T>* surr = this->getSurrogate<T>();
714 surr->compose(*
this, type);
719 template <
typename T>
722 const BasicSerializationSurrogate<T>* surr = this->getSurrogate<T>();
726 surr->decompose(*
this, type);
756 _si = _si->sibling();
766 bool operator!=(
const Iterator& other)
const
767 {
return _si != other._si; }
769 bool operator==(
const Iterator& other)
const
770 {
return _si == other._si; }
801 _si = _si->sibling();
812 {
return _si != other._si; }
815 {
return _si == other._si; }
853 template <
typename T>
880 inline SaveInfo operator <<(SerializationInfo& si,
const Save&)
886 template <
typename T>
887 inline void operator <<=(SaveInfo info,
const T& type)
897 template <
typename T>
900 if( ! si.
save(type) )
926 template <
typename T>
951 inline LoadInfo operator >>(
const SerializationInfo& si,
const Load&)
957 template <
typename T>
958 inline void operator >>=(
const LoadInfo& li, T& type)
968 template <
typename T>
979 template <
typename T>
989 template <
typename T>
1220 ch =
static_cast<char>( tmp.
value() );
1281 template <
typename T,
typename A>
1291 vec.push_back(elem);
1292 *it >> Pt::load() >>= vec.back();
1300 template <
typename T,
typename A>
1301 inline void operator <<=(SerializationInfo& si, const std::vector<T, A>& vec)
1303 typename std::vector<T, A>::const_iterator it;
1305 for(it = vec.begin(); it != vec.end(); ++it)
1307 si.addElement() << Pt::save() <<= *it;
1318 template <
typename T,
typename A>
1324 list.resize( list.size() + 1 );
1325 *it >> Pt::load() >>= list.back();
1333 template <
typename T,
typename A>
1334 inline void operator <<=(SerializationInfo& si, const std::list<T, A>& list)
1336 typename std::list<T, A>::const_iterator it;
1338 for(it = list.begin(); it != list.end(); ++it)
1340 si.addElement() << Pt::save() <<= *it;
1351 template <
typename T,
typename A>
1358 deque.push_back( T() );
1359 *it >> Pt::load() >>= deque.back();
1367 template <
typename T,
typename A>
1368 inline void operator <<=(SerializationInfo& si, const std::deque<T, A>& deque)
1370 typename std::deque<T, A>::const_iterator it;
1372 for(it = deque.begin(); it != deque.end(); ++it)
1374 si.addElement() << Pt::save() <<= *it;
1390 template <
typename T,
typename C,
typename A>
1416 template <
typename T,
typename C,
typename A>
1417 inline void operator <<=(SerializationInfo& si, const std::set<T, C, A>& set)
1419 typename std::set<T, C, A>::const_iterator it;
1421 for(it = set.begin(); it != set.end(); ++it)
1423 si.addElement() << Pt::save() <<= *it;
1438 template <
typename T,
typename C,
typename A>
1463 template <
typename T,
typename C,
typename A>
1464 inline void operator <<=(SerializationInfo& si, const std::multiset<T, C, A>& multiset)
1466 typename std::multiset<T, C, A>::const_iterator it;
1468 for(it = multiset.begin(); it != multiset.end(); ++it)
1470 si.addElement() << Pt::save() <<= *it;
1478 template <
typename A,
typename B>
1486 template <
typename A,
typename B>
1487 inline void operator <<=(SerializationInfo& si, const std::pair<A, B>& p)
1498 template <
typename K,
typename V,
typename P,
typename A>
1501 typedef typename std::map<K, V, P, A>::iterator MapIterator;
1502 std::pair<MapIterator, bool> pos;
1510 if( kv != it->
end() )
1513 std::pair<K, V> elem( k, V() );
1514 pos = map.insert(elem);
1516 if( pos.second && ++kv != it->
end() )
1517 *kv >> Pt::load() >>= pos.first->second;
1525 template <
typename K,
typename V,
typename P,
typename A>
1526 inline void operator <<=(SerializationInfo& si, const std::map<K, V, P, A>& map)
1528 typename std::map<K, V, P, A>::const_iterator it;
1530 for(it = map.begin(); it != map.end(); ++it)
1545 template <
typename K,
typename V,
typename P,
typename A>
1548 typename std::multimap<K, V, P, A>::iterator mit;
1556 if( kv != it->
end() )
1559 std::pair<K, V> elem( k, V() );
1560 mit = multimap.insert(elem);
1562 if( ++kv != it->
end() )
1563 *kv >> Pt::load() >>= mit->second;
1571 template <
typename T,
typename C,
typename P,
typename A>
1572 inline void operator <<=(SerializationInfo& si, const std::multimap<T, C, P, A>& multimap)
1574 typename std::multimap<T, C, P, A>::const_iterator it;
1576 for(it = multimap.begin(); it != multimap.end(); ++it)
1589 #endif // Pt_SerializationInfo_h
void getUInt64(Pt::uint64_t &n) const
Get value as a 64-bit unsigned integer.
uint_type uint16_t
Unsigned 16-bit integer type.
Definition: Types.h:30
void setReference(const std::string &id)
Set to reference with ID to fixup.
Definition: SerializationInfo.h:565
const SerializationInfo * findMember(const std::string &name) const
Find a struct member.
Definition: SerializationInfo.h:504
void getChar(char c) const
Get value as a character.
Const forward iterator for child elements.
Definition: SerializationInfo.h:778
Type type() const
Returns the type identifier.
Definition: SerializationInfo.h:134
const char * name() const
Returns the instance name.
Definition: SerializationInfo.h:237
void finishSave()
Finish saving.
int_type int16_t
Signed 16-bit integer type.
Definition: Types.h:24
void setReference(const void *ref)
Set to reference for which to create an ID.
SerializationInfo & out() const
Returns the SerializationInfo to save to.
Definition: SerializationInfo.h:848
Loads referencable types.
Definition: SerializationInfo.h:911
void getUInt16(Pt::uint16_t &n) const
Get value as a 16-bit unsigned integer.
SerializationInfo()
Default constructor.
Definition: SerializationInfo.h:93
SerializationInfo * parent()
Returns the parent node.
Definition: SerializationInfo.h:206
void finishLoad() const
Finish loading.
std::size_t memberCount() const
Returns the number of members.
void getBool(bool &b) const
Get value as a bool.
bool isReference() const
Returns true if reference.
Definition: SerializationInfo.h:168
bool isStruct() const
Returns true if struct type.
Definition: SerializationInfo.h:153
Iterator end()
Returns an iterator to the end of child elements.
Definition: SerializationInfo.h:822
void setDouble(double f)
Set to double value.
Type
Type identifier.
Definition: SerializationInfo.h:65
const SerializationInfo & in() const
Returns the SerializationInfo to load from.
Definition: SerializationInfo.h:921
void getLongDouble(long double &d) const
Get value as a long double.
void save(SaveInfo &si, const T &type)
Saves referencable types.
Definition: SerializationInfo.h:898
void setUInt16(Pt::uint16_t n)
Set to 16-bit unsigned integer value.
void beginLoad(void *p, const std::type_info &ti) const
Begin loading.
void setInt64(Pt::int64_t l)
Set to 64-bit integer value.
void getInt8(Pt::int8_t &n) const
Get value as a 8-bit integer.
SerializationInfo & addMember(const std::string &name)
Add a struct member.
Definition: SerializationInfo.h:449
SerializationInfo & addDictValue()
Add a dict value.
void setInt32(Pt::int32_t n)
Set to 32-bit integer value.
void getInt32(Pt::int32_t &i) const
Get value as a 32-bit integer.
uint32_t value() const
Returns the unicode value.
Definition: String.h:90
bool beginSave(const void *p)
Begin saving.
void getUInt8(Pt::uint8_t &n) const
Get value as a 8-bit unsigned integer.
const SerializationInfo * parent() const
Returns the parent node.
Definition: SerializationInfo.h:211
void setString(const std::string &str, const TextCodec< Pt::Char, char > &codec)
Set to string value.
Definition: SerializationInfo.h:299
bool isDict() const
Returns true if dictionary type.
Definition: SerializationInfo.h:158
const Pt::Char * c_str() const
Returns a null terminated C string.
Definition: String.h:264
bool save(const T &type)
Returns true if type was saved, false if type was already saved.
Definition: SerializationInfo.h:854
void setLongDouble(long double d)
Set to long double value.
void getInt64(Pt::int64_t &l) const
Get value as a 64-bit integer.
void setFloat(float f)
Set to float value.
int_type int32_t
Signed 32-bit integer type.
Definition: Types.h:36
void setUInt32(Pt::uint32_t n)
Set to 32-bit unsigned integer value.
void setUInt64(Pt::uint64_t n)
Set to 64-bit unsigned integer value.
void loadPointer(T *&fixme, unsigned mid=0) const
Load a reference during deserialization.
Definition: SerializationInfo.h:583
SerializationInfo(SerializationContext *context)
Construct with context.
Definition: SerializationInfo.h:109
Unicode character type.
Definition: String.h:66
size_type length() const
Returns the length of the string.
Definition: String.h:234
int_type int64_t
Signed 64-bit integer type.
Definition: Types.h:48
Saves referencable types.
Definition: SerializationInfo.h:838
const char * typeName() const
Returns the type name.
Definition: SerializationInfo.h:216
void setBool(bool b)
Set to bool value.
void getString(std::string &s, const TextCodec< Pt::Char, char > &codec) const
Get value as a string.
bool decompose(const T &type)
Returns true if the type could be decomposed with a surrogate.
Definition: SerializationInfo.h:720
void clear()
Clears all content.
void getDouble(double &f) const
Get value as a double.
void setInt8(Pt::int8_t n)
Set to 8-bit integer value.
void setDict()
Set to dictionary type.
int_type int8_t
Signed 8-bit integer type.
Definition: Types.h:12
void setChar(char c)
Set to character value.
bool compose(T &type) const
Returns true if the type could be composed with a surrogate.
Definition: SerializationInfo.h:708
bool isSequence() const
Returns true if sequence type.
Definition: SerializationInfo.h:163
SerializationInfo & addDictElement()
Add a dict element.
Represents a pointer to a literal.
Definition: LiteralPtr.h:39
uint_type uint64_t
Unsigned 64-bit integer type.
Definition: Types.h:54
void load(T &type) const
Loads the type.
Definition: SerializationInfo.h:927
Unicode capable basic_string.
Definition: String.h:42
void setString(const char *s)
Set to string value.
Void type.
Definition: Void.h:43
const SerializationInfo & getMember(const std::string &name) const
Get a struct member.
Definition: SerializationInfo.h:492
uint_type uint32_t
Unsigned 32-bit integer type.
Definition: Types.h:42
void setInt16(Pt::int16_t n)
Set to 16-bit integer value.
void removeMember(const std::string &name)
Remove a struct member.
Definition: SerializationInfo.h:467
Context for the serialization of types.
Definition: SerializationContext.h:20
uint_type uint8_t
Unsigned 8-bit integer type.
Definition: Types.h:18
void getFloat(float &f) const
Get value as a float.
Represents arbitrary types during serialization.
Definition: SerializationInfo.h:58
Iterator begin()
Returns an iterator to the begin of child elements.
void loadReference(T &fixme, unsigned mid=0) const
Load a reference during deserialization.
Definition: SerializationInfo.h:575
SerializationInfo & addDictKey()
Add a dict key.
bool isVoid() const
Returns true if not set to a type.
Definition: SerializationInfo.h:139
void setUInt8(Pt::uint8_t n)
Set to 8-bit unsigned integer value.
void getUInt32(Pt::uint32_t &n) const
Get value as a 32-bit unsigned integer.
const char * id() const
Returns the reference ID.
Definition: SerializationInfo.h:258
void load(const LoadInfo &li, T &type)
Loads referencable types.
Definition: SerializationInfo.h:969
Forward Iterator for child elements.
Definition: SerializationInfo.h:733
SerializationInfo * findMember(const std::string &name)
Find a struct member.
Definition: SerializationInfo.h:519
SerializationContext * context() const
Returns the used context.
Definition: SerializationInfo.h:185
void getInt16(Pt::int16_t &n) const
Get value as a 16-bit integer.
void setString(const Pt::String &s)
Set to string value.
Definition: SerializationInfo.h:304
SerializationInfo & addMember(const char *name)
Add a struct member.
Definition: SerializationInfo.h:454
void setTypeName(const std::string &type)
Sets the type name.
bool isScalar() const
Returns true if scalar type.
Definition: SerializationInfo.h:148