Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef ORO_CORELIB_TYPEINFO_HPP
00039 #define ORO_CORELIB_TYPEINFO_HPP
00040
00041 #include <vector>
00042 #include <string>
00043 #include "../base/DataSourceBase.hpp"
00044 #include "../base/ChannelElementBase.hpp"
00045
00046 #ifndef NO_TYPE_INFO_FACTORY_FUNCTIONS
00047 #include "MemberFactory.hpp"
00048 #include "ValueFactory.hpp"
00049 #include "CompositionFactory.hpp"
00050 #ifndef NO_TYPE_INFO_STREAMS
00051 #include "StreamFactory.hpp"
00052 #endif
00053 #endif
00054
00055
00056 namespace RTT
00057 { namespace types {
00058 typedef boost::shared_ptr<internal::ConnFactory> ConnFactoryPtr;
00059
00066 class RTT_API TypeInfo
00067 {
00068 public:
00069 typedef const std::type_info * TypeId;
00070
00071 TypeInfo(const std::string& name) : mtypenames(1,name) {}
00072
00073 ~TypeInfo();
00082 const std::string& getTypeName() const { return mtypenames[0]; }
00083
00087 std::vector<std::string> getTypeNames() const;
00088
00094 void addAlias(const std::string& alias);
00095
00102 bool isType(const std::string& name);
00103
00107 TypeId getTypeId() const { return mtid; }
00108
00112 const char * getTypeIdName() const { return mtid_name; }
00113
00119 base::DataSourceBase::shared_ptr construct(const std::vector<base::DataSourceBase::shared_ptr>& args) const;
00120
00126 base::DataSourceBase::shared_ptr convert(base::DataSourceBase::shared_ptr arg) const;
00127
00131 void addConstructor(TypeConstructor* tb);
00132
00142 bool addProtocol(int protocol_id, TypeTransporter* tt);
00143
00149 TypeTransporter* getProtocol(int protocol_id) const;
00150
00154 bool hasProtocol(int protocol_id) const;
00155
00159 std::vector<int> getTransportNames() const;
00160
00161 #ifndef NO_TYPE_INFO_FACTORY_FUNCTIONS
00162
00172 base::AttributeBase* buildConstant(std::string name,base::DataSourceBase::shared_ptr source, int sizehint) const
00173 {
00174 return mdsf ? mdsf->buildConstant(name, source, sizehint) : 0;
00175 }
00176
00177 base::AttributeBase* buildConstant(std::string name,base::DataSourceBase::shared_ptr source) const
00178 {
00179 return mdsf ? mdsf->buildConstant(name, source) : 0;
00180 }
00186 base::AttributeBase* buildVariable(std::string name,int sizehint) const;
00187 base::AttributeBase* buildVariable(std::string name) const
00188 {
00189 return mdsf ? mdsf->buildVariable(name) : 0;
00190 }
00191
00196 bool resize(base::DataSourceBase::shared_ptr arg, int size) const
00197 {
00198 return mmembf ? mmembf->resize(arg, size) : false;
00199 }
00200
00205 base::AttributeBase* buildAlias(std::string name, base::DataSourceBase::shared_ptr b ) const
00206 {
00207 return mdsf ? mdsf->buildAlias(name, b) : 0;
00208 }
00209
00213 base::PropertyBase* buildProperty(const std::string& name, const std::string& desc, base::DataSourceBase::shared_ptr source = 0) const
00214 {
00215 return mdsf ? mdsf->buildProperty(name, desc, source) : 0;
00216 }
00217
00221 base::AttributeBase* buildAttribute(std::string name, base::DataSourceBase::shared_ptr source = 0 ) const
00222 {
00223 return mdsf ? mdsf->buildAttribute(name, source) : 0;
00224 }
00225
00229 base::DataSourceBase::shared_ptr buildValue() const
00230 {
00231 return mdsf ? mdsf->buildValue() : base::DataSourceBase::shared_ptr();
00232 }
00233
00237 base::DataSourceBase::shared_ptr buildReference(void* ptr) const
00238 {
00239 return mdsf ? mdsf->buildReference(ptr) : base::DataSourceBase::shared_ptr();
00240 }
00241
00247 base::DataSourceBase::shared_ptr buildActionAlias(base::ActionInterface* action, base::DataSourceBase::shared_ptr source) const
00248 {
00249 return mdsf ? mdsf->buildActionAlias(action,source) : base::DataSourceBase::shared_ptr();
00250 }
00251
00254 #ifndef NO_TYPE_INFO_STREAMS
00255
00264 std::ostream& write(std::ostream& os, base::DataSourceBase::shared_ptr in ) const
00265 {
00266 return mstrf ? mstrf->write(os, in) : os;
00267 }
00268
00273 std::istream& read(std::istream& os, base::DataSourceBase::shared_ptr out ) const
00274 {
00275 return mstrf ? mstrf->read(os, out) : os;
00276 }
00277
00278
00282 std::string toString( base::DataSourceBase::shared_ptr in ) const
00283 {
00284 return mstrf ? mstrf->toString(in) : std::string();
00285 }
00286
00290 bool fromString( const std::string& value, base::DataSourceBase::shared_ptr out ) const
00291 {
00292 return mstrf ? mstrf->fromString(value, out) : false;
00293 }
00294
00299 bool isStreamable() const
00300 {
00301 return mstrf ? mstrf->isStreamable() : false;
00302 }
00304 #endif
00305
00315 std::vector<std::string> getMemberNames() const
00316 {
00317 return mmembf ? mmembf->getMemberNames() : std::vector<std::string>();
00318 }
00319
00327 base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item, const std::string& name) const
00328 {
00329 return mmembf ? mmembf->getMember(item,name) : base::DataSourceBase::shared_ptr();
00330 }
00331
00341 bool getMember(internal::Reference* ref, base::DataSourceBase::shared_ptr item, const std::string& name) const
00342 {
00343 return mmembf ? mmembf->getMember(ref, item,name) : false;
00344 }
00345
00353 base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item,
00354 base::DataSourceBase::shared_ptr id) const
00355 {
00356 return mmembf ? mmembf->getMember(item,id) : base::DataSourceBase::shared_ptr();
00357 }
00358
00377 bool composeType( base::DataSourceBase::shared_ptr source, base::DataSourceBase::shared_ptr target) const
00378 {
00379 return mcompf ? mcompf->composeType(source,target) : false;
00380 }
00381
00393 base::DataSourceBase::shared_ptr decomposeType(base::DataSourceBase::shared_ptr source) const
00394 {
00395 return mcompf ? mcompf->decomposeType(source) : base::DataSourceBase::shared_ptr();
00396 }
00397
00405 base::DataSourceBase::shared_ptr convertType(base::DataSourceBase::shared_ptr source) const
00406 {
00407 return mcompf ? mcompf->convertType(source) : base::DataSourceBase::shared_ptr();
00408 }
00409
00418 base::InputPortInterface* inputPort(std::string const& name) const;
00419
00424 base::OutputPortInterface* outputPort(std::string const& name) const;
00425
00432 base::ChannelElementBase::shared_ptr buildDataStorage(ConnPolicy const& policy) const;
00433 base::ChannelElementBase::shared_ptr buildChannelOutput(base::InputPortInterface& port) const;
00434 base::ChannelElementBase::shared_ptr buildChannelInput(base::OutputPortInterface& port) const;
00435
00436 #endif // NO_TYPE_INFO_FACTORY_FUNCTIONS
00437
00438 void setTypeId(TypeId tid) {
00439 mtid = tid;
00440 mtid_name = tid->name();
00441 }
00442
00447 void setPortFactory( ConnFactoryPtr cf ) { if (cf) mconnf = cf; }
00448
00449 ConnFactoryPtr getPortFactory() const { return mconnf; }
00450
00451 void setMemberFactory( MemberFactoryPtr mf ) { if (mf) mmembf = mf; }
00452
00453 MemberFactoryPtr getMemberFactory() const { return mmembf; }
00454
00455 void setValueFactory( ValueFactoryPtr dsf) { if (dsf) mdsf = dsf; }
00456
00457 ValueFactoryPtr getValueFactory() const { return mdsf; }
00458
00459 void setCompositionFactory( CompositionFactoryPtr cf) { if(cf) mcompf = cf; }
00460
00461 CompositionFactoryPtr getCompositionFactory() const { return mcompf; }
00462
00463 void setStreamFactory( StreamFactoryPtr sf ) { if (sf) mstrf = sf; }
00464
00465 StreamFactoryPtr getStreamFactory() const { return mstrf; }
00466 protected:
00467 typedef std::vector<TypeConstructor*> Constructors;
00468 typedef std::vector<TypeTransporter*> Transporters;
00469 Constructors constructors;
00470 Transporters transporters;
00471 std::vector<std::string> mtypenames;
00472 const char* mtid_name;
00473 TypeId mtid;
00474 boost::shared_ptr<internal::ConnFactory> mconnf;
00475 boost::shared_ptr<MemberFactory> mmembf;
00476 boost::shared_ptr<ValueFactory> mdsf;
00477 boost::shared_ptr<CompositionFactory> mcompf;
00478 boost::shared_ptr<StreamFactory> mstrf;
00479 };
00480
00481 }}
00482
00483 #endif