TypeInfo.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jan 19 14:11:26 CET 2004 TypeInfo.hpp
3 
4  TypeInfo.hpp - description
5  -------------------
6  begin : Mon January 19 2004
7  copyright : (C) 2004 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
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  * Lesser 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 #ifndef ORO_CORELIB_TYPEINFO_HPP
39 #define ORO_CORELIB_TYPEINFO_HPP
40 
41 #include <vector>
42 #include <string>
43 #include "../base/DataSourceBase.hpp"
44 #include "../base/ChannelElementBase.hpp"
45 #include "../internal/SharedConnection.hpp"
46 
47 #ifndef NO_TYPE_INFO_FACTORY_FUNCTIONS
48 #include "MemberFactory.hpp"
49 #include "ValueFactory.hpp"
50 #include "CompositionFactory.hpp"
51 #ifndef NO_TYPE_INFO_STREAMS
52 #include "StreamFactory.hpp"
53 #endif
54 #endif
55 
56 
57 namespace RTT
58 { namespace types {
59  typedef boost::shared_ptr<internal::ConnFactory> ConnFactoryPtr;
60 
67  class RTT_API TypeInfo
68  {
69  public:
70  typedef const std::type_info * TypeId;
71 
72  TypeInfo(const std::string& name) : mtypenames(1,name) {}
73 
74  ~TypeInfo();
83  const std::string& getTypeName() const { return mtypenames[0]; }
84 
88  std::vector<std::string> getTypeNames() const;
89 
95  void addAlias(const std::string& alias);
96 
103  bool isType(const std::string& name);
104 
108  TypeId getTypeId() const { return mtid; }
109 
113  const char * getTypeIdName() const { return mtid_name; }
114 
120  base::DataSourceBase::shared_ptr construct(const std::vector<base::DataSourceBase::shared_ptr>& args) const;
121 
128 
132  void addConstructor(TypeConstructor* tb);
133 
143  bool addProtocol(int protocol_id, TypeTransporter* tt);
144 
150  TypeTransporter* getProtocol(int protocol_id) const;
151 
155  bool hasProtocol(int protocol_id) const;
156 
160  std::vector<int> getTransportNames() const;
161 
162 #ifndef NO_TYPE_INFO_FACTORY_FUNCTIONS
163 
173  base::AttributeBase* buildConstant(std::string name,base::DataSourceBase::shared_ptr source, int sizehint) const
174  {
175  return mdsf ? mdsf->buildConstant(name, source, sizehint) : 0;
176  }
177 
179  {
180  return mdsf ? mdsf->buildConstant(name, source) : 0;
181  }
187  base::AttributeBase* buildVariable(std::string name,int sizehint) const;
188  base::AttributeBase* buildVariable(std::string name) const
189  {
190  return mdsf ? mdsf->buildVariable(name) : 0;
191  }
192 
197  bool resize(base::DataSourceBase::shared_ptr arg, int size) const
198  {
199  return mmembf ? mmembf->resize(arg, size) : false;
200  }
201 
207  {
208  return mdsf ? mdsf->buildAlias(name, b) : 0;
209  }
210 
214  base::PropertyBase* buildProperty(const std::string& name, const std::string& desc, base::DataSourceBase::shared_ptr source = 0) const
215  {
216  return mdsf ? mdsf->buildProperty(name, desc, source) : 0;
217  }
218 
223  {
224  return mdsf ? mdsf->buildAttribute(name, source) : 0;
225  }
226 
231  {
232  return mdsf ? mdsf->buildValue() : base::DataSourceBase::shared_ptr();
233  }
234 
239  {
240  return mdsf ? mdsf->buildReference(ptr) : base::DataSourceBase::shared_ptr();
241  }
242 
249  {
250  return mdsf ? mdsf->buildActionAlias(action,source) : base::DataSourceBase::shared_ptr();
251  }
252 
255 #ifndef NO_TYPE_INFO_STREAMS
256 
265  std::ostream& write(std::ostream& os, base::DataSourceBase::shared_ptr in ) const
266  {
267  if ( mstrf ) {
268  return mstrf->write(os,in);
269  } else {
270 #ifdef OS_HAVE_STREAMS
271  std::string output = std::string("(")+ in->getTypeName() +")";
272  os << output;
273 #endif
274  return os;
275  }
276  }
277 
282  std::istream& read(std::istream& os, base::DataSourceBase::shared_ptr out ) const
283  {
284  return mstrf ? mstrf->read(os, out) : os;
285  }
286 
287 
292  {
293  return mstrf ? mstrf->toString(in) : std::string();
294  }
295 
299  bool fromString( const std::string& value, base::DataSourceBase::shared_ptr out ) const
300  {
301  return mstrf ? mstrf->fromString(value, out) : false;
302  }
303 
308  bool isStreamable() const
309  {
310  return mstrf ? mstrf->isStreamable() : false;
311  }
313 #endif
314 
324  std::vector<std::string> getMemberNames() const
325  {
326  return mmembf ? mmembf->getMemberNames() : std::vector<std::string>();
327  }
328 
337  {
338  return mmembf ? mmembf->getMember(item,name) : base::DataSourceBase::shared_ptr();
339  }
340 
350  bool getMember(internal::Reference* ref, base::DataSourceBase::shared_ptr item, const std::string& name) const
351  {
352  return mmembf ? mmembf->getMember(ref, item,name) : false;
353  }
354 
364  {
365  return mmembf ? mmembf->getMember(item,id) : base::DataSourceBase::shared_ptr();
366  }
367 
387  {
388  return mcompf ? mcompf->composeType(source,target) : false;
389  }
390 
403  {
404  return mcompf ? mcompf->decomposeType(source) : base::DataSourceBase::shared_ptr();
405  }
406 
415  {
416  return mcompf ? mcompf->convertType(source) : base::DataSourceBase::shared_ptr();
417  }
418 
427  base::InputPortInterface* inputPort(std::string const& name) const;
428 
433  base::OutputPortInterface* outputPort(std::string const& name) const;
434 
441  base::ChannelElementBase::shared_ptr buildDataStorage(ConnPolicy const& policy) const;
442  base::ChannelElementBase::shared_ptr buildChannelOutput(base::InputPortInterface& port, ConnPolicy const& policy) const;
443  base::ChannelElementBase::shared_ptr buildChannelInput(base::OutputPortInterface& port, ConnPolicy const& policy) const;
444  internal::SharedConnectionBase::shared_ptr buildSharedConnection(base::OutputPortInterface *output_port, base::InputPortInterface *input_port, ConnPolicy const& policy) const;
445 
446 #endif // NO_TYPE_INFO_FACTORY_FUNCTIONS
447 
448  void setTypeId(TypeId tid) {
449  mtid = tid;
450  mtid_name = tid->name();
451  }
452 
457  void setPortFactory( ConnFactoryPtr cf ) { if (cf) mconnf = cf; }
458 
459  ConnFactoryPtr getPortFactory() const { return mconnf; }
460 
461  void setMemberFactory( MemberFactoryPtr mf ) { if (mf) mmembf = mf; }
462 
463  MemberFactoryPtr getMemberFactory() const { return mmembf; }
464 
465  void setValueFactory( ValueFactoryPtr dsf) { if (dsf) mdsf = dsf; }
466 
467  ValueFactoryPtr getValueFactory() const { return mdsf; }
468 
469  void setCompositionFactory( CompositionFactoryPtr cf) { if(cf) mcompf = cf; }
470 
471  CompositionFactoryPtr getCompositionFactory() const { return mcompf; }
472 
473  void setStreamFactory( StreamFactoryPtr sf ) { if (sf) mstrf = sf; }
474 
475  StreamFactoryPtr getStreamFactory() const { return mstrf; }
476  protected:
477  typedef std::vector<TypeConstructor*> Constructors;
478  typedef std::vector<TypeTransporter*> Transporters;
479  Constructors constructors;
480  Transporters transporters;
481  std::vector<std::string> mtypenames;
482  const char* mtid_name;
483  TypeId mtid;
484  boost::shared_ptr<internal::ConnFactory> mconnf;
485  boost::shared_ptr<MemberFactory> mmembf;
486  boost::shared_ptr<ValueFactory> mdsf;
487  boost::shared_ptr<CompositionFactory> mcompf;
488  boost::shared_ptr<StreamFactory> mstrf;
489  };
490 
491 }}
492 
493 #endif
base::DataSourceBase::shared_ptr buildReference(void *ptr) const
Definition: TypeInfo.hpp:238
bool composeType(base::DataSourceBase::shared_ptr source, base::DataSourceBase::shared_ptr target) const
Definition: TypeInfo.hpp:386
boost::shared_ptr< MemberFactory > MemberFactoryPtr
boost::intrusive_ptr< SharedConnectionBase > shared_ptr
void setStreamFactory(StreamFactoryPtr sf)
Definition: TypeInfo.hpp:473
base::AttributeBase * buildVariable(std::string name) const
Definition: TypeInfo.hpp:188
base::AttributeBase * buildAttribute(std::string name, base::DataSourceBase::shared_ptr source=0) const
Definition: TypeInfo.hpp:222
const char * mtid_name
Definition: TypeInfo.hpp:482
const std::string & getTypeName() const
Definition: TypeInfo.hpp:83
boost::shared_ptr< CompositionFactory > mcompf
Definition: TypeInfo.hpp:487
TypeInfo(const std::string &name)
Definition: TypeInfo.hpp:72
bool isStreamable() const
Definition: TypeInfo.hpp:308
void setValueFactory(ValueFactoryPtr dsf)
Definition: TypeInfo.hpp:465
std::string toString(base::DataSourceBase::shared_ptr in) const
Definition: TypeInfo.hpp:291
boost::shared_ptr< MemberFactory > mmembf
Definition: TypeInfo.hpp:485
bool resize(base::DataSourceBase::shared_ptr arg, int size) const
Definition: TypeInfo.hpp:197
const std::type_info * TypeId
Definition: TypeInfo.hpp:70
void setCompositionFactory(CompositionFactoryPtr cf)
Definition: TypeInfo.hpp:469
base::DataSourceBase::shared_ptr buildActionAlias(base::ActionInterface *action, base::DataSourceBase::shared_ptr source) const
Definition: TypeInfo.hpp:248
TypeId getTypeId() const
Definition: TypeInfo.hpp:108
Transporters transporters
Definition: TypeInfo.hpp:480
CompositionFactoryPtr getCompositionFactory() const
Definition: TypeInfo.hpp:471
boost::shared_ptr< internal::ConnFactory > mconnf
Definition: TypeInfo.hpp:484
const char * getTypeIdName() const
Definition: TypeInfo.hpp:113
bool getMember(internal::Reference *ref, base::DataSourceBase::shared_ptr item, const std::string &name) const
Definition: TypeInfo.hpp:350
MemberFactoryPtr getMemberFactory() const
Definition: TypeInfo.hpp:463
std::vector< std::string > getMemberNames() const
Definition: TypeInfo.hpp:324
void setTypeId(TypeId tid)
Definition: TypeInfo.hpp:448
boost::shared_ptr< StreamFactory > StreamFactoryPtr
bool fromString(const std::string &value, base::DataSourceBase::shared_ptr out) const
Definition: TypeInfo.hpp:299
base::AttributeBase * buildConstant(std::string name, base::DataSourceBase::shared_ptr source, int sizehint) const
Definition: TypeInfo.hpp:173
base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item, const std::string &name) const
Definition: TypeInfo.hpp:336
boost::shared_ptr< internal::ConnFactory > ConnFactoryPtr
Definition: TypeInfo.hpp:59
base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item, base::DataSourceBase::shared_ptr id) const
Definition: TypeInfo.hpp:362
ConnFactoryPtr getPortFactory() const
Definition: TypeInfo.hpp:459
base::AttributeBase * buildConstant(std::string name, base::DataSourceBase::shared_ptr source) const
Definition: TypeInfo.hpp:178
Based on the software pattern &#39;command&#39;, this interface allows execution of action objects...
base::AttributeBase * buildAlias(std::string name, base::DataSourceBase::shared_ptr b) const
Definition: TypeInfo.hpp:206
void setMemberFactory(MemberFactoryPtr mf)
Definition: TypeInfo.hpp:461
base::DataSourceBase::shared_ptr convertType(base::DataSourceBase::shared_ptr source) const
Definition: TypeInfo.hpp:414
base::PropertyBase * buildProperty(const std::string &name, const std::string &desc, base::DataSourceBase::shared_ptr source=0) const
Definition: TypeInfo.hpp:214
boost::shared_ptr< ValueFactory > ValueFactoryPtr
boost::intrusive_ptr< ChannelElementBase > shared_ptr
Constructors constructors
Definition: TypeInfo.hpp:479
boost::shared_ptr< CompositionFactory > CompositionFactoryPtr
ValueFactoryPtr getValueFactory() const
Definition: TypeInfo.hpp:467
std::vector< std::string > mtypenames
Definition: TypeInfo.hpp:481
base::DataSourceBase::shared_ptr buildValue() const
Definition: TypeInfo.hpp:230
boost::shared_ptr< ValueFactory > mdsf
Definition: TypeInfo.hpp:486
boost::shared_ptr< StreamFactory > mstrf
Definition: TypeInfo.hpp:488
void setPortFactory(ConnFactoryPtr cf)
Definition: TypeInfo.hpp:457
boost::intrusive_ptr< DataSourceBase > shared_ptr
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
StreamFactoryPtr getStreamFactory() const
Definition: TypeInfo.hpp:475
std::vector< TypeConstructor * > Constructors
Definition: TypeInfo.hpp:477
base::DataSourceBase::shared_ptr decomposeType(base::DataSourceBase::shared_ptr source) const
Definition: TypeInfo.hpp:402
std::vector< TypeTransporter * > Transporters
Definition: TypeInfo.hpp:478
std::istream & read(std::istream &os, base::DataSourceBase::shared_ptr out) const
Definition: TypeInfo.hpp:282
std::ostream & write(std::ostream &os, base::DataSourceBase::shared_ptr in) const
Definition: TypeInfo.hpp:265


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:45