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
00039 #ifndef RTT_CONFIGURATIONINTERFACE_HPP
00040 #define RTT_CONFIGURATIONINTERFACE_HPP
00041
00042 #include <memory>
00043 #include <map>
00044 #include "Attribute.hpp"
00045 #include "internal/DataSources.hpp"
00046 #include "base/DataObjectInterface.hpp"
00047 #include "Property.hpp"
00048 #include "PropertyBag.hpp"
00049
00050 namespace RTT
00051 {
00060 class RTT_API ConfigurationInterface
00061 {
00062 public:
00063
00067 ConfigurationInterface();
00068 ~ConfigurationInterface();
00069
00074 typedef std::vector<std::string> AttributeNames;
00075
00080 typedef std::vector<base::AttributeBase*> AttributeObjects;
00081
00085 void clear();
00086
00090 bool hasAttribute( const std::string& name ) const;
00091
00100 template<class T>
00101 bool addAttribute( const std::string& name, T& attr) {
00102 Alias a(name, new internal::ReferenceDataSource<T>(attr));
00103 return this->addAttribute( a );
00104 }
00105
00113 template<class T>
00114 Attribute<T>& addAttribute( const std::string& name, Attribute<T>& attr) {
00115 if ( !attr.ready() )
00116 attr = Attribute<T>(name);
00117 else
00118 attr.setName(name);
00119 this->addAttribute( attr );
00120 assert(attr.ready());
00121 return attr;
00122 }
00123
00132 template<class T>
00133 bool addConstant( const std::string& name, const T& cnst) {
00134 Alias a(name, new internal::ConstReferenceDataSource<T>(cnst));
00135 return this->addAttribute( a );
00136 }
00137
00146 template<class T>
00147 Constant<T>& addConstant( const std::string& name, Constant<T>& cnst) {
00148 if ( !cnst.ready() )
00149 cnst = Constant<T>(name, T());
00150 else
00151 cnst.setName(name);
00152 this->addConstant( cnst );
00153 assert(cnst.ready());
00154 return cnst;
00155 }
00156
00166 template<class T>
00167 Property<T>& addProperty( const std::string& name, T& prop) {
00168 return this->properties()->addProperty( name, prop );
00169 }
00170
00178 template<class T>
00179 Property<T>& addProperty( const std::string& name, Property<T>& prop) {
00180 if ( !prop.ready() )
00181 prop = Property<T>(name);
00182 else
00183 prop.setName(name);
00184 this->properties()->addProperty( prop );
00185 assert(prop.ready());
00186 return prop;
00187 }
00188
00198 bool addAttribute( base::AttributeBase& a )
00199 {
00200 return a.getDataSource() ? setValue( a.clone() ) : false;
00201 }
00202
00211 base::AttributeBase* getAttribute( const std::string& name ) const
00212 {
00213 return this->getValue( name );
00214 }
00215
00219 void removeAttribute( const std::string& name );
00220
00225 bool addConstant( base::AttributeBase& c)
00226 {
00227 return c.getDataSource() ? setValue( c.clone() ) : false;
00228 }
00229
00238 base::AttributeBase* getConstant( const std::string& name ) const
00239 {
00240 return this->getValue( name );
00241 }
00242
00246 bool hasProperty( const std::string& name ) const;
00247
00253 bool addProperty( base::PropertyBase& pb );
00254
00259 bool removeProperty( base::PropertyBase& p );
00260
00268 base::PropertyBase* getProperty(const std::string& name) const
00269 {
00270 return bag.find(name);
00271 }
00272
00278 bool setValue( base::AttributeBase* ab );
00279
00289 base::AttributeBase* getValue( const std::string& name ) const;
00290
00294 bool removeValue(const std::string& name );
00295
00303 ConfigurationInterface* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& repl, bool instantiate ) const;
00304
00308 void loadValues( AttributeObjects const& new_values);
00309
00313 AttributeObjects const& getValues() const {
00314 return values;
00315 }
00316
00320 AttributeNames getAttributeNames() const;
00321
00325 PropertyBag* properties();
00326
00327 protected:
00328 typedef std::vector<base::AttributeBase*> map_t;
00329 map_t values;
00330 PropertyBag bag;
00331 };
00332 }
00333
00334 #endif