dynamicgraph::SignalCaster Class Reference

This singleton class allows serialization of a number of objects into (disp) and from (cast) std i/o streams. More...

#include <dynamic-graph/signal-caster.h>

List of all members.

Public Types

typedef boost::function2< void,
const boost::any
&, std::ostream & > 
displayer_type
 Typedef of displayer functions that take an encapsulated 'any' object and displays, cast, or trace it on an output stream (serialization).
typedef boost::function1
< boost::any,
std::istringstream & > 
caster_type
typedef boost::function2< void,
const boost::any
&, std::ostream & > 
tracer_type

Public Member Functions

virtual ~SignalCaster ()
void disp (const boost::any &object, std::ostream &os)
 Displays an object using a registered displayer function.
void trace (const boost::any &object, std::ostream &os)
 Traces an object using a registered trace function.
boost::any cast (const std::type_info &, std::istringstream &iss)
 Casts an object using a registered cast function.
void registerCast (const std::type_info &type, displayer_type displayer, caster_type caster, tracer_type tracer)
 Registers a cast.
void unregisterCast (const std::type_info &type)
 Unregister a cast.
bool existsCast (const std::type_info &type) const
 Checks if there is a displayer registered with type_name.
std::vector< std::string > listTypenames () const
 Return the list of type names registered.

Static Public Member Functions

static void destroy ()
 Destroy the unique instance.
static SignalCastergetInstance (void)
 Get a reference to the unique object of the class.

Detailed Description

This singleton class allows serialization of a number of objects into (disp) and from (cast) std i/o streams.

The transformation is done at run-time, i.e. SignalCaster doesn't know about the type of objects it casts to.

It also allows registering of user-defined casts. A cast is identified by the compiler. The mapping from a type to a serialization function is dynamic, hence it is more complex than a typical template-based compile-time resolve. So disp, cast and trace are costly functions and should be used as such.


Member Typedef Documentation

typedef boost::function1<boost::any, std::istringstream&> dynamicgraph::SignalCaster::caster_type
typedef boost::function2<void, const boost::any&, std::ostream&> dynamicgraph::SignalCaster::displayer_type

Typedef of displayer functions that take an encapsulated 'any' object and displays, cast, or trace it on an output stream (serialization).

typedef boost::function2<void, const boost::any&, std::ostream&> dynamicgraph::SignalCaster::tracer_type

Constructor & Destructor Documentation

virtual dynamicgraph::SignalCaster::~SignalCaster ( ) [virtual]

Member Function Documentation

boost::any dynamicgraph::SignalCaster::cast ( const std::type_info &  ,
std::istringstream &  iss 
)

Casts an object using a registered cast function.

Referenced by dynamicgraph::signal_cast().

static void dynamicgraph::SignalCaster::destroy ( ) [static]

Destroy the unique instance.

void dynamicgraph::SignalCaster::disp ( const boost::any &  object,
std::ostream &  os 
)

Displays an object using a registered displayer function.

Referenced by dynamicgraph::signal_disp().

bool dynamicgraph::SignalCaster::existsCast ( const std::type_info &  type) const

Checks if there is a displayer registered with type_name.

static SignalCaster* dynamicgraph::SignalCaster::getInstance ( void  ) [static]
std::vector<std::string> dynamicgraph::SignalCaster::listTypenames ( ) const

Return the list of type names registered.

void dynamicgraph::SignalCaster::registerCast ( const std::type_info &  type,
displayer_type  displayer,
caster_type  caster,
tracer_type  tracer 
)
void dynamicgraph::SignalCaster::trace ( const boost::any &  object,
std::ostream &  os 
)

Traces an object using a registered trace function.

Referenced by dynamicgraph::signal_trace().

void dynamicgraph::SignalCaster::unregisterCast ( const std::type_info &  type)

Unregister a cast.