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
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 if ( !chkPtr("addAttribute", name, &attr) ) return false;
00103 Alias a(name, new internal::ReferenceDataSource<T>(attr));
00104 return this->addAttribute( a );
00105 }
00106
00114 template<class T>
00115 Attribute<T>& addAttribute( const std::string& name, Attribute<T>& attr) {
00116 if ( !chkPtr("addAttribute", name, &attr) ) return attr;
00117 if ( !attr.ready() )
00118 attr = Attribute<T>(name);
00119 else
00120 attr.setName(name);
00121 this->addAttribute( attr );
00122 assert(attr.ready());
00123 return attr;
00124 }
00125
00134 template<class T>
00135 bool addConstant( const std::string& name, const T& cnst) {
00136 if ( !chkPtr("addConstant", name, &cnst) ) return false;
00137 Alias a(name, new internal::ConstReferenceDataSource<T>(cnst));
00138 return this->addAttribute( a );
00139 }
00140
00149 template<class T>
00150 Constant<T>& addConstant( const std::string& name, Constant<T>& cnst) {
00151 if ( !chkPtr("addConstant", name, &cnst) ) return cnst;
00152 if ( !cnst.ready() )
00153 cnst = Constant<T>(name, T());
00154 else
00155 cnst.setName(name);
00156 this->addConstant( cnst );
00157 assert(cnst.ready());
00158 return cnst;
00159 }
00160
00170 template<class T>
00171 Property<T>& addProperty( const std::string& name, T& prop) {
00172 if ( !chkPtr("addProperty", name, &prop) ) return internal::NA<Property<T>& >::na();
00173 return this->properties()->addProperty( name, prop );
00174 }
00175
00183 template<class T>
00184 Property<T>& addProperty( const std::string& name, Property<T>& prop) {
00185 if ( !chkPtr("addProperty", name, &prop) ) return prop;
00186 if ( !prop.ready() )
00187 prop = Property<T>(name);
00188 else
00189 prop.setName(name);
00190 this->properties()->addProperty( prop );
00191 assert(prop.ready());
00192 return prop;
00193 }
00194
00204 bool addAttribute( base::AttributeBase& a )
00205 {
00206 if ( !chkPtr("addAttribute", "AttributeBase", &a) ) return false;
00207 return a.getDataSource() ? setValue( a.clone() ) : false;
00208 }
00209
00218 base::AttributeBase* getAttribute( const std::string& name ) const
00219 {
00220 return this->getValue( name );
00221 }
00222
00226 void removeAttribute( const std::string& name );
00227
00232 bool addConstant( base::AttributeBase& c)
00233 {
00234 return c.getDataSource() ? setValue( c.clone() ) : false;
00235 }
00236
00245 base::AttributeBase* getConstant( const std::string& name ) const
00246 {
00247 return this->getValue( name );
00248 }
00249
00253 bool hasProperty( const std::string& name ) const;
00254
00260 bool addProperty( base::PropertyBase& pb );
00261
00266 bool removeProperty( base::PropertyBase& p );
00267
00275 base::PropertyBase* getProperty(const std::string& name) const
00276 {
00277 return bag.find(name);
00278 }
00279
00285 bool setValue( base::AttributeBase* ab );
00286
00296 base::AttributeBase* getValue( const std::string& name ) const;
00297
00301 bool removeValue(const std::string& name );
00302
00310 ConfigurationInterface* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& repl, bool instantiate ) const;
00311
00315 void loadValues( AttributeObjects const& new_values);
00316
00320 AttributeObjects const& getValues() const {
00321 return values;
00322 }
00323
00327 AttributeNames getAttributeNames() const;
00328
00332 PropertyBag* properties();
00333
00334 protected:
00335 bool chkPtr(const std::string &where, const std::string& name, const void* ptr);
00336 typedef std::vector<base::AttributeBase*> map_t;
00337 map_t values;
00338 PropertyBag bag;
00339 };
00340 }
00341
00342 #endif