Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

s11n::s11n_traits< SerializableT > 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>

Inheritance diagram for s11n::s11n_traits< SerializableT >:

Inheritance graph
[legend]
List of all members.

Public Types

typedef SerializableT serializable_type
 The type of object we want to [de]serialize.
typedef ::s11n::cl::object_factory<
serializable_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 *instance_hint)
 As of s11n 1.1, specializations must define the class_name() function.

Detailed Description

template<typename SerializableT>
struct s11n::s11n_traits< SerializableT >

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.

Changes from 1.0.x to 1.1.x:

Definition at line 405 of file traits.hpp.


Member Typedef Documentation

template<typename SerializableT>
typedef ::s11n::default_cleanup_functor<serializable_type> s11n::s11n_traits< SerializableT >::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 465 of file traits.hpp.

template<typename SerializableT>
typedef ::s11n::default_serialize_functor s11n::s11n_traits< SerializableT >::deserialize_functor
 

Functor type implementing deserialize code.

Must implement:

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

Definition at line 453 of file traits.hpp.

template<typename SerializableT>
typedef ::s11n::cl::object_factory<serializable_type> s11n::s11n_traits< SerializableT >::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 434 of file traits.hpp.

template<typename SerializableT>
typedef SerializableT s11n::s11n_traits< SerializableT >::serializable_type
 

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

Definition at line 418 of file traits.hpp.

template<typename SerializableT>
typedef ::s11n::default_serialize_functor s11n::s11n_traits< SerializableT >::serialize_functor
 

Functor type implementing serialize code.

Must implement:

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

Definition at line 444 of file traits.hpp.


Constructor & Destructor Documentation

template<typename SerializableT>
s11n::s11n_traits< SerializableT >::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 412 of file traits.hpp.

template<typename SerializableT>
s11n::s11n_traits< SerializableT >::~s11n_traits  )  [inline]
 

Definition at line 413 of file traits.hpp.


Member Function Documentation

template<typename SerializableT>
static const std::string s11n::s11n_traits< SerializableT >::class_name const serializable_type instance_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 505 of file traits.hpp.


The documentation for this struct was generated from the following file:
Generated on Sat Dec 10 13:41:47 2005 for libs11n-1.2.1 by  doxygen 1.4.4