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>
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). More... | |
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. More... | |
void | trace (const boost::any &object, std::ostream &os) |
Traces an object using a registered trace function. More... | |
boost::any | cast (const std::type_info &, std::istringstream &iss) |
Casts an object using a registered cast function. More... | |
void | registerCast (const std::type_info &type, displayer_type displayer, caster_type caster, tracer_type tracer) |
Registers a cast. More... | |
void | unregisterCast (const std::type_info &type) |
Unregister a cast. More... | |
bool | existsCast (const std::type_info &type) const |
Checks if there is a displayer registered with type_name. More... | |
std::vector< std::string > | listTypenames () const |
Return the list of type names registered. More... | |
Static Public Member Functions | |
static void | destroy () |
Destroy the unique instance. More... | |
static SignalCaster * | getInstance (void) |
Get a reference to the unique object of the class. More... | |
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.
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 |
|
virtual |
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 |
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 |
Get a reference to the unique object of the class.
Referenced by dynamicgraph::signal_cast(), dynamicgraph::signal_disp(), dynamicgraph::signal_trace(), and dynamicgraph::SignalCastRegisterer::SignalCastRegisterer().
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 | ||
) |
Registers a cast.
Referenced by dynamicgraph::SignalCastRegisterer::SignalCastRegisterer().
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.