SerializationProxy

class SerializationProxy

A SerializationProxy is an object that knows how to serialize and deserialize objects of a particular type. This is an abstract class. Subclasses implement the logic for serializing particular types of logic.

A global registry maintains the list of what SerializationProxy to use for each type of object. Call registerProxy() to register the proxy for a particular type. This is typically done at application startup or by a dynamic library’s initialization code.

Public Functions

SerializationProxy(const std::string &typeName)

Create a new SerializationProxy.

Parameters

typeName – the name of the object type this proxy knows how to serialize. This name is stored in the output stream during serialization, and is used to select a proxy during deserialization. This typically is the class name, although that is not a requirement.

const std::string &getTypeName() const

Get the name of the object type this proxy manipulates, as passed to the constructor.

virtual void serialize(const void *object, SerializationNode &node) const = 0

Subclasses implement this method to record information about an object being serialized.

Parameters
  • object – a pointer to the object being serialized

  • node – all data to be serialized should be stored into this node, either directly as properties or indirectly by adding child nodes to it

virtual void *deserialize(const SerializationNode &node) const = 0

Reconstruct an object from its serialized data.

Parameters

node – a SerializationNode containing the object’s description

Returns

a pointer to a new object created from the data. The caller assumes ownership of the object.

Public Static Functions

static void registerProxy(const std::type_info &type, const SerializationProxy *proxy)

Register a SerializationProxy to be used for objects of a particular type.

Parameters
  • type – the type_info for the object type

  • proxy – the proxy to use for objects of the specified type

static const SerializationProxy &getProxy(const std::string &typeName)

Get the SerializationProxy to use for objects of a particular type, specified by name.

Parameters

typeName – the name of the object type to get a proxy for

static const SerializationProxy &getProxy(const std::type_info &type)

Get the SerializationProxy to use for objects of a particular type, specified by type_info.

Parameters

type – the type_info of the object type to get a proxy for