Orocos Real-Time Toolkit  2.9.0
PrimitiveTypeInfo.hpp
Go to the documentation of this file.
1 #ifndef ORO_PRIMITIVE_TYPEINFO_HPP
2 #define ORO_PRIMITIVE_TYPEINFO_HPP
3 
4 #include "Types.hpp"
5 #include "../Property.hpp"
6 #include "../Attribute.hpp"
7 #include "../Logger.hpp"
8 #include "TypeStreamSelector.hpp"
9 #include "TypeInfoGenerator.hpp"
10 #include "StreamFactory.hpp"
11 #include "TemplateValueFactory.hpp"
12 #include "../rtt-config.h"
13 
14 namespace RTT
15 {
16  namespace types {
17 
31  template<typename T, bool use_ostream = false>
33  public TypeInfoGenerator,
34  public TemplateValueFactory<T>,
35  public StreamFactory
36  {
37  protected:
38  const std::string tname;
39  boost::shared_ptr<PrimitiveTypeInfo<T, use_ostream> > mshared;
40  public:
44  typedef T DataType;
45 
53  PrimitiveTypeInfo(std::string name)
54  : tname(name)
55  {
56  }
57 
59  {
60  }
61 
62  boost::shared_ptr<PrimitiveTypeInfo<T, use_ostream> > getSharedPtr() {
63  if (!mshared)
64  mshared.reset(this);
65  return mshared;
66  }
67 
69  // Install the factories for primitive types
70  ti->setValueFactory( this->getSharedPtr() );
71  if (use_ostream)
72  ti->setStreamFactory( this->getSharedPtr() );
73 
74  // Install the type info object for T
76  ti->setTypeId( &typeid(T) );
77 
78  // Clean up reference to ourselves.
79  mshared.reset();
80  // Don't delete us, we're memory-managed.
81  return false;
82  }
83 
85  return TypeInfoRepository::Instance()->getTypeInfo<T>();
86  }
87 
88  virtual const std::string& getTypeName() const { return tname; }
89 
90  virtual std::ostream& write( std::ostream& os, base::DataSourceBase::shared_ptr in ) const {
91  typename internal::DataSource<T>::shared_ptr d = boost::dynamic_pointer_cast< internal::DataSource<T> >( in );
92  if ( d ) {
94  }
95  return os;
96  }
97 
98  virtual std::istream& read( std::istream& os, base::DataSourceBase::shared_ptr out ) const {
99  typename internal::AssignableDataSource<T>::shared_ptr d = boost::dynamic_pointer_cast< internal::AssignableDataSource<T> >( out );
100  if ( d ) {
102  d->updated(); // because use of set().
103  }
104  return os;
105  }
106 
107  virtual bool isStreamable() const {
108  return use_ostream;
109  }
110 
112  return false;
113  }
114 
119  {
120  return source;
121  }
122 
123  virtual bool decomposeType( base::DataSourceBase::shared_ptr source, PropertyBag& targetbag ) const {
124  return false;
125  }
126  };
127 }}
128 
129 #endif
DataSource is a base class representing a generic way to read data of type T.
Definition: DataSource.hpp:94
void setStreamFactory(StreamFactoryPtr sf)
Definition: TypeInfo.hpp:473
void setValueFactory(ValueFactoryPtr dsf)
Definition: TypeInfo.hpp:465
virtual void set(param_t t)=0
Set this DataSource with a value.
PrimitiveTypeInfo(std::string name)
Setup Type Information for type name.
virtual bool composeType(base::DataSourceBase::shared_ptr source, base::DataSourceBase::shared_ptr result) const
A container for holding references to properties.
Definition: PropertyBag.hpp:96
All generator classes inherit from this object in order to allow them to be added to the TypeInfoRepo...
bool installTypeInfoObject(TypeInfo *ti)
Installs the type info object in the global data source type info handler and adds any additional fea...
void setTypeId(TypeId tid)
Definition: TypeInfo.hpp:448
virtual bool decomposeType(base::DataSourceBase::shared_ptr source, PropertyBag &targetbag) const
virtual std::ostream & write(std::ostream &os, base::DataSourceBase::shared_ptr in) const
Output this datasource as a human readable string.
virtual const_reference_t rvalue() const =0
Get a const reference to the value of this DataSource.
virtual const std::string & getTypeName() const
Return the type name for which this generator generates type info features.
boost::shared_ptr< PrimitiveTypeInfo< T, use_ostream > > mshared
A class for representing a user type, and which can build instances of that type. ...
Definition: TypeInfo.hpp:67
virtual base::DataSourceBase::shared_ptr decomposeType(base::DataSourceBase::shared_ptr source) const
A primitive type is decomposed into itself.
virtual bool isStreamable() const
Returns true if this type is directly streamable using read()/write() or toString()/fromString().
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
Every DataSource of type T has a type info class which it can ask type information.
virtual std::istream & read(std::istream &os, base::DataSourceBase::shared_ptr out) const
Read a new value for this datasource from a human readable string.
A DataSource which has set() methods.
Definition: DataSource.hpp:184
T DataType
The given T parameter is the type of the DataSources.
TypeInfo * getTypeInfoObject() const
Returns the TypeInfo object of this type, or null if none exists yet.
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
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
This template class allows primitive types, which are not sent over ports, to be added to Orocos...
boost::shared_ptr< PrimitiveTypeInfo< T, use_ostream > > getSharedPtr()