s11n::s11n_traits< SerializableT, InterfaceType > Struct Template Reference

s11n_traits encapsulates information about what type(s) are responsible for handling de/serialize operations for a given type, plus the factory for that type. More...

#include <traits.hpp>

List of all members.

Public Types

typedef InterfaceType serializable_interface_type
 The InterfaceType.
typedef SerializableT serializable_type
 The type of object we want to [de]serialize.
typedef
::s11n::cl::object_factory
< serializable_interface_type
factory_type
 Type which will be used to instantiate new objects of serializable_type.
typedef
::s11n::default_serialize_functor 
serialize_functor
 Functor type implementing serialize code.
typedef
::s11n::default_serialize_functor 
deserialize_functor
 Functor type implementing deserialize code.
typedef
::s11n::default_cleanup_functor
< serializable_type
cleanup_functor
 This type is used to clean up a partial deserialized object on error.

Public Member Functions

 s11n_traits ()
 The s11n framework instantiates an s11n_traits object at some points to allow the traits object to do things like factory registration.
 ~s11n_traits ()

Static Public Member Functions

static const std::string class_name (const serializable_type *)
 As of s11n 1.1, specializations must define the class_name() function.


Detailed Description

template<typename SerializableT, typename InterfaceType = SerializableT>
struct s11n::s11n_traits< SerializableT, InterfaceType >

s11n_traits encapsulates information about what type(s) are responsible for handling de/serialize operations for a given type, plus the factory for that type.

It should be specialized to define various aspects of serialization for a given type.

The interface shown here is the bare minimum which s11n_traits specializations must implement. Specializations may optionally add to the interface, but client code is discouraged from relying on any extensions.

This type is stateless, and specializations are expected to be stateless (at least, they will be treated as if they are).

Client code is not expected to need to use this type directly, except for purposes of plugging in their types into the s11n framework. More specifically, it is not expected that Serializables will use this type.

Parameterized on:

SerializableT: the base-most Serializable type. This is the base-most point of reference for classloading and "template typing". Subclasses of SerializableT are assumed to be handleable via the same de/serialize interface as SerializableT.

InterfaceType is the base Serializable interface which SerializableT is assumed to subclass. The default is SerializableT. This type is required for cases where SerializableT wants to register with multiple Serializable interfaces.

Changes from 1.0.x to 1.1.x:

Definition at line 413 of file traits.hpp.


Member Typedef Documentation

template<typename SerializableT, typename InterfaceType = SerializableT>
typedef InterfaceType s11n::s11n_traits< SerializableT, InterfaceType >::serializable_interface_type

The InterfaceType.

Added in 1.3.1. This is needed for cases where a Serializable wants to be registered with several Serializable interfaces. If we don't have this key then ODR violations happen on the second and subsequent registration.

Definition at line 430 of file traits.hpp.

template<typename SerializableT, typename InterfaceType = SerializableT>
typedef SerializableT s11n::s11n_traits< SerializableT, InterfaceType >::serializable_type

The type of object we want to [de]serialize.

Definition at line 435 of file traits.hpp.

template<typename SerializableT, typename InterfaceType = SerializableT>
typedef ::s11n::cl::object_factory<serializable_interface_type> s11n::s11n_traits< SerializableT, InterfaceType >::factory_type

Type which will be used to instantiate new objects of serializable_type.

It must implement:

serializable_type * operator()( const std::string & classname ) const;

It is expected to return, polymorphically if possible, a new serializable_type on success or 0 on failure.

The default factory_type works with types registered via the s11n::cl::classload() family of functions.

Definition at line 451 of file traits.hpp.

template<typename SerializableT, typename InterfaceType = SerializableT>
typedef ::s11n::default_serialize_functor s11n::s11n_traits< SerializableT, InterfaceType >::serialize_functor

Functor type implementing serialize code.

Must implement:

bool operator()( SomeNodeType & dest, const base_type & src ) const;

Definition at line 461 of file traits.hpp.

template<typename SerializableT, typename InterfaceType = SerializableT>
typedef ::s11n::default_serialize_functor s11n::s11n_traits< SerializableT, InterfaceType >::deserialize_functor

Functor type implementing deserialize code.

Must implement:

bool operator()( const SomeNodeType & src, base_type & dest ) const;

Definition at line 470 of file traits.hpp.

template<typename SerializableT, typename InterfaceType = SerializableT>
typedef ::s11n::default_cleanup_functor<serializable_type> s11n::s11n_traits< SerializableT, InterfaceType >::cleanup_functor

This type is used to clean up a partial deserialized object on error.

If this functor, and all specializations it calls, do their part, we can make much better exception guarantees, theoretically avoiding any leaks due to exceptions thrown during deserialization.

cleanup_functor must follow the conventions laid out by s11n::default_cleanup_functor<serializable_type>.

Definition at line 482 of file traits.hpp.


Constructor & Destructor Documentation

template<typename SerializableT, typename InterfaceType = SerializableT>
s11n::s11n_traits< SerializableT, InterfaceType >::s11n_traits (  )  [inline]

The s11n framework instantiates an s11n_traits object at some points to allow the traits object to do things like factory registration.

Definition at line 420 of file traits.hpp.

template<typename SerializableT, typename InterfaceType = SerializableT>
s11n::s11n_traits< SerializableT, InterfaceType >::~s11n_traits (  )  [inline]

Definition at line 421 of file traits.hpp.


Member Function Documentation

template<typename SerializableT, typename InterfaceType = SerializableT>
static const std::string s11n::s11n_traits< SerializableT, InterfaceType >::class_name ( const serializable_type  )  [inline, static]

As of s11n 1.1, specializations must define the class_name() function.

This implementation returns a useless, unspecified class name. Specializations must return the class name of serializable_type, preferably polymorphically (polymorphic naming is unfortunately not possible without some client-side help).

instance_hint is a HINT to this class as to the actual instance we want the name for, and may be 0. It is provided so that class hierarchies which have virtual functions like className() can make those available to the core library via s11n_traits specializations.

Specializations MUST accept 0 as a valid instance_hint value are are NEVER REQUIRED to pay any attention to instance_hint. The default implementation does nothing with it.

Design notes:

Definition at line 522 of file traits.hpp.


The documentation for this struct was generated from the following file:
Generated on Wed Jun 4 21:45:47 2008 for libs11n-1.2.7 by  doxygen 1.5.3