Orocos Real-Time Toolkit
2.6.0
|
A class for representing a user type, and which can build instances of that type. More...
#include <rtt/types/TypeInfo.hpp>
Public Types | |
typedef const std::type_info * | TypeId |
Public Member Functions | |
TypeInfo (const std::string &name) | |
const std::string & | getTypeName () const |
Return the type name which was first registered. | |
std::vector< std::string > | getTypeNames () const |
Returns all registered names and aliases of this type. | |
void | addAlias (const std::string &alias) |
Adds an alias to the this type. | |
bool | isType (const std::string &name) |
Returns true if this type is known by the type system under the given name. | |
TypeId | getTypeId () const |
Returns the compiler generated type id pointer. | |
const char * | getTypeIdName () const |
Returns the compiler generated type name (non portable accross compilers!). | |
base::DataSourceBase::shared_ptr | construct (const std::vector< base::DataSourceBase::shared_ptr > &args) const |
Constructor syntax: construct a internal::DataSource which returns an instance of data depending on the given arguments. | |
base::DataSourceBase::shared_ptr | convert (base::DataSourceBase::shared_ptr arg) const |
Automatic conversion: convert a internal::DataSource to this type. | |
void | addConstructor (TypeConstructor *tb) |
Add a constructor/convertor object. | |
base::InputPortInterface * | inputPort (std::string const &name) const |
Returns a new InputPort<T> object where T is the type represented by this TypeInfo object. | |
base::OutputPortInterface * | outputPort (std::string const &name) const |
Returns a new OutputPort<T> object where T is the type represented by this TypeInfo object. | |
base::ChannelElementBase::shared_ptr | buildDataStorage (ConnPolicy const &policy) const |
Creates single data or buffered storage for this type. | |
base::ChannelElementBase::shared_ptr | buildChannelOutput (base::InputPortInterface &port) const |
base::ChannelElementBase::shared_ptr | buildChannelInput (base::OutputPortInterface &port) const |
void | setTypeId (TypeId tid) |
void | setPortFactory (ConnFactoryPtr cf) |
Installs a new port factory such that in-process data can be communicated between components. | |
ConnFactoryPtr | getPortFactory () const |
void | setMemberFactory (MemberFactoryPtr mf) |
MemberFactoryPtr | getMemberFactory () const |
void | setValueFactory (ValueFactoryPtr dsf) |
ValueFactoryPtr | getValueFactory () const |
void | setCompositionFactory (CompositionFactoryPtr cf) |
CompositionFactoryPtr | getCompositionFactory () const |
void | setStreamFactory (StreamFactoryPtr sf) |
StreamFactoryPtr | getStreamFactory () const |
Distribution of objects | |
Used to transport data over a network. | |
bool | addProtocol (int protocol_id, TypeTransporter *tt) |
Register a protocol for data transport over a network. | |
TypeTransporter * | getProtocol (int protocol_id) const |
Returns this type's transport for a given protocol. | |
bool | hasProtocol (int protocol_id) const |
Check if this type is transporable over a given protocol. | |
std::vector< int > | getTransportNames () const |
Return a list of protocols that have transporters. | |
Type building/factory functions | |
Used to create objects that hold data of a certain type. | |
base::AttributeBase * | buildConstant (std::string name, base::DataSourceBase::shared_ptr source, int sizehint) const |
Build a non modifyable instance of this type. | |
base::AttributeBase * | buildConstant (std::string name, base::DataSourceBase::shared_ptr source) const |
Build a non modifyable instance of this type. | |
base::AttributeBase * | buildVariable (std::string name, int sizehint) const |
Build a modifyable instance of this type. | |
base::AttributeBase * | buildVariable (std::string name) const |
Build a non modifyable instance of this type. | |
bool | resize (base::DataSourceBase::shared_ptr arg, int size) const |
Tries to resize a data source in case it's a resizable sequence. | |
base::AttributeBase * | buildAlias (std::string name, base::DataSourceBase::shared_ptr b) const |
build an alias with b as the value. | |
base::PropertyBase * | buildProperty (const std::string &name, const std::string &desc, base::DataSourceBase::shared_ptr source=0) const |
Build a Property of this type. | |
base::AttributeBase * | buildAttribute (std::string name, base::DataSourceBase::shared_ptr source=0) const |
Build an Attribute of this type. | |
base::DataSourceBase::shared_ptr | buildValue () const |
Build a internal::ValueDataSource of this type. | |
base::DataSourceBase::shared_ptr | buildReference (void *ptr) const |
Build a internal::ReferenceDataSource of this type, pointing to the given pointer. | |
base::DataSourceBase::shared_ptr | buildActionAlias (base::ActionInterface *action, base::DataSourceBase::shared_ptr source) const |
Returns a DataSource that first executes an action and returns the result of another data source. | |
Conversion to/from text | |
Used to convert data to human readable text and vice versa. | |
std::ostream & | write (std::ostream &os, base::DataSourceBase::shared_ptr in) const |
Output this datasource as a human readable string. | |
std::istream & | read (std::istream &os, base::DataSourceBase::shared_ptr out) const |
Read a new value for this datasource from a human readable string. | |
std::string | toString (base::DataSourceBase::shared_ptr in) const |
Usability function which converts data to a string. | |
bool | fromString (const std::string &value, base::DataSourceBase::shared_ptr out) const |
Usability function which converts a string to data. | |
bool | isStreamable () const |
Returns true if this type is directly streamable using read()/write() or toString()/fromString(). | |
Inspecting data structures. | |
Used to write a complex type to an external representation, like XML. | |
std::vector< std::string > | getMemberNames () const |
Returns the list of struct member names of this type. | |
base::DataSourceBase::shared_ptr | getMember (base::DataSourceBase::shared_ptr item, const std::string &name) const |
Returns a member of a given data source struct identified by its name. | |
bool | getMember (internal::Reference *ref, base::DataSourceBase::shared_ptr item, const std::string &name) const |
Stores a reference to a member of a struct identified by its name. | |
base::DataSourceBase::shared_ptr | getMember (base::DataSourceBase::shared_ptr item, base::DataSourceBase::shared_ptr id) const |
Returns a reference to a member of a given data source struct identified by its name. | |
bool | composeType (base::DataSourceBase::shared_ptr source, base::DataSourceBase::shared_ptr target) const |
Compose a type (target) from a DataSourceBase (source) containing its members. | |
base::DataSourceBase::shared_ptr | decomposeType (base::DataSourceBase::shared_ptr source) const |
Specialize this function to return an alternate type which represents this one in a compatible way. | |
base::DataSourceBase::shared_ptr | convertType (base::DataSourceBase::shared_ptr source) const |
Specialize this function to return an alternate type which represents this one in a compatible way. | |
Protected Types | |
typedef std::vector < TypeConstructor * > | Constructors |
typedef std::vector < TypeTransporter * > | Transporters |
Protected Attributes | |
Constructors | constructors |
Transporters | transporters |
std::vector< std::string > | mtypenames |
const char * | mtid_name |
TypeId | mtid |
boost::shared_ptr< ConnFactory > | mconnf |
boost::shared_ptr< MemberFactory > | mmembf |
boost::shared_ptr< ValueFactory > | mdsf |
boost::shared_ptr < CompositionFactory > | mcompf |
boost::shared_ptr< StreamFactory > | mstrf |
A class for representing a user type, and which can build instances of that type.
Once you get hold of a TypeInfo object pointer, this pointer will be valid during the whole lifetime of the process.
Definition at line 68 of file TypeInfo.hpp.
void RTT::TypeInfo::addAlias | ( | const std::string & | alias | ) |
Adds an alias to the this type.
alias | an alternative name for this type which will be returned in getTypeNames() |
Definition at line 71 of file TypeInfo.cpp.
Referenced by RTT::types::TypeInfoRepository::addType().
base::DataSourceBase::shared_ptr RTT::types::TypeInfo::buildActionAlias | ( | base::ActionInterface * | action, |
base::DataSourceBase::shared_ptr | source | ||
) | const [inline] |
Returns a DataSource that first executes an action and returns the result of another data source.
If source is an AssignableDataSource, an AssignableDataSource is returned of the same type, otherwise, a plain DataSource is returned.
Definition at line 249 of file TypeInfo.hpp.
Referenced by RTT::corba::CorbaOperationCallerFactory::produce().
base::AttributeBase* RTT::types::TypeInfo::buildAlias | ( | std::string | name, |
base::DataSourceBase::shared_ptr | b | ||
) | const [inline] |
build an alias with b as the value.
If b is of the wrong type, 0 will be returned..
Definition at line 207 of file TypeInfo.hpp.
base::AttributeBase* RTT::types::TypeInfo::buildConstant | ( | std::string | name, |
base::DataSourceBase::shared_ptr | source, | ||
int | sizehint | ||
) | const [inline] |
Build a non modifyable instance of this type.
sizehint | For variable size instances, use it to hint the size of the instance. |
Definition at line 174 of file TypeInfo.hpp.
base::AttributeBase* RTT::types::TypeInfo::buildConstant | ( | std::string | name, |
base::DataSourceBase::shared_ptr | source | ||
) | const [inline] |
Build a non modifyable instance of this type.
sizehint | For variable size instances, use it to hint the size of the instance. |
Definition at line 179 of file TypeInfo.hpp.
base::ChannelElementBase::shared_ptr RTT::types::TypeInfo::buildDataStorage | ( | ConnPolicy const & | policy | ) | const [inline] |
Creates single data or buffered storage for this type.
policy | Describes the kind of storage requested by the user |
Definition at line 440 of file TypeInfo.hpp.
Referenced by RTT::corba::RemoteInputPort::buildRemoteChannelOutput().
base::AttributeBase * RTT::TypeInfo::buildVariable | ( | std::string | name, |
int | sizehint | ||
) | const |
Build a modifyable instance of this type.
sizehint | For variable size instances, use it to hint the size of the instance. |
Definition at line 81 of file TypeInfo.cpp.
base::AttributeBase* RTT::types::TypeInfo::buildVariable | ( | std::string | name | ) | const [inline] |
Build a non modifyable instance of this type.
sizehint | For variable size instances, use it to hint the size of the instance. |
Definition at line 189 of file TypeInfo.hpp.
bool RTT::types::TypeInfo::composeType | ( | base::DataSourceBase::shared_ptr | source, |
base::DataSourceBase::shared_ptr | target | ||
) | const [inline] |
Compose a type (target) from a DataSourceBase (source) containing its members.
The default behavior tries to assign source to target. If that fails, it tries to decompose target into its members and update the members of target with the contents of source.
The default implementation in TemplateTypeInfo works for most types, but can be overridden in case there are multiple versions/possibilities to make a target from a source. For example, in order to support legacy formats or in order to do the inverse of decomposeType().
source | A data source of the same type as target OR a PropertyBag that contains the parts of target to be refreshed. |
target | A data source of the same type as this TypeInfo object which contains the data to be updated from source. |
Definition at line 379 of file TypeInfo.hpp.
Referenced by RTT::types::composePropertyBag(), and RTT::updateProperties().
DataSourceBase::shared_ptr RTT::TypeInfo::construct | ( | const std::vector< base::DataSourceBase::shared_ptr > & | args | ) | const |
Constructor syntax: construct a internal::DataSource which returns an instance of data depending on the given arguments.
When args is empty, the default 'variable' is returned.
Definition at line 86 of file TypeInfo.cpp.
References RTT::base::AttributeBase::getDataSource().
Automatic conversion: convert a internal::DataSource to this type.
For example, for converting float -> double. If no valid conversion was found, returns arg again, otherwise, a new data source.
Definition at line 117 of file TypeInfo.cpp.
Referenced by RTT::internal::AssignableDataSource< T >::update(), and RTT::internal::AssignableDataSource< T >::updateAction().
base::DataSourceBase::shared_ptr RTT::types::TypeInfo::convertType | ( | base::DataSourceBase::shared_ptr | source | ) | const [inline] |
Specialize this function to return an alternate type which represents this one in a compatible way.
For example, a short converts to an long or an enum to an int or a string.
Definition at line 407 of file TypeInfo.hpp.
base::DataSourceBase::shared_ptr RTT::types::TypeInfo::decomposeType | ( | base::DataSourceBase::shared_ptr | source | ) | const [inline] |
Specialize this function to return an alternate type which represents this one in a compatible way.
For example, a short converts to an long or an enum to an int or a string. If your return a datasource containing a property bag, then this function should do the inverse of composeType: the returned property bag contains all parts of the current type (source) which can be modified and merged back into this type with composeType. Mathematically: composeType( decomposeType( A ), B); assert( A == B );
Definition at line 395 of file TypeInfo.hpp.
Referenced by RTT::base::PropertyBagVisitor::introspectAndDecompose().
base::DataSourceBase::shared_ptr RTT::types::TypeInfo::getMember | ( | base::DataSourceBase::shared_ptr | item, |
const std::string & | name | ||
) | const [inline] |
Returns a member of a given data source struct identified by its name.
item | The item of which to return a reference to a member |
name | The name of a member within item. Is a name of a member in case of a struct or an index number in case of a sequence. |
Definition at line 329 of file TypeInfo.hpp.
Referenced by RTT::base::DataSourceBase::getMember().
bool RTT::types::TypeInfo::getMember | ( | internal::Reference * | ref, |
base::DataSourceBase::shared_ptr | item, | ||
const std::string & | name | ||
) | const [inline] |
Stores a reference to a member of a struct identified by its name.
This method does not allocate memory when item is assignable..
ref | The reference object in which to store the reference. |
item | The item of which to return a reference to a member. It must be assignable, otherwise, a reference to a copy of item will be returned. This copy will allocate memory. |
name | The name of a member within item. |
Definition at line 343 of file TypeInfo.hpp.
base::DataSourceBase::shared_ptr RTT::types::TypeInfo::getMember | ( | base::DataSourceBase::shared_ptr | item, |
base::DataSourceBase::shared_ptr | id | ||
) | const [inline] |
Returns a reference to a member of a given data source struct identified by its name.
item | The item of which to return a reference to a member |
name | The name of a member within item. Is a name of a member in case of a struct or an index number in case of a sequence. |
Definition at line 355 of file TypeInfo.hpp.
std::vector<std::string> RTT::types::TypeInfo::getMemberNames | ( | ) | const [inline] |
Returns the list of struct member names of this type.
In case this type is not a struct, returns an empty list.
Definition at line 317 of file TypeInfo.hpp.
Referenced by RTT::base::DataSourceBase::getMemberNames().
TypeTransporter * RTT::TypeInfo::getProtocol | ( | int | protocol_id | ) | const |
Returns this type's transport for a given protocol.
Will print a warning when returning null. Use hasProtocol() to query without warning.
Definition at line 148 of file TypeInfo.cpp.
Referenced by RTT::corba::RemoteInputPort::buildRemoteChannelOutput(), RTT::internal::ConnFactory::createAndCheckStream(), RTT::corba::DataSourceProxy< T >::DataSourceProxy(), RTT::corba::CorbaOperationCallerFactory::produce(), RTT::corba::CorbaOperationCallerFactory::produceCollect(), and RTT::corba::CorbaOperationCallerFactory::produceSend().
const std::string& RTT::types::TypeInfo::getTypeName | ( | ) | const [inline] |
Return the type name which was first registered.
Do not rely on this function to return always the same string, as type loading order changes may return different names. Use getTypeNames() to get all aliases as well or getTypeIdName() to return the compiler generated C++ type name (non-portable accross compilers).
Definition at line 84 of file TypeInfo.hpp.
Referenced by RTT::types::TypeInfoRepository::addType(), RTT::corba::RemoteInputPort::buildRemoteChannelOutput(), RTT::internal::ConnFactory::createAndCheckStream(), RTT::corba::CorbaOperationCallerFactory::produce(), and RTT::corba::CorbaOperationCallerFactory::produceSend().
bool RTT::TypeInfo::isType | ( | const std::string & | name | ) |
Returns true if this type is known by the type system under the given name.
type_name | the name to query for |
Definition at line 77 of file TypeInfo.cpp.
std::istream& RTT::types::TypeInfo::read | ( | std::istream & | os, |
base::DataSourceBase::shared_ptr | out | ||
) | const [inline] |
Read a new value for this datasource from a human readable string.
The default does nothing.
Definition at line 275 of file TypeInfo.hpp.
bool RTT::types::TypeInfo::resize | ( | base::DataSourceBase::shared_ptr | arg, |
int | size | ||
) | const [inline] |
Tries to resize a data source in case it's a resizable sequence.
Definition at line 198 of file TypeInfo.hpp.
std::ostream& RTT::types::TypeInfo::write | ( | std::ostream & | os, |
base::DataSourceBase::shared_ptr | in | ||
) | const [inline] |
Output this datasource as a human readable string.
The default just writes the type name in parentheses to os.
Definition at line 266 of file TypeInfo.hpp.