TemplateTypeInfo Class Template Reference

#include <rtt/TemplateTypeInfo.hpp>

Inheritance diagram for TemplateTypeInfo:

TypeInfo TemplateContainerTypeInfo< std::vector< double >, int, double, RTT::ArrayIndexChecker< std::vector< double > >, RTT::SizeAssignChecker< std::vector< double > >, true >

List of all members.


Detailed Description

template<typename T, bool use_ostream = false>
class RTT::TemplateTypeInfo< T, use_ostream >

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.

Parameters:
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.
See also:
TypeInfoRepository.

composeType

decomposeType

operator<<

composeTypeImpl() and decomposeTypeImpl()

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.


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.
AttributeBasebuildConstant (std::string name, DataSourceBase::shared_ptr dsb) const
 Build a non modifyable instance of this type.
AttributeBasebuildVariable (std::string name) const
 Build a non modifyable instance of this type.
AttributeBasebuildAttribute (std::string name, DataSourceBase::shared_ptr in) const
 Build an Attribute of this type.
AttributeBasebuildAlias (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 PropertyBasebuildProperty (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.
Type building/factory functions
Used to create objects that hold data of a certain type.

virtual AttributeBasebuildConstant (std::string name, DataSourceBase::shared_ptr, int sizehint) const
 Build a non modifyable instance of this type.
virtual AttributeBasebuildVariable (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 void addConstructor (TypeBuilder *tb)
 Add a constructor.
Conversion to/from text
Used to convert data to human readable text and vice versa.

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
Used to transport data over a network.

bool addProtocol (int protocol_id, detail::TypeTransporter *tt)
 Register a protocol for data transport over a network.
detail::TypeTransportergetProtocol (int protocol_id) const
 Register a protocol for data transport over a network.

Protected Types

typedef std::vector
< TypeBuilder * > 
Constructors
typedef std::vector
< detail::TypeTransporter * > 
Transporters

Protected Attributes

Constructors constructors
Transporters transporters

Constructor & Destructor Documentation

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.

Parameters:
name the 'Orocos' type name.

Definition at line 185 of file TemplateTypeInfo.hpp.


Member Function Documentation

AttributeBase* buildConstant ( std::string  name,
DataSourceBase::shared_ptr   
) const [inline, virtual]

Build a non modifyable instance of this type.

Parameters:
sizehint For variable size instances, use it to hint the size of the instance.

Implements TypeInfo.

Definition at line 199 of file TemplateTypeInfo.hpp.

AttributeBase* buildVariable ( std::string  name  )  const [inline, virtual]

Build a non modifyable instance of this type.

Parameters:
sizehint For variable size instances, use it to hint the size of the instance.

Implements TypeInfo.

Reimplemented in TemplateContainerTypeInfo, TemplateIndexTypeInfo, and TemplateContainerTypeInfo< std::vector< double >, int, double, RTT::ArrayIndexChecker< std::vector< double > >, RTT::SizeAssignChecker< std::vector< double > >, true >.

Definition at line 211 of file TemplateTypeInfo.hpp.

AttributeBase* 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 TypeInfo.

Definition at line 232 of file TemplateTypeInfo.hpp.

virtual std::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 TypeInfo.

Reimplemented in BoolTypeInfo.

Definition at line 257 of file TemplateTypeInfo.hpp.

virtual std::istream& 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 TypeInfo.

Reimplemented in BoolTypeInfo.

Definition at line 271 of file TemplateTypeInfo.hpp.

virtual bool decomposeType ( DataSourceBase::shared_ptr  source,
PropertyBag targetbag 
) const [inline, virtual]

Decompose a structure as basic components into a PropertyBag.

Return values:
true decomposition resulted in new types added to targetbag.
false nothing was added to targetbag.

Implements TypeInfo.

Definition at line 280 of file TemplateTypeInfo.hpp.

virtual bool 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 TemplateTypeInfo< bool >::decomposeType().

virtual bool 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 TypeInfo.

Definition at line 296 of file TemplateTypeInfo.hpp.

virtual bool 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 TemplateTypeInfo< bool >::composeType().

AttributeBase * buildConstant ( std::string  name,
DataSourceBase::shared_ptr  dsb,
int  sizehint 
) const [virtual, inherited]

Build a non modifyable instance of this type.

Parameters:
sizehint For variable size instances, use it to hint the size of the instance.

Definition at line 87 of file Types.cpp.

Referenced by ControlTaskProxy::fetchObjects(), and ControlTaskProxy::synchronize().

AttributeBase * buildVariable ( std::string  name,
int  sizehint 
) const [virtual, inherited]

Build a modifyable instance of this type.

Parameters:
sizehint For variable size instances, use it to hint the size of the instance.

Reimplemented in TemplateContainerTypeInfo, and TemplateContainerTypeInfo< std::vector< double >, int, double, RTT::ArrayIndexChecker< std::vector< double > >, RTT::SizeAssignChecker< std::vector< double > >, true >.

Definition at line 83 of file Types.cpp.

Referenced by TypeInfo::construct().

DataSourceBase::shared_ptr 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 EmptyTypeInfo.

Definition at line 102 of file Types.cpp.

References TypeInfo::buildVariable(), TypeInfo::constructors, Logger::Debug, Logger::endl(), AttributeBase::getDataSource(), TypeInfo::getTypeName(), and Logger::log().


The documentation for this class was generated from the following file:
Generated on Tue Mar 25 17:41:58 2008 for OrocosReal-TimeToolkit by  doxygen 1.5.3