Retrieve a Attribute by name. Returns zero if no Attribute by that name exists.
#ifndef RTT_CONFIGURATIONINTERFACE_HPP
#define RTT_CONFIGURATIONINTERFACE_HPP
#include <memory>
#include <map>
{
class RTT_API ConfigurationInterface
{
public:
ConfigurationInterface();
~ConfigurationInterface();
typedef std::vector<std::string> AttributeNames;
typedef std::vector<base::AttributeBase*> AttributeObjects;
void clear();
bool hasAttribute( const std::string& name ) const;
template<class T>
bool addAttribute(
const std::string& name, T&
attr) {
if ( !chkPtr("addAttribute", name, &attr) ) return false;
Alias a(name, new internal::ReferenceDataSource<T>(attr));
return this->addAttribute( a );
}
template<class T>
Attribute<T>& addAttribute( const std::string& name, Attribute<T>& attr) {
if ( !chkPtr(
"addAttribute", name, &attr) )
return attr;
if ( !attr.ready() )
attr = Attribute<T>(name);
else
attr.setName(name);
this->addAttribute( attr );
assert(attr.ready());
}
template<class T>
bool addConstant( const std::string& name, const T& cnst) {
if ( !chkPtr("addConstant", name, &cnst) ) return false;
Alias a(name, new internal::ConstReferenceDataSource<T>(cnst));
return this->addAttribute( a );
}
template<class T>
Constant<T>& addConstant( const std::string& name, Constant<T>& cnst) {
if ( !chkPtr("addConstant", name, &cnst) ) return cnst;
if ( !cnst.ready() )
cnst = Constant<T>(name, T());
else
cnst.setName(name);
this->addConstant( cnst );
assert(cnst.ready());
return cnst;
}
template<class T>
Property<T>& addProperty( const std::string& name, T& prop) {
if ( !chkPtr("addProperty", name, &prop) ) return internal::NA<Property<T>& >::na();
return this->properties()->addProperty( name, prop );
}
template<class T>
Property<T>& addProperty( const std::string& name, Property<T>& prop) {
if ( !chkPtr("addProperty", name, &prop) ) return prop;
if ( !prop.ready() )
prop = Property<T>(name);
else
prop.setName(name);
this->properties()->addProperty( prop );
assert(prop.ready());
return prop;
}
bool addAttribute( base::AttributeBase& a )
{
if ( !chkPtr("addAttribute", "AttributeBase", &a) ) return false;
return a.getDataSource() ? setValue( a.clone() ) : false;
}
base::AttributeBase* getAttribute( const std::string& name ) const
{
return this->getValue( name );
}
void removeAttribute( const std::string& name );
bool addConstant( base::AttributeBase& c)
{
return c.getDataSource() ? setValue( c.clone() ) : false;
}
base::AttributeBase* getConstant( const std::string& name ) const
{
return this->getValue( name );
}
bool hasProperty( const std::string& name ) const;
bool addProperty( base::PropertyBase& pb );
base::PropertyBase* getProperty(const std::string& name) const
{
return bag.find(name);
}
bool setValue( base::AttributeBase* ab );
base::AttributeBase* getValue( const std::string& name ) const;
bool removeValue(const std::string& name );
ConfigurationInterface* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& repl, bool instantiate ) const;
void loadValues( AttributeObjects const& new_values);
AttributeObjects const& getValues() const {
}
AttributeNames getAttributeNames() const;
PropertyBag* properties();
protected:
bool chkPtr(const std::string &where, const std::string& name, const void* ptr);
typedef std::vector<base::AttributeBase*> map_t;
PropertyBag bag;
};
}
#endif