This helper class allows user types to be added to Orocos. More...
#include <rtt/TemplateTypeInfo.hpp>
Public Types | |
typedef T | UserType |
The given T parameter is the type for reading DataSources. | |
typedef Property< T > ::DataSourceType | PropertyType |
When Properties of T are constructed, they are non-const, non-reference. | |
Public Member Functions | |
TemplateTypeInfo (std::string name) | |
Setup Type Information for type name. | |
AttributeBase * | buildConstant (std::string name, DataSourceBase::shared_ptr dsb) const |
Build a non modifyable instance of this type. | |
AttributeBase * | buildVariable (std::string name) const |
Build a non modifyable instance of this type. | |
AttributeBase * | buildAttribute (std::string name, DataSourceBase::shared_ptr in) const |
Build an Attribute of this type. | |
AttributeBase * | buildAlias (std::string name, DataSourceBase::shared_ptr in) const |
build an alias with b as the value. | |
virtual const std::string & | getTypeName () const |
Return unique the type name. | |
virtual PropertyBase * | buildProperty (const std::string &name, const std::string &desc, DataSourceBase::shared_ptr source=0) const |
Build a Property of this type. | |
virtual DataSourceBase::shared_ptr | buildValue () const |
Build a ValueDataSource of this type. | |
virtual std::ostream & | write (std::ostream &os, DataSourceBase::shared_ptr in) const |
Output this datasource as a human readable string. | |
virtual std::istream & | read (std::istream &os, DataSourceBase::shared_ptr out) const |
Read a new value for this datasource from a human readable string. | |
virtual bool | decomposeType (DataSourceBase::shared_ptr source, PropertyBag &targetbag) const |
Decompose a structure as basic components into a PropertyBag. | |
virtual bool | decomposeTypeImpl (typename AssignableDataSource< T >::const_reference_t source, PropertyBag &targetbag) const |
User, implement this function. | |
virtual bool | composeType (DataSourceBase::shared_ptr source, DataSourceBase::shared_ptr result) const |
Compose a structure from a PropertyBase containing its basic components. | |
virtual bool | composeTypeImpl (const PropertyBag &source, typename AssignableDataSource< T >::reference_t result) const |
User, implement this function. | |
std::string | getTypeIdName () const |
Type building/factory functions | |
virtual AttributeBase * | buildConstant (std::string name, DataSourceBase::shared_ptr, int sizehint) const |
Build a non modifyable instance of this type. | |
virtual AttributeBase * | buildVariable (std::string name, int sizehint) const |
Build a modifyable instance of this type. | |
virtual DataSourceBase::shared_ptr | construct (const std::vector< DataSourceBase::shared_ptr > &args) const |
Constructor syntax: construct a DataSource which returns an instance of data depending on the given arguments. | |
virtual DataSourceBase::shared_ptr | convert (DataSourceBase::shared_ptr arg) const |
Automatic conversion: convert a DataSource to this type. | |
virtual void | addConstructor (TypeBuilder *tb) |
Add a constructor/convertor object. | |
Conversion to/from text | |
virtual std::string | toString (DataSourceBase::shared_ptr in) const |
Usability function which converts data to a string. | |
virtual bool | fromString (const std::string &value, DataSourceBase::shared_ptr out) const |
Usability function which converts a string to data. | |
Distribution of objects | |
bool | addProtocol (int protocol_id, detail::TypeTransporter *tt) |
Register a protocol for data transport over a network. | |
detail::TypeTransporter * | getProtocol (int protocol_id) const |
Register a protocol for data transport over a network. | |
std::vector< int > | getTransportNames () const |
Return a list of protocols that have transporters. | |
Protected Types | |
typedef std::vector < TypeBuilder * > | Constructors |
typedef std::vector < detail::TypeTransporter * > | Transporters |
Protected Attributes | |
Constructors | constructors |
Transporters | transporters |
This helper class allows user types to be added to Orocos.
It provides 'default' implementations for each conversion type. For user defined types, this is very likely not satisfactory and the user needs to override the methods of this class in a subclass or provide specialised global functions.
T | The user class type. | |
ParamT | The type used to pass the value as a parameter. This defaults to T, but if T allocates upon copy (like std::string or std::vector), ParamT tells Orocos how to pass it, probably by const& or &. | |
use_ostream | When set to true, the class will use operator<<(std::ostream&, T) to write out the type to a stream. When set to false, the class will use this function and write '( type name )' to a stream instead. Defaults to false. Set to true if your class T has the above mentioned function. |
The decomposeTypeImpl function is a function which converts user data into property bags of native C++ primitive types. The primitive types are then typically used to write the data to screen or to disk. The inverse operation is done by composeTypeImpl, which reassembles a Property from its composite parts.
Every new user type used as a property will require these two functions if it must be 'written to a file'. The subclass must implement these functions by using composeTypeImpl() and decomposeTypeImpl(). such that class T is decomposed in primitive property types.
Example for type MyClass :
struct MyClass { bool var1; double var2; }; bool decomposeTypeImpl(const MyClass &c, PropertyBag& result) { // Decode c into primitive properties Var1 and Var2 which are in a PropertyBag of the // bag-type "MyClass" with the same name as the Property 'c'. result.setType("MyClass"); // Put var1 and var2 in the bag result.add( new Property<bool>("Var1","Description", c.var1 ); result.add( new Property<double("Var2","Description", c.var2 ); return true; // done ! } bool composeTypeImpl(const PropertyBag& bag, MyClass &result) { // Read the variables from the bag and write them to result. if ( bag.getType() != "MyClass") { std::cerr << "Wrong type encountered when composing "<< this->getTypeName()<<std::endl; return false; } if ( bag.find("Var1") == 0 || bag.find("Var2") == 0 ) { std::cerr << "Missing properties when composing "<< this->getTypeName()<<std::endl; return false; } // Read var1 and var2 from the bag result.var1 = bag.getProperty<bool>("Var1")->get(); result.var2 = bag.getProperty<bool>("Var2")->get(); return true; // done ! }
Definition at line 161 of file TemplateTypeInfo.hpp.
RTT::TemplateTypeInfo< T, use_ostream >::TemplateTypeInfo | ( | std::string | name | ) | [inline] |
Setup Type Information for type name.
This causes a switch from 'unknown' type to basic type information for type T.
name | the 'Orocos' type name. |
Definition at line 185 of file TemplateTypeInfo.hpp.
AttributeBase* RTT::TemplateTypeInfo< T, use_ostream >::buildAlias | ( | std::string | name, | |
DataSourceBase::shared_ptr | b | |||
) | const [inline, virtual] |
build an alias with b as the value.
If b is of the wrong type, 0 will be returned..
Implements RTT::TypeInfo.
Definition at line 232 of file TemplateTypeInfo.hpp.
virtual AttributeBase* RTT::TypeInfo::buildConstant | ( | std::string | name, | |
DataSourceBase::shared_ptr | , | |||
int | sizehint | |||
) | const [virtual, inherited] |
Build a non modifyable instance of this type.
sizehint | For variable size instances, use it to hint the size of the instance. |
AttributeBase* RTT::TemplateTypeInfo< T, use_ostream >::buildConstant | ( | std::string | name, | |
DataSourceBase::shared_ptr | ||||
) | const [inline, virtual] |
Build a non modifyable instance of this type.
sizehint | For variable size instances, use it to hint the size of the instance. |
Implements RTT::TypeInfo.
Definition at line 198 of file TemplateTypeInfo.hpp.
virtual AttributeBase* RTT::TypeInfo::buildVariable | ( | std::string | name, | |
int | sizehint | |||
) | const [virtual, inherited] |
Build a modifyable instance of this type.
sizehint | For variable size instances, use it to hint the size of the instance. |
Reimplemented in RTT::TemplateContainerTypeInfo< T, IndexType, SetType, IPred, APred, has_ostream >, and RTT::TemplateContainerTypeInfo< std::vector< T >, int, T, ArrayIndexChecker< std::vector< T > >, SizeAssignChecker< std::vector< T > >, has_ostream >.
AttributeBase* RTT::TemplateTypeInfo< T, use_ostream >::buildVariable | ( | std::string | name | ) | const [inline, virtual] |
Build a non modifyable instance of this type.
sizehint | For variable size instances, use it to hint the size of the instance. |
Implements RTT::TypeInfo.
Reimplemented in RTT::TemplateContainerTypeInfo< T, IndexType, SetType, IPred, APred, has_ostream >, RTT::TemplateIndexTypeInfo< T, IndexType, SetType, IPred, APred, has_ostream >, and RTT::TemplateContainerTypeInfo< std::vector< T >, int, T, ArrayIndexChecker< std::vector< T > >, SizeAssignChecker< std::vector< T > >, has_ostream >.
Definition at line 211 of file TemplateTypeInfo.hpp.
virtual bool RTT::TemplateTypeInfo< T, use_ostream >::composeType | ( | DataSourceBase::shared_ptr | source, | |
DataSourceBase::shared_ptr | target | |||
) | const [inline, virtual] |
Compose a structure from a PropertyBase containing its basic components.
The default behavior tries to assign source to target. If this does not work, because source and target have different type, this function returns false.
Implements RTT::TypeInfo.
Definition at line 296 of file TemplateTypeInfo.hpp.
virtual bool RTT::TemplateTypeInfo< T, use_ostream >::composeTypeImpl | ( | const PropertyBag & | source, | |
typename AssignableDataSource< T >::reference_t | result | |||
) | const [inline, virtual] |
User, implement this function.
Extract the structural elements in source to result.
Definition at line 322 of file TemplateTypeInfo.hpp.
Referenced by RTT::TemplateTypeInfo< std::vector< T >, has_ostream >::composeType().
virtual DataSourceBase::shared_ptr RTT::TypeInfo::construct | ( | const std::vector< DataSourceBase::shared_ptr > & | args | ) | const [virtual, inherited] |
Constructor syntax: construct a DataSource which returns an instance of data depending on the given arguments.
When args is empty, the default 'variable' is returned.
Reimplemented in RTT::EmptyTypeInfo.
virtual DataSourceBase::shared_ptr RTT::TypeInfo::convert | ( | DataSourceBase::shared_ptr | arg | ) | const [virtual, inherited] |
Automatic conversion: convert a DataSource to this type.
For example, for converting float -> double. If no valid conversion was found, returns arg again, otherwise, a new data source.
virtual bool RTT::TemplateTypeInfo< T, use_ostream >::decomposeType | ( | DataSourceBase::shared_ptr | source, | |
PropertyBag & | targetbag | |||
) | const [inline, virtual] |
Decompose a structure as basic components into a PropertyBag.
true | decomposition resulted in new types added to targetbag. | |
false | nothing was added to targetbag. |
Implements RTT::TypeInfo.
Definition at line 280 of file TemplateTypeInfo.hpp.
virtual bool RTT::TemplateTypeInfo< T, use_ostream >::decomposeTypeImpl | ( | typename AssignableDataSource< T >::const_reference_t | source, | |
PropertyBag & | targetbag | |||
) | const [inline, virtual] |
User, implement this function.
Add the structural elements of source to targetbag.
Definition at line 292 of file TemplateTypeInfo.hpp.
Referenced by RTT::TemplateTypeInfo< std::vector< T >, has_ostream >::decomposeType().
virtual std::istream& RTT::TemplateTypeInfo< T, use_ostream >::read | ( | std::istream & | os, | |
DataSourceBase::shared_ptr | out | |||
) | const [inline, virtual] |
Read a new value for this datasource from a human readable string.
The default does nothing.
Implements RTT::TypeInfo.
Definition at line 271 of file TemplateTypeInfo.hpp.
Referenced by RTT::TemplateTypeInfo< std::vector< T >, has_ostream >::read().
virtual std::ostream& RTT::TemplateTypeInfo< T, use_ostream >::write | ( | std::ostream & | os, | |
DataSourceBase::shared_ptr | in | |||
) | const [inline, virtual] |
Output this datasource as a human readable string.
The default just writes the type name in parentheses to os.
Implements RTT::TypeInfo.
Definition at line 257 of file TemplateTypeInfo.hpp.
Referenced by RTT::TemplateTypeInfo< std::vector< T >, has_ostream >::write().