/tmp/ws/src/rtt/rtt/ConfigurationInterface.hpp

Retrieve a Attribute by name. Returns zero if no Attribute by that name exists.

Attribute<double> d_attr = getAttribute("Xval");

See also
addAttribute to add an Attribute.
/***************************************************************************
tag: Peter Soetens Tue Dec 21 22:43:08 CET 2004 ConfigurationInterface.hpp
ConfigurationInterface.hpp - description
-------------------
begin : Tue December 21 2004
copyright : (C) 2004 Peter Soetens
email : peter.soetens@mech.kuleuven.ac.be
***************************************************************************
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public *
* License as published by the Free Software Foundation; *
* version 2 of the License. *
* *
* As a special exception, you may use this file as part of a free *
* software library without restriction. Specifically, if other files *
* instantiate templates or use macros or inline functions from this *
* file, or you compile this file and link it with other files to *
* produce an executable, this file does not by itself cause the *
* resulting executable to be covered by the GNU General Public *
* License. This exception does not however invalidate any other *
* reasons why the executable file might be covered by the GNU General *
* Public License. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307 USA *
* *
***************************************************************************/
#ifndef RTT_CONFIGURATIONINTERFACE_HPP
#define RTT_CONFIGURATIONINTERFACE_HPP
#include <memory>
#include <map>
#include "Attribute.hpp"
#include "Property.hpp"
#include "PropertyBag.hpp"
namespace RTT
{
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());
return attr;
}
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 );
bool removeProperty( base::PropertyBase& p );
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 {
return values;
}
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;
map_t values;
PropertyBag bag;
};
}
#endif


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:19