ConfigurationInterface.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Tue Dec 21 22:43:08 CET 2004 ConfigurationInterface.hpp
3 
4  ConfigurationInterface.hpp - description
5  -------------------
6  begin : Tue December 21 2004
7  copyright : (C) 2004 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 #ifndef RTT_CONFIGURATIONINTERFACE_HPP
40 #define RTT_CONFIGURATIONINTERFACE_HPP
41 
42 #include <memory>
43 #include <map>
44 #include "Attribute.hpp"
45 #include "internal/DataSources.hpp"
47 #include "Property.hpp"
48 #include "PropertyBag.hpp"
49 
50 namespace RTT
51 {
60  class RTT_API ConfigurationInterface
61  {
62  public:
63 
69 
74  typedef std::vector<std::string> AttributeNames;
75 
80  typedef std::vector<base::AttributeBase*> AttributeObjects;
81 
85  void clear();
86 
90  bool hasAttribute( const std::string& name ) const;
91 
100  template<class T>
101  bool addAttribute( const std::string& name, T& attr) {
102  if ( !chkPtr("addAttribute", name, &attr) ) return false;
103  Alias a(name, new internal::ReferenceDataSource<T>(attr));
104  return this->addAttribute( a );
105  }
106 
114  template<class T>
115  Attribute<T>& addAttribute( const std::string& name, Attribute<T>& attr) {
116  if ( !chkPtr("addAttribute", name, &attr) ) return attr;
117  if ( !attr.ready() )
118  attr = Attribute<T>(name);
119  else
120  attr.setName(name);
121  this->addAttribute( attr );
122  assert(attr.ready());
123  return attr;
124  }
125 
134  template<class T>
135  bool addConstant( const std::string& name, const T& cnst) {
136  if ( !chkPtr("addConstant", name, &cnst) ) return false;
137  Alias a(name, new internal::ConstReferenceDataSource<T>(cnst));
138  return this->addAttribute( a );
139  }
140 
149  template<class T>
150  Constant<T>& addConstant( const std::string& name, Constant<T>& cnst) {
151  if ( !chkPtr("addConstant", name, &cnst) ) return cnst;
152  if ( !cnst.ready() )
153  cnst = Constant<T>(name, T());
154  else
155  cnst.setName(name);
156  this->addConstant( cnst );
157  assert(cnst.ready());
158  return cnst;
159  }
160 
170  template<class T>
171  Property<T>& addProperty( const std::string& name, T& prop) {
172  if ( !chkPtr("addProperty", name, &prop) ) return internal::NA<Property<T>& >::na();
173  return this->properties()->addProperty( name, prop );
174  }
175 
183  template<class T>
184  Property<T>& addProperty( const std::string& name, Property<T>& prop) {
185  if ( !chkPtr("addProperty", name, &prop) ) return prop;
186  if ( !prop.ready() )
187  prop = Property<T>(name);
188  else
189  prop.setName(name);
190  this->properties()->addProperty( prop );
191  assert(prop.ready());
192  return prop;
193  }
194 
205  {
206  if ( !chkPtr("addAttribute", "AttributeBase", &a) ) return false;
207  return a.getDataSource() ? setValue( a.clone() ) : false;
208  }
209 
218  base::AttributeBase* getAttribute( const std::string& name ) const
219  {
220  return this->getValue( name );
221  }
222 
226  void removeAttribute( const std::string& name );
227 
233  {
234  return c.getDataSource() ? setValue( c.clone() ) : false;
235  }
236 
245  base::AttributeBase* getConstant( const std::string& name ) const
246  {
247  return this->getValue( name );
248  }
249 
253  bool hasProperty( const std::string& name ) const;
254 
260  bool addProperty( base::PropertyBase& pb );
261 
267 
275  base::PropertyBase* getProperty(const std::string& name) const
276  {
277  return bag.find(name);
278  }
279 
285  bool setValue( base::AttributeBase* ab );
286 
296  base::AttributeBase* getValue( const std::string& name ) const;
297 
301  bool removeValue(const std::string& name );
302 
310  ConfigurationInterface* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& repl, bool instantiate ) const;
311 
315  void loadValues( AttributeObjects const& new_values);
316 
320  AttributeObjects const& getValues() const {
321  return values;
322  }
323 
327  AttributeNames getAttributeNames() const;
328 
332  PropertyBag* properties();
333 
334  protected:
335  bool chkPtr(const std::string &where, const std::string& name, const void* ptr);
336  typedef std::vector<base::AttributeBase*> map_t;
337  map_t values;
339  };
340 }
341 
342 #endif
bool removeProperty(PropertyBag &bag, const std::string &path, const std::string &separator)
bool addAttribute(base::AttributeBase &a)
virtual AttributeBase * clone() const =0
Constant< T > & addConstant(const std::string &name, Constant< T > &cnst)
bool addConstant(base::AttributeBase &c)
A container for holding references to properties.
Definition: PropertyBag.hpp:96
virtual DataSourceBase::shared_ptr getDataSource() const =0
std::vector< base::AttributeBase * > map_t
std::vector< std::string > AttributeNames
AttributeObjects const & getValues() const
base::PropertyBase * getProperty(const std::string &name) const
A property represents a named value of any type with a description.
Definition: Property.hpp:76
base::AttributeBase * getAttribute(const std::string &name) const
A class for keeping track of Attribute, Constant and Property objects of a TaskContext. It allows plugins and remote components to browse the attributes and properties of a TaskContext.
void setName(const std::string &name)
Property< T > & addProperty(const std::string &name, T &prop)
Property< T > & addProperty(const std::string &name, Property< T > &prop)
bool addConstant(const std::string &name, const T &cnst)
std::vector< base::AttributeBase * > AttributeObjects
base::AttributeBase * getConstant(const std::string &name) const
std::vector< typename MapT::mapped_type > values(const MapT &map)
Definition: mystd.hpp:140
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
def attr(e, n)
Definition: svn2log.py:70
void setName(std::string const &new_name)
Definition: Attribute.cpp:64
Attribute< T > & addAttribute(const std::string &name, Attribute< T > &attr)
bool addAttribute(const std::string &name, T &attr)


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