Adapt parser DataSource storage type to user type. More...
#include <rtt/DataSourceAdaptor.hpp>
Public Types | |
typedef boost::remove_const < typename boost::remove_reference< To > ::type >::type | value_t |
The bare type of T is extracted into value_t. | |
typedef To | result_t |
typedef boost::intrusive_ptr < DataSource< To > > | shared_ptr |
Use this type to store a pointer to a DataSourceBase. | |
typedef boost::intrusive_ptr < const DataSource< To > > | const_ptr |
Use this type to store a const pointer to a DataSourceBase. | |
Public Member Functions | |
DataSourceAdaptor (typename DataSource< From >::shared_ptr orig) | |
virtual DataSource< To >::result_t | get () const |
Return the data as type T. | |
virtual DataSource< To >::result_t | value () const |
Return the result of the last evaluate() function. | |
virtual void | reset () |
Reset the data to initial values. | |
virtual bool | evaluate () const |
Force an evaluation of the DataSourceBase. | |
virtual DataSource< To > * | clone () const |
Return a shallow clone of this DataSource. | |
virtual DataSource< To > * | copy (std::map< const DataSourceBase *, DataSourceBase * > &alreadyCloned) const |
Create a deep copy of this DataSource, unless it is already cloned. | |
virtual std::string | getType () const |
Return useful type info in a human readable format. | |
virtual const TypeInfo * | getTypeInfo () const |
Return the Orocos type info object. | |
virtual std::string | getTypeName () const |
Return the Orocos type name, without const, pointer or reference qualifiers. | |
void | ref () const |
Increase the reference count by one. | |
void | deref () const |
Decrease the reference count by one and delete this on zero. | |
virtual void | updated () |
In case the DataSource returns a 'reference' type, call this method to notify it that the data was updated in the course of an invocation of get(). | |
virtual bool | update (DataSourceBase *other) |
Update the value of this DataSource with the value of an other DataSource. | |
virtual CommandInterface * | updateCommand (DataSourceBase *other) |
Generate a CommandInterface object which will update this DataSource with the value of another DataSource when execute()'ed. | |
virtual bool | updatePart (DataSourceBase *part, DataSourceBase *other) |
Update part of the value of this DataSource with the value of an other DataSource. | |
virtual CommandInterface * | updatePartCommand (DataSourceBase *part, DataSourceBase *other) |
Generate a CommandInterface object which will partially update this DataSource with the value of another DataSource when execute()'ed. | |
std::ostream & | write (std::ostream &os) |
Stream the contents of this object. | |
std::string | toString () |
Get the contents of this object as a string. | |
bool | decomposeType (PropertyBag &targetbag) |
Decompose the contents of this object into properties. | |
bool | composeType (DataSourceBase::shared_ptr source) |
Compose the contents of this object from another datasource. | |
virtual void * | createBlob (int protocol) |
Creates a transportable data object with the current value of this DataSource. | |
virtual void * | getBlob (int protocol) |
Creates a transportable data object with the current value of this DataSource. | |
virtual bool | updateBlob (int protocol, const void *data) |
Updates the value of this DataSource with the value of a transportable data object. | |
virtual int | serverProtocol () const |
Inspect if this DataSource is a proxy for a remote server object. | |
virtual void * | server (int protocol, void *arg) |
Create an object server which 'mirrors' this DataSource. | |
virtual void * | method (int protocol, MethodC *orig, void *arg) |
Create an object server which 'mirrors' this DataSource. | |
Static Public Member Functions | |
static std::string | GetType () |
Return usefull type info in a human readable format. | |
static const TypeInfo * | GetTypeInfo () |
Return the Orocos type info. | |
static std::string | GetTypeName () |
Return the Orocos type name, without const, pointer or reference qualifiers. | |
static DataSource< To > * | narrow (DataSourceBase *db) |
This method narrows a DataSourceBase to a typeded DataSource, possibly returning a new object. | |
Public Attributes | |
DataSource< From >::shared_ptr | orig_ |
Protected Attributes | |
OS::AtomicInt | refcount |
We keep the refcount ourselves. |
Adapt parser DataSource storage type to user type.
Rationale : the Parser chooses internally how to pass values from DataSource to DataSource. The user however might choose to receive the result by value or by const reference. The parser thus needs to apply adaptors to convert from value to const reference and vice versa :
* (1) (2) (3) (4) * Parser: value constref constref value * \/ \/ (copy to stack) (copy to heap) *----------------------------------------------------------- * User : value constref value constref * * (note : 2bis, 3bis and 4bis are cases for 'ref' instead of 'const ref') *
If the internal format is constref and the user chooses value (3) ( very unwise! ) we can make a copy and pass that to the users method. If the internal format is value, and the user chooses constref (4) we can not pass it directly, but must copy it to a heap variable and pass a constref of the heaped variable to the user.
A user should always follow the parser's choice, since, not doing so will not save a copy. In the worst case, a memory allocation might follow in (3), when the parser chooses constref for containers, for example.
This implementation Adapts cases (1), (2) and (3). A specialisation in this same file implements (4) and (4bis).
Specialises for example DataSourceAdaptor<[const &] int, int> DataSourceAdaptor<[const &] int, const int>,
Definition at line 90 of file DataSourceAdaptor.hpp.
virtual DataSource<To>* RTT::detail::DataSourceAdaptor< From, To >::clone | ( | ) | const [inline, virtual] |
Return a shallow clone of this DataSource.
This method returns a duplicate of this instance which re-uses the DataSources this DataSource holds reference to. The clone() function is thus a non-deep copy.
Implements RTT::DataSource< To >.
Definition at line 106 of file DataSourceAdaptor.hpp.
References RTT::DataSource< T >::clone().
bool RTT::DataSourceBase::composeType | ( | DataSourceBase::shared_ptr | source | ) | [inherited] |
Compose the contents of this object from another datasource.
virtual DataSource<To>* RTT::detail::DataSourceAdaptor< From, To >::copy | ( | std::map< const DataSourceBase *, DataSourceBase * > & | alreadyCloned | ) | const [inline, virtual] |
Create a deep copy of this DataSource, unless it is already cloned.
Places the association (parent, clone) in alreadyCloned. If the DataSource is non-copyable (for example it represents the Property of a Task ), this may be returned.
Implements RTT::DataSource< To >.
Definition at line 110 of file DataSourceAdaptor.hpp.
References RTT::DataSource< T >::copy().
virtual void* RTT::DataSourceBase::createBlob | ( | int | protocol | ) | [virtual, inherited] |
Creates a transportable data object with the current value of this DataSource.
This does not trigger the evaluation() of this data source.
Reimplemented in RTT::Corba::ExpressionProxy.
Referenced by RTT::Corba::CorbaDataObjectProxy< T >::Set().
bool RTT::DataSourceBase::decomposeType | ( | PropertyBag & | targetbag | ) | [inherited] |
Decompose the contents of this object into properties.
virtual bool RTT::detail::DataSourceAdaptor< From, To >::evaluate | ( | ) | const [inline, virtual] |
Force an evaluation of the DataSourceBase.
Reimplemented from RTT::DataSource< To >.
Definition at line 104 of file DataSourceAdaptor.hpp.
References RTT::DataSource< T >::evaluate().
virtual void* RTT::DataSourceBase::getBlob | ( | int | protocol | ) | [virtual, inherited] |
Creates a transportable data object with the current value of this DataSource.
This does trigger the evaluation() of this data source. Equivalent to this->evaluate(); this->createBlob();
Reimplemented in RTT::Corba::ExpressionProxy.
virtual void* RTT::DataSourceBase::method | ( | int | protocol, | |
MethodC * | orig, | |||
void * | arg | |||
) | [virtual, inherited] |
Create an object server which 'mirrors' this DataSource.
Reimplemented in RTT::Corba::ExpressionProxy.
virtual void* RTT::DataSourceBase::server | ( | int | protocol, | |
void * | arg | |||
) | [virtual, inherited] |
Create an object server which 'mirrors' this DataSource.
Reimplemented in RTT::Corba::CORBAExpression< T >, RTT::Corba::CORBAExpression< void >, RTT::Corba::CORBAAssignableExpression< T >, RTT::Corba::ExpressionProxy, RTT::AssignableDataSource< T >, RTT::AssignableDataSource< arg3_type >, RTT::AssignableDataSource< DataSourceType >, RTT::AssignableDataSource< T1 >, RTT::AssignableDataSource< T2 >, RTT::AssignableDataSource< A1 >, RTT::AssignableDataSource< T3 >, RTT::AssignableDataSource< StateMachineWPtr >, RTT::AssignableDataSource< R >, RTT::AssignableDataSource< A2 >, RTT::AssignableDataSource< A >, RTT::AssignableDataSource< A3 >, RTT::AssignableDataSource< arg4_type >, RTT::AssignableDataSource< TFrom >, RTT::AssignableDataSource< From >, RTT::AssignableDataSource< ProgramInterfaceWPtr >, RTT::AssignableDataSource< arg2_type >, RTT::AssignableDataSource< arg1_type >, RTT::AssignableDataSource< ProgramInterface * >, RTT::AssignableDataSource< value_t >, RTT::AssignableDataSource< bool >, RTT::AssignableDataSource< To >, RTT::AssignableDataSource< boost::function_traits< DataType >::result_type >, and RTT::AssignableDataSource< TFrom & >.
virtual int RTT::DataSourceBase::serverProtocol | ( | ) | const [virtual, inherited] |
Inspect if this DataSource is a proxy for a remote server object.
Reimplemented in RTT::Corba::AnyDataSource, RTT::Corba::CORBAExpression< T >, RTT::Corba::CORBAExpression< void >, RTT::Corba::CORBAAssignableExpression< T >, and RTT::Corba::ExpressionProxy.
Referenced by RTT::AssignableDataSource< T >::narrow(), and RTT::DataSource< T >::narrow().
std::string RTT::DataSourceBase::toString | ( | ) | [inherited] |
Get the contents of this object as a string.
virtual bool RTT::DataSourceBase::update | ( | DataSourceBase * | other | ) | [virtual, inherited] |
Update the value of this DataSource with the value of an other DataSource.
Update does a full update of the value, adding extra information if necessary.
Reimplemented in RTT::AssignableDataSource< T >, RTT::AssignableDataSource< arg3_type >, RTT::AssignableDataSource< DataSourceType >, RTT::AssignableDataSource< T1 >, RTT::AssignableDataSource< T2 >, RTT::AssignableDataSource< A1 >, RTT::AssignableDataSource< T3 >, RTT::AssignableDataSource< StateMachineWPtr >, RTT::AssignableDataSource< R >, RTT::AssignableDataSource< A2 >, RTT::AssignableDataSource< A >, RTT::AssignableDataSource< A3 >, RTT::AssignableDataSource< arg4_type >, RTT::AssignableDataSource< TFrom >, RTT::AssignableDataSource< From >, RTT::AssignableDataSource< ProgramInterfaceWPtr >, RTT::AssignableDataSource< arg2_type >, RTT::AssignableDataSource< arg1_type >, RTT::AssignableDataSource< ProgramInterface * >, RTT::AssignableDataSource< value_t >, RTT::AssignableDataSource< bool >, RTT::AssignableDataSource< To >, RTT::AssignableDataSource< boost::function_traits< DataType >::result_type >, and RTT::AssignableDataSource< TFrom & >.
virtual bool RTT::DataSourceBase::updateBlob | ( | int | protocol, | |
const void * | data | |||
) | [virtual, inherited] |
Updates the value of this DataSource with the value of a transportable data object.
any | The value to update to. |
Reimplemented in RTT::AssignableDataSource< T >, RTT::AssignableDataSource< arg3_type >, RTT::AssignableDataSource< DataSourceType >, RTT::AssignableDataSource< T1 >, RTT::AssignableDataSource< T2 >, RTT::AssignableDataSource< A1 >, RTT::AssignableDataSource< T3 >, RTT::AssignableDataSource< StateMachineWPtr >, RTT::AssignableDataSource< R >, RTT::AssignableDataSource< A2 >, RTT::AssignableDataSource< A >, RTT::AssignableDataSource< A3 >, RTT::AssignableDataSource< arg4_type >, RTT::AssignableDataSource< TFrom >, RTT::AssignableDataSource< From >, RTT::AssignableDataSource< ProgramInterfaceWPtr >, RTT::AssignableDataSource< arg2_type >, RTT::AssignableDataSource< arg1_type >, RTT::AssignableDataSource< ProgramInterface * >, RTT::AssignableDataSource< value_t >, RTT::AssignableDataSource< bool >, RTT::AssignableDataSource< To >, RTT::AssignableDataSource< boost::function_traits< DataType >::result_type >, and RTT::AssignableDataSource< TFrom & >.
virtual CommandInterface* RTT::DataSourceBase::updateCommand | ( | DataSourceBase * | other | ) | [virtual, inherited] |
Generate a CommandInterface object which will update this DataSource with the value of another DataSource when execute()'ed.
Reimplemented in RTT::Corba::CORBAAssignableExpression< T >, RTT::AssignableDataSource< T >, RTT::IndexedValueDataSource< T, Index, SetType, IPred, APred >, RTT::AssignableDataSource< arg3_type >, RTT::AssignableDataSource< DataSourceType >, RTT::AssignableDataSource< T1 >, RTT::AssignableDataSource< T2 >, RTT::AssignableDataSource< A1 >, RTT::AssignableDataSource< T3 >, RTT::AssignableDataSource< StateMachineWPtr >, RTT::AssignableDataSource< R >, RTT::AssignableDataSource< A2 >, RTT::AssignableDataSource< A >, RTT::AssignableDataSource< A3 >, RTT::AssignableDataSource< arg4_type >, RTT::AssignableDataSource< TFrom >, RTT::AssignableDataSource< From >, RTT::AssignableDataSource< ProgramInterfaceWPtr >, RTT::AssignableDataSource< arg2_type >, RTT::AssignableDataSource< arg1_type >, RTT::AssignableDataSource< ProgramInterface * >, RTT::AssignableDataSource< value_t >, RTT::AssignableDataSource< bool >, RTT::AssignableDataSource< To >, RTT::AssignableDataSource< boost::function_traits< DataType >::result_type >, and RTT::AssignableDataSource< TFrom & >.
virtual bool RTT::DataSourceBase::updatePart | ( | DataSourceBase * | part, | |
DataSourceBase * | other | |||
) | [virtual, inherited] |
Update part of the value of this DataSource with the value of an other DataSource.
Update does a partial update of the value, according to part, which is most likely an index or hash value of some type.
Reimplemented in RTT::detail::AssignableDataSourceAdaptor< To const &, To >.
Referenced by RTT::detail::AssignableDataSourceAdaptor< To const &, To >::updatePart().
virtual CommandInterface* RTT::DataSourceBase::updatePartCommand | ( | DataSourceBase * | part, | |
DataSourceBase * | other | |||
) | [virtual, inherited] |
Generate a CommandInterface object which will partially update this DataSource with the value of another DataSource when execute()'ed.
part is an index or hash value of some type.
Reimplemented in RTT::Corba::CORBAAssignableExpression< T >, RTT::detail::AssignableDataSourceAdaptor< To const &, To >, and RTT::IndexedValueDataSource< T, Index, SetType, IPred, APred >.
Referenced by RTT::detail::AssignableDataSourceAdaptor< To const &, To >::updatePartCommand().
std::ostream& RTT::DataSourceBase::write | ( | std::ostream & | os | ) | [inherited] |
Stream the contents of this object.
OS::AtomicInt RTT::DataSourceBase::refcount [mutable, protected, inherited] |
We keep the refcount ourselves.
We aren't using boost::shared_ptr, because boost::intrusive_ptr is better, exactly because it can be used with refcounts that are stored in the class itself. Advantages are that the shared_ptr's for derived classes use the same refcount, which is of course very much desired, and that refcounting happens in an efficient way, which is also nice :)
Definition at line 89 of file DataSourceBase.hpp.