#include <Pt/Composer.h>
Composes types during serialization. More...
Inherited by BasicComposer< Pt::SerializationInfo >, BasicComposer< R >, BasicComposer< Pt::XmlRpc::Fault >, BasicComposer< T >, and BasicComposer< Pt::SerializationInfo >.
Public Member Functions | |
| virtual | ~Composer () |
| Destructor. | |
| void | setParent (Composer *parent) |
| Sets the parent composer. | |
| Composer * | parent () const |
| Returns the parent composer. | |
| void | setTypeName (const std::string &type) |
| Sets the type name of the type to compose. | |
| void | setTypeName (const char *type, std::size_t len) |
| Sets the type name of the type to compose. | |
| void | setId (const std::string &id) |
| Sets the reference id of the type to compose. | |
| void | setId (const char *id, std::size_t len) |
| Sets the reference id of the type to compose. | |
| void | setString (const Pt::String &value) |
| Composes a string value. | |
| void | setString (const Pt::Char *value, std::size_t len) |
| Composes a string value. | |
| void | setBinary (const char *data, std::size_t length) |
| Composes a binary value. | |
| void | setChar (const Pt::Char &ch) |
| Composes a char value. | |
| void | setBool (bool value) |
| Composes a boolean value. | |
| void | setInt (Pt::int64_t value) |
| Composes a signed integer type. | |
| void | setUInt (Pt::int64_t value) |
| Composes an unsigned integer type. | |
| void | setFloat (long double value) |
| Composes a float value. | |
| void | setReference (const std::string &id) |
| Composes a reference. | |
| void | setReference (const char *id, std::size_t len) |
| Composes a reference. | |
| Composer * | beginMember (const std::string &name) |
| Begins composition of a struct member. | |
| Composer * | beginMember (const char *name, std::size_t len) |
| Begins composition of a struct member. | |
| Composer * | beginElement () |
| Begins composition of a sequence member. | |
| Composer * | beginDictElement () |
| Begins composition of a dict key. | |
| Composer * | beginDictKey () |
| Begins composition of a dict key. | |
| Composer * | beginDictValue () |
| Begins composition of a dict value. | |
| Composer * | finish () |
| Finishes composition of a struct or sequence member. | |
Protected Member Functions | |
| Composer () | |
| Constructor. | |
| virtual void | onSetTypeName (const char *, std::size_t) |
| Set type name. | |
| virtual void | onSetId (const char *id, std::size_t len)=0 |
| Set reference ID. | |
| virtual void | onSetString (const Pt::Char *, std::size_t) |
| Compose a string value. | |
| virtual void | onSetBinary (const char *, std::size_t) |
| Compose a binary value. | |
| virtual void | onSetChar (const Pt::Char &) |
| Compose a character value. | |
| virtual void | onSetBool (bool) |
| Compose a bool value. | |
| virtual void | onSetInt (Pt::int64_t) |
| Compose a integer value. | |
| virtual void | onSetUInt (Pt::uint64_t) |
| Compose a unsigned integer value. | |
| virtual void | onSetFloat (long double) |
| Compose a floating point value. | |
| virtual void | onSetReference (const char *, std::size_t) |
| Compose a reference. | |
| virtual Composer * | onBeginMember (const char *, std::size_t) |
| Begin composition os a struct member. | |
| virtual Composer * | onBeginElement () |
| Begins composition of a sequence member. | |
| virtual Composer * | onBeginDictElement () |
| Begins composition of a dict key. | |
| virtual Composer * | onBeginDictKey () |
| Begins composition of a dict key. | |
| virtual Composer * | onBeginDictValue () |
| Begins composition of a dict value. | |
| virtual Composer * | onFinish () |
| Finishes composition of a struct or sequence member. | |
Implementing the serialization operators is not the only way to make a type serializable. An alternative is to specialize Pt::BasicComposer. The default implementation of BasicComposer uses the serialization operators and a tree of SerializationInfo objects, which is fine for small and medium sized objects. The parsing layer interacts with this class to compose the actual type, and this layer can be completely customized. This is normally done for container types, where building the complete tree of SerializationInfo objects in memory is undesirable. The following example shows a specialization for std::vector:
The specialized BasicComposer inherits Composer, which is the interface used by the deserializer to report parse events. The virtual functions onBeginElement() and onSetId() are overridden to build the vector from the parse events. onBeginElement() is called when the beginning of a vector element has been parsed; it sets up and returns a composer for the new element in the vector. A constructor is required that optionally takes a reference to a SerializationContext; the context can be used in onSetId() to map a reference id to the vector being composed, if another object has a weak reference to it. The begin() function is also required, to set up the composer to start composing a type. A composer may delegate to other composers, which might or might not be specialized; here, the composer for the element type is used, which works for a vector of vectors right away.
| void setTypeName | ( | const std::string & | type | ) |
This is only supported by formats that save typename information.
| void setTypeName | ( | const char * | type, |
| std::size_t | len ) |
This is only supported by formats that save typename information.
| void setId | ( | const std::string & | id | ) |
This is only supported by formats that support references.
| void setId | ( | const char * | id, |
| std::size_t | len ) |
This is only supported by formats that support references.
| void setInt | ( | Pt::int64_t | value | ) |
There is only one method for all sizes of signed integer types, because that type information is not required for composition.
| void setUInt | ( | Pt::int64_t | value | ) |
There is only one method for all sizes of unsigned integer types, because that type information is not required for composition.