Public Types | Public Member Functions | Private Types | Private Attributes

dynamicgraph::SignalCaster Class Reference

List of all members.

Public Types

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

Public Member Functions

 SignalCaster ()
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)
 Unregisters a cast.
bool existsCast (const std::type_info &type)
 Checks if there is a displayer registered with type_name.

Private Types

typedef boost::tuple
< displayer_type, caster_type,
tracer_type
cast_functions_type
 Container for the three cast functions.

Private Attributes

std::map< std::string,
cast_functions_type
functions_

Detailed Description

This 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

Container for the three cast functions.

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

dynamicgraph::SignalCaster::SignalCaster (  ) 
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.

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

Displays an object using a registered displayer function.

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

Checks if there is a displayer registered with type_name.

void dynamicgraph::SignalCaster::registerCast ( const std::type_info &  type,
displayer_type  displayer,
caster_type  caster,
tracer_type  tracer 
)

Registers a cast.

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

Traces an object using a registered trace function.

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

Unregisters a cast.


Member Data Documentation

This map associates the typename of objects and the corresponding using boost::function with 'compatible' syntax





dynamicGraph library documentation