Orocos Real-Time Toolkit  2.9.0
TemplateValueFactory.hpp
Go to the documentation of this file.
1 #ifndef RTT_TEMPLATE_TYPE_FACTORY
2 #define RTT_TEMPLATE_TYPE_FACTORY
3 
4 #include "ValueFactory.hpp"
5 #include "../Property.hpp"
6 #include "../Attribute.hpp"
7 #include "../Logger.hpp"
8 #include "../rtt-config.h"
9 
10 namespace RTT
11 {
12  namespace types {
13 
14  template<class T>
16  : public ValueFactory
17  {
18  public:
19  typedef T DataType;
21  {
24  if ( res ) {
25  res->get();
26  //Logger::log() << Logger::Info << "Building "<<tname<<" Constant '"<<name<<"' with value "<< dsb->getTypeInfo()->toString(dsb) <<Logger::endl;
27  return new Constant<DataType>( name, res->rvalue() );
28  }
29  else
30  return 0;
31  }
32 
33  base::AttributeBase* buildVariable(std::string name) const
34  {
35  // A variable starts its life as unbounded.
36  //Logger::log() << Logger::Debug << "Building variable '"<<name <<"' of type " << tname <<Logger::endl;
38  }
39 
41  {
43  if ( !in )
45  else
47  if (!ds)
48  return 0;
49  // An attribute is always bounded.
50  //Logger::log() << Logger::Debug << "Building Attribute '"<< name <<"' of type " << tname <<Logger::endl;
51  return new Attribute<DataType>( name, ds.get() );
52  }
53 
55  {
57  if ( ! ds )
58  return 0;
59  return new Alias( name, ds );
60  }
61 
63  {
64  typename internal::AssignableDataSource<T>::shared_ptr ads = boost::dynamic_pointer_cast< internal::AssignableDataSource<T> >( in ); // no type conversion is done.
65  if ( ads )
66  return new internal::ActionAliasAssignableDataSource<T>(action, ads.get());
67 
68  typename internal::DataSource<T>::shared_ptr ds = boost::dynamic_pointer_cast< internal::DataSource<T> >( in ); // no type conversion is done.
69  if ( ! ds )
70  return 0;
71  return new internal::ActionAliasDataSource<T>(action, ds.get());
72  }
73 
74  virtual base::PropertyBase* buildProperty(const std::string& name, const std::string& desc, base::DataSourceBase::shared_ptr source = 0) const {
75  if (source) {
77  = boost::dynamic_pointer_cast< internal::AssignableDataSource<DataType> >( source );
78  if (ad)
79  return new Property<DataType>(name, desc, ad );
80  else {
81  //log(Error) <<"Failed to build 'Property<"<< this->tname <<"> "<<name<<"' from given DataSourceBase. Returning default."<<endlog();
82  }
83  }
84  return new Property<DataType>(name, desc, DataType());
85  }
86 
89  }
91  return new internal::ReferenceDataSource<DataType>(*static_cast<DataType*>(ptr));
92  }
93 
94  };
95 
96  }
97 }
98 
99 #endif
DataSource is a base class representing a generic way to read data of type T.
Definition: DataSource.hpp:94
base::AttributeBase * buildConstant(std::string name, base::DataSourceBase::shared_ptr dsb) const
Build a non modifyable instance of this type.
virtual result_t get() const =0
Return the data as type T.
base::DataSourceBase::shared_ptr convert(base::DataSourceBase::shared_ptr arg) const
Automatic conversion: convert a internal::DataSource to this type.
Definition: TypeInfo.cpp:118
virtual base::DataSourceBase::shared_ptr buildReference(void *ptr) const
Build a internal::ReferenceDataSource of this type, pointing to the given pointer.
virtual 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 class for all properties.
base::AttributeBase * buildVariable(std::string name) const
Build a non modifyable instance of this type.
Creates all value objects of a certain type.
A DataSource which is used to manipulate a reference to an external value.
base::DataSourceBase::shared_ptr buildActionAlias(base::ActionInterface *action, base::DataSourceBase::shared_ptr in) const
Returns a DataSource that first executes an action and returns the result of another data source...
An attribute is a minimalistic, named placeholder for data.
A DataSource which is used to execute an action and then return the value of another DataSource...
virtual base::DataSourceBase::shared_ptr buildValue() const
Build a internal::ValueDataSource of this type.
static const types::TypeInfo * getTypeInfo()
Return the typeinfo object.
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
Based on the software pattern &#39;command&#39;, this interface allows execution of action objects...
DataSource< T >::result_t get() const
Return the data as type T.
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 special DataSource only to be used for if you understand the copy()/clone() semantics very well...
static AssignableDataSource< T > * narrow(base::DataSourceBase *db)
This method narrows a base::DataSourceBase to a typeded AssignableDataSource, possibly returning a ne...
Definition: DataSource.inl:72
A DataSource which has set() methods.
Definition: DataSource.hpp:184
DataSource< T >::result_t get() const
Return the data as type T.
Definition: DataSources.hpp:78
base::AttributeBase * buildAttribute(std::string name, base::DataSourceBase::shared_ptr in) const
Build an Attribute of this type.
base::AttributeBase * buildAlias(std::string name, base::DataSourceBase::shared_ptr in) const
build an alias with b as the value.
boost::intrusive_ptr< DataSourceBase > shared_ptr
Use this type to store a pointer to a DataSourceBase.
An Attribute has a name and contains data which can be set and get.
Definition: Attribute.hpp:56
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52
As opposed to a Attribute, a Constant can not be assigned to a new value after creation.
Definition: Attribute.hpp:249
This class is the most basic Attribute implementation (only suitable for reading a internal::DataSour...
Definition: Attribute.hpp:375
A simple, yet very useful DataSource, which keeps a value, and returns it in its get() method...
Definition: DataSources.hpp:60
An AssignableDataSource which is used to execute an action and then return the value of another DataS...