Orocos Real-Time Toolkit  2.9.0
Go to the documentation of this file.
4 #include "CompositionFactory.hpp"
5 #include "../Property.hpp"
6 #include "../PropertyBag.hpp"
8 namespace RTT {
9  namespace types {
10  template<typename T>
12  : public CompositionFactory
13  {
14  public:
19  typedef T UserType;
22  const internal::DataSource<PropertyBag>* pb = dynamic_cast< const internal::DataSource<PropertyBag>* > (source.get() );
23  if ( !pb )
24  return false;
25  typename internal::AssignableDataSource<UserType>::shared_ptr ads = boost::dynamic_pointer_cast< internal::AssignableDataSource<UserType> >( result );
26  if ( !ads )
27  return false;
29  // last fall-back: use user supplied function:
30  if ( composeTypeImpl( pb->rvalue(), ads->set() ) )
31  ads->updated();
32  else {
33  Logger::log() <<Logger::Debug<<"Failed to compose from "<< source->getTypeName() <<Logger::endl;
34  return false;
35  }
36  Logger::log() <<Logger::Debug<<"Successfuly composed type from "<< source->getTypeName() <<Logger::endl;
37  return true;
38  }
47  {
48  // Extract typed values
49  typename internal::DataSource<UserType>::shared_ptr ds = boost::dynamic_pointer_cast< internal::DataSource<UserType> >( source );
50  if ( !ds )
51  return base::DataSourceBase::shared_ptr(); // happens in the case of 'unknown type'
52  Property<PropertyBag> targetbag_p("targetbag");
53  if (decomposeTypeImpl( ds->rvalue(), targetbag_p.value() ))
54  return targetbag_p.getDataSource();
56  }
61  virtual bool composeTypeImpl(const PropertyBag& source, typename internal::AssignableDataSource<T>::reference_t result) const {
62  return false;
63  }
69  virtual bool decomposeTypeImpl( typename internal::AssignableDataSource<T>::const_reference_t source, PropertyBag& targetbag ) const {
70  return false;
71  }
73  };
74  }
75 }
77 #endif
virtual base::DataSourceBase::shared_ptr getDataSource() const
Get an assignable base::DataSource through which this PropertyBase can be manipulated.
Definition: Property.hpp:393
DataSource is a base class representing a generic way to read data of type T.
Definition: DataSource.hpp:94
virtual bool composeTypeImpl(const PropertyBag &source, typename internal::AssignableDataSource< T >::reference_t result) const
User, implement this function in case you want to control reading the XML data format.
virtual bool decomposeTypeImpl(typename internal::AssignableDataSource< T >::const_reference_t source, PropertyBag &targetbag) const
User, implement this function in case you want to control writing the XML data format.
virtual bool composeType(base::DataSourceBase::shared_ptr source, base::DataSourceBase::shared_ptr result) const
Compose a type (target) from a DataSourceBase (source) containing its members.
boost::call_traits< value_t >::reference reference_t
Definition: DataSource.hpp:193
virtual void set(param_t t)=0
Set this DataSource with a value.
A container for holding references to properties.
Definition: PropertyBag.hpp:96
A factory for composing/decomposing and converting types to a form suitable for persistent storage...
reference_t value()
Access to the value of the Property.
Definition: Property.hpp:277
virtual base::DataSourceBase::shared_ptr decomposeType(base::DataSourceBase::shared_ptr source) const
This default implementation sets up a PropertyBag which is passed to decomposeTypeImpl().
virtual const_reference_t rvalue() const =0
Get a const reference to the value of this DataSource.
A property represents a named value of any type with a description.
Definition: Property.hpp:76
static std::ostream & endl(std::ostream &__os)
Definition: Logger.cpp:383
boost::intrusive_ptr< DataSource< T > > shared_ptr
Definition: DataSource.hpp:115
boost::intrusive_ptr< AssignableDataSource< T > > shared_ptr
Use this type to store a pointer to an AssignableDataSource.
Definition: DataSource.hpp:198
A DataSource which has set() methods.
Definition: DataSource.hpp:184
static Logger & log()
As Instance(), but more userfriendly.
Definition: Logger.cpp:117
DataSource< T >::const_reference_t const_reference_t
Definition: DataSource.hpp:191
boost::intrusive_ptr< DataSourceBase > shared_ptr
Use this type to store a pointer to a DataSourceBase.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52
T UserType
The given T parameter is the type for reading DataSources.
virtual void updated()
In case the internal::DataSource returns a &#39;reference&#39; type, call this method to notify it that the d...
Definition: DataSource.cpp:112