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 tr::s_factory
< serializable_type,
serializable_interface_type >
::type 
factory_type
 Type which will be used to instantiate new objects of serializable_type.
typedef tr::s_sfunc
< serializable_type,
serializable_interface_type >
::type 
serialize_functor
 Functor type implementing serialize code.
typedef tr::s_dfunc
< serializable_type,
serializable_interface_type >
::type 
deserialize_functor
 Functor type implementing deserialize code.
typedef tr::s_cleaner
< serializable_type,
serializable_interface_type >
::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_interface_type *hint)
 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 464 of file traits.hpp.


Member Typedef Documentation

template<typename SerializableT, typename InterfaceType = SerializableT>
typedef tr::s_cleaner<serializable_type,serializable_interface_type>::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 533 of file traits.hpp.

template<typename SerializableT, typename InterfaceType = SerializableT>
typedef tr::s_dfunc<serializable_type,serializable_interface_type>::type 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 521 of file traits.hpp.

template<typename SerializableT, typename InterfaceType = SerializableT>
typedef tr::s_factory<serializable_type,serializable_interface_type>::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 502 of file traits.hpp.

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 481 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 486 of file traits.hpp.

template<typename SerializableT, typename InterfaceType = SerializableT>
typedef tr::s_sfunc<serializable_type,serializable_interface_type>::type 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 512 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 471 of file traits.hpp.

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

Definition at line 472 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_interface_type hint  )  [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:

  • It really should take a default value of 0 for instance_hint, but the idea of relying on a default value, considering things like how template specializations should define them and subclassing (though that is not an issue *here*), gives me the willies. Too much room for error there.
  • Also, we could probably argue that it should return a const string.
  • We could argue that it should return an empty string instead of a useless one. i don't want to to generate output which might break parsers, though.

Definition at line 573 of file traits.hpp.


The documentation for this struct was generated from the following file:

Generated on Sat Mar 20 12:29:25 2010 for libs11n-1.2.10 by  doxygen 1.6.1