PrimitiveTypeInfo.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Fri Jun 10 15:16:01 2011 +0200 PrimitiveTypeInfo.hpp
3 
4  PrimitiveTypeInfo.hpp - description
5  -------------------
6  begin : Fri Jun 10 2011
7  copyright : (C) 2011 Peter Soetens
8  email : peter@thesourceworks.com
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 #ifndef ORO_PRIMITIVE_TYPEINFO_HPP
40 #define ORO_PRIMITIVE_TYPEINFO_HPP
41 
42 #include "Types.hpp"
43 #include "../Property.hpp"
44 #include "../Attribute.hpp"
45 #include "../Logger.hpp"
46 #include "TypeStreamSelector.hpp"
47 #include "TypeInfoGenerator.hpp"
48 #include "StreamFactory.hpp"
49 #include "TemplateValueFactory.hpp"
50 #include "../rtt-config.h"
51 
52 namespace RTT
53 {
54  namespace types {
55 
69  template<typename T, bool use_ostream = false>
71  public TypeInfoGenerator,
72  public TemplateValueFactory<T>,
73  public StreamFactory
74  {
75  protected:
76  const std::string tname;
77  boost::shared_ptr<PrimitiveTypeInfo<T, use_ostream> > mshared;
78  public:
82  typedef T DataType;
83 
91  PrimitiveTypeInfo(std::string name)
92  : tname(name)
93  {
94  }
95 
97  {
98  }
99 
100  boost::shared_ptr<PrimitiveTypeInfo<T, use_ostream> > getSharedPtr() {
101  if (!mshared)
102  mshared.reset(this);
103  return mshared;
104  }
105 
107  // Install the factories for primitive types
108  ti->setValueFactory( this->getSharedPtr() );
109  if (use_ostream)
110  ti->setStreamFactory( this->getSharedPtr() );
111 
112  // Install the type info object for T
114  ti->setTypeId( &typeid(T) );
115 
116  // Clean up reference to ourselves.
117  mshared.reset();
118  // Don't delete us, we're memory-managed.
119  return false;
120  }
121 
123  return TypeInfoRepository::Instance()->getTypeInfo<T>();
124  }
125 
126  virtual const std::string& getTypeName() const { return tname; }
127 
128  virtual std::ostream& write( std::ostream& os, base::DataSourceBase::shared_ptr in ) const {
129  typename internal::DataSource<T>::shared_ptr d = boost::dynamic_pointer_cast< internal::DataSource<T> >( in );
130  if ( d ) {
132  }
133  return os;
134  }
135 
136  virtual std::istream& read( std::istream& os, base::DataSourceBase::shared_ptr out ) const {
137  typename internal::AssignableDataSource<T>::shared_ptr d = boost::dynamic_pointer_cast< internal::AssignableDataSource<T> >( out );
138  if ( d ) {
140  d->updated(); // because use of set().
141  }
142  return os;
143  }
144 
145  virtual bool isStreamable() const {
146  return use_ostream;
147  }
148 
150  return false;
151  }
152 
157  {
158  return source;
159  }
160 
161  virtual bool decomposeType( base::DataSourceBase::shared_ptr source, PropertyBag& targetbag ) const {
162  return false;
163  }
164  };
165 }}
166 
167 #endif
void setStreamFactory(StreamFactoryPtr sf)
Definition: TypeInfo.hpp:473
void setValueFactory(ValueFactoryPtr dsf)
Definition: TypeInfo.hpp:465
virtual void set(param_t t)=0
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
bool installTypeInfoObject(TypeInfo *ti)
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
virtual const_reference_t rvalue() const =0
virtual const std::string & getTypeName() const
boost::shared_ptr< PrimitiveTypeInfo< T, use_ostream > > mshared
virtual base::DataSourceBase::shared_ptr decomposeType(base::DataSourceBase::shared_ptr source) const
virtual bool isStreamable() const
boost::intrusive_ptr< DataSource< T > > shared_ptr
Definition: DataSource.hpp:115
boost::intrusive_ptr< AssignableDataSource< T > > shared_ptr
Definition: DataSource.hpp:198
virtual std::istream & read(std::istream &os, base::DataSourceBase::shared_ptr out) const
TypeInfo * getTypeInfoObject() const
boost::intrusive_ptr< DataSourceBase > shared_ptr
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
boost::shared_ptr< PrimitiveTypeInfo< T, use_ostream > > getSharedPtr()


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:26