Types.hpp
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_TYPES_HPP
00039 #define ORO_CORELIB_TYPES_HPP
00040
00041 #include <map>
00042 #include <vector>
00043 #include <string>
00044 #include "DataSourceBase.hpp"
00045 #include <boost/shared_ptr.hpp>
00046 #include "AttributeBase.hpp"
00047 #include "Logger.hpp"
00048
00057 namespace RTT
00058 {
00059
00060 class PropertyBase;
00061 class PropertyBag;
00062 class AttributeBase;
00063 class TransportPlugin;
00064
00065 namespace detail {
00066 class TypeTransporter;
00067 }
00068
00072 struct RTT_API TypeBuilder
00073 {
00074 virtual ~TypeBuilder();
00079 virtual DataSourceBase::shared_ptr build(const std::vector<DataSourceBase::shared_ptr>& args) const = 0;
00080
00084 virtual DataSourceBase::shared_ptr convert(DataSourceBase::shared_ptr arg) const
00085 {
00086 return DataSourceBase::shared_ptr();
00087 }
00088 };
00089
00094 class RTT_API TypeInfo
00095 {
00096 protected:
00097 typedef std::vector<TypeBuilder*> Constructors;
00098 typedef std::vector<detail::TypeTransporter*> Transporters;
00099 Constructors constructors;
00100 Transporters transporters;
00101 public:
00102 virtual ~TypeInfo();
00106 virtual const std::string& getTypeName() const = 0;
00107
00118 virtual AttributeBase* buildConstant(std::string name,DataSourceBase::shared_ptr, int sizehint) const;
00119 virtual AttributeBase* buildConstant(std::string name,DataSourceBase::shared_ptr) const = 0;
00125 virtual AttributeBase* buildVariable(std::string name,int sizehint) const;
00126 virtual AttributeBase* buildVariable(std::string name) const = 0;
00127
00133 virtual DataSourceBase::shared_ptr construct(const std::vector<DataSourceBase::shared_ptr>& args) const;
00134
00140 virtual DataSourceBase::shared_ptr convert(DataSourceBase::shared_ptr arg) const;
00141
00145 virtual void addConstructor(TypeBuilder* tb);
00146
00151 virtual AttributeBase* buildAlias(std::string name, DataSourceBase::shared_ptr b ) const = 0;
00152
00156 virtual PropertyBase* buildProperty(const std::string& name, const std::string& desc, DataSourceBase::shared_ptr source = 0) const = 0;
00157
00161 virtual AttributeBase* buildAttribute(std::string name, DataSourceBase::shared_ptr source = 0 ) const = 0;
00162
00166 virtual DataSourceBase::shared_ptr buildValue() const = 0;
00178 virtual std::ostream& write(std::ostream& os, DataSourceBase::shared_ptr in ) const = 0;
00179
00184 virtual std::istream& read(std::istream& os, DataSourceBase::shared_ptr out ) const = 0;
00185
00189 virtual std::string toString( DataSourceBase::shared_ptr in ) const;
00190
00194 virtual bool fromString( const std::string& value, DataSourceBase::shared_ptr out ) const;
00207 virtual bool decomposeType( DataSourceBase::shared_ptr source, PropertyBag& targetbag ) const = 0;
00208
00214 virtual bool composeType( DataSourceBase::shared_ptr source, DataSourceBase::shared_ptr target) const = 0;
00228 bool addProtocol(int protocol_id, detail::TypeTransporter* tt);
00229
00230 detail::TypeTransporter* getProtocol(int protocol_id) const;
00231
00235 std::vector<int> getTransportNames() const;
00236
00241 };
00242
00247 class RTT_API TypeInfoRepository
00248 {
00249 TypeInfoRepository();
00250 typedef std::map<std::string, TypeInfo*> map_t;
00251 map_t data;
00252
00253 typedef std::vector<TransportPlugin*> Transports;
00254 Transports transports;
00255 public:
00256 ~TypeInfoRepository();
00257 typedef boost::shared_ptr<TypeInfoRepository> shared_ptr;
00258 static shared_ptr Instance();
00262 TypeInfo* type( const std::string& name ) const;
00263
00267 bool addType( TypeInfo* );
00268
00272 std::vector<std::string> getTypes() const;
00273
00278 void registerTransport( TransportPlugin* tr );
00279
00284 void logTypeInfo() const;
00285
00286 };
00287
00292 TypeInfoRepository::shared_ptr types();
00293 }
00294
00295 #endif