PropertyBag.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jan 19 14:11:20 CET 2004 PropertyBag.hpp
3 
4  PropertyBag.hpp - description
5  -------------------
6  begin : Mon January 19 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 #ifndef PI_PROPERTY_BAG
39 #define PI_PROPERTY_BAG
40 
41 #include "base/PropertyBase.hpp"
42 
43 #include <vector>
44 #include <algorithm>
45 
46 #ifdef ORO_PRAGMA_INTERFACE
47 #pragma interface
48 #endif
49 
50 namespace RTT
51 {
52 
96  class RTT_API PropertyBag
97  {
98  public:
102  typedef std::vector<base::PropertyBase*> Properties;
106  typedef Properties PropertyContainerType;
110  typedef Properties::iterator iterator;
114  typedef Properties::const_iterator const_iterator;
115 
119  typedef std::vector<std::string> Names;
123  PropertyBag();
124 
130  PropertyBag( const std::string& _type);
131 
137  PropertyBag( const PropertyBag& orig);
138 
142  ~PropertyBag();
143 
148  void add(base::PropertyBase *p);
149 
154  void remove(base::PropertyBase *p);
155 
165  template<class T>
166  Property<T>& addProperty( const std::string& name, T& attr) {
168  Property<T>* p = new Property<T>(name,"", datasource);
169  this->ownProperty( p );
170  return *p;
171  }
172 
173 
179  bool addProperty(base::PropertyBase& p);
180 
186 
190  bool ownProperty(base::PropertyBase* p);
191 
195  bool ownsProperty(base::PropertyBase* p) const;
196 
201  void clear();
202 
208  void list(Names &names) const;
209 
214  Names list() const;
215 
219  bool empty() const
220  {
221  return mproperties.empty();
222  }
223 
231  base::PropertyBase* getProperty(const std::string& name) const;
232 
241  template<class T>
242  Property<T>* getPropertyType(const std::string& name) const
243  {
244  const_iterator i( std::find_if(mproperties.begin(), mproperties.end(), std::bind2nd(FindPropType<T>(), name ) ) );
245  if ( i != mproperties.end() )
246  return dynamic_cast<Property<T>* >(*i);
247  return 0;
248  }
249 
255  {
256  if ( i < 0 || i >= int(mproperties.size()) )
257  return 0;
258  return mproperties[i];
259  }
260 
264  size_t size() const { return mproperties.size(); }
265 
270  void identify( base::PropertyIntrospection* pi ) const;
271 
276  void identify( base::PropertyBagVisitor* pi ) const;
277 
286  base::PropertyBase* find(const std::string& name) const;
287 
294  template<class T>
295  base::PropertyBase* findValue(const T& value) const {
296  for ( const_iterator i = mproperties.begin();
297  i != mproperties.end();
298  i++ )
299  {
300  Property<T> p = *i;
301  if (p.ready() && (p.value() == value))
302  return *i;
303  }
304  return 0;
305  }
306 
312  PropertyBag& operator=(const PropertyBag& orig);
313 
320  PropertyBag& operator<<=(const PropertyBag& source);
321 
327  PropertyBag& operator<<( base::PropertyBase* item) { this->add(item); return *this; }
328 
329  const std::string& getType() const { return type;}
330 
331  void setType(const std::string& newtype) { type = newtype; }
332 
336  Properties& getProperties() { return mproperties; }
337 
341  const Properties& getProperties() const { return mproperties; }
342 
346  Properties getProperties(const std::string& name) const;
347 
351  Names getPropertyNames() const { return list(); }
352 
353  iterator begin() { return mproperties.begin(); }
354  const_iterator begin() const { return mproperties.begin(); }
355  iterator end() { return mproperties.end(); }
356  const_iterator end() const { return mproperties.end(); }
357  protected:
358  Properties mproperties;
359  Properties mowned_props;
360 
364  template<class T>
365  struct FindPropType : public std::binary_function<const base::PropertyBase*,const std::string, bool>
366  {
367  bool operator()(const base::PropertyBase* b1, const std::string& b2) const { return b1->getName() == b2 && dynamic_cast<const Property<T>* >(b1) != 0; }
368  };
369 
370  std::string type;
371  };
372 
388  RTT_API std::ostream& operator<<(std::ostream& os, const PropertyBag& bag);
389 
396  RTT_API std::istream& operator>>(std::istream& is, PropertyBag& bag);
397 
409  RTT_API base::PropertyBase* findProperty(const PropertyBag& bag, const std::string& path, const std::string& separator = std::string(".") );
410 
421  RTT_API std::vector<std::string> listProperties( const PropertyBag& bag, const std::string& separator = std::string("."));
422 
432  RTT_API std::vector<std::string> listPropertyDescriptions( const PropertyBag& bag, const std::string& separator = std::string("."));
433 
442  RTT_API bool storeProperty(PropertyBag& bag, const std::string& path, base::PropertyBase* item, const std::string& separator = std::string(".") );
443 
452  RTT_API bool removeProperty(PropertyBag& bag, const std::string& path, const std::string& separator = std::string(".") );
453 
467  RTT_API bool refreshProperties(const PropertyBag& target, const PropertyBag& source, bool strict=false);
468 
476  RTT_API bool refreshProperty(const PropertyBag& target, const base::PropertyBase& source);
477 
488  RTT_API bool copyProperties(PropertyBag& target, const PropertyBag& source);
489 
501  RTT_API bool updateProperties(PropertyBag& target, const PropertyBag& source);
502 
517  RTT_API bool updateProperty(PropertyBag& target, const PropertyBag& source, const std::string& path, const std::string& separator = ".");
518 
532  RTT_API bool refreshProperty(PropertyBag& target, const PropertyBag& source, const std::string& path, const std::string& separator = ".");
533 
544  RTT_API void deleteProperties(PropertyBag& target);
545 
556  RTT_API void deletePropertyBag(PropertyBag& target);
557 
567  RTT_API void flattenPropertyBag(PropertyBag& target, const std::string& separator=".");
568 
572 } // Namespace RTT
573 #endif
bool removeProperty(PropertyBag &bag, const std::string &path, const std::string &separator)
bool updateProperty(PropertyBag &target, const PropertyBag &source, const std::string &name, const std::string &separator)
base::PropertyBase * findValue(const T &value) const
Property< T > * getPropertyType(const std::string &name) const
bool updateProperties(PropertyBag &target, const PropertyBag &source)
PropertyBag & operator<<(base::PropertyBase *item)
std::istream & operator>>(std::istream &is, BufferPolicy &bp)
const std::string & getType() const
bool operator()(const base::PropertyBase *b1, const std::string &b2) const
bool refreshProperties(const PropertyBag &target, const PropertyBag &source, bool allprops)
bool copyProperties(PropertyBag &target, const PropertyBag &source)
void setType(const std::string &newtype)
A container for holding references to properties.
Definition: PropertyBag.hpp:96
void flattenPropertyBag(PropertyBag &target, const std::string &separator)
Names getPropertyNames() const
reference_t value()
Definition: Property.hpp:277
PropertyBase * findProperty(const PropertyBag &bag, const std::string &nameSequence, const std::string &separator)
void deletePropertyBag(PropertyBag &target)
Property< T > & addProperty(const std::string &name, T &attr)
Properties PropertyContainerType
const_iterator begin() const
A property represents a named value of any type with a description.
Definition: Property.hpp:76
Properties mowned_props
std::string type
Properties & getProperties()
Properties::const_iterator const_iterator
bool empty() const
bool refreshProperty(const PropertyBag &target, const PropertyBase &source)
boost::intrusive_ptr< AssignableDataSource< T > > shared_ptr
Definition: DataSource.hpp:198
const Properties & getProperties() const
std::ostream & operator<<(std::ostream &os, const BufferPolicy &bp)
vector< string > listProperties(const PropertyBag &source, const std::string &separator)
bool storeProperty(PropertyBag &bag, const std::string &path, base::PropertyBase *item, const std::string &separator)
base::PropertyBase * getItem(int i) const
void deleteProperties(PropertyBag &target)
std::vector< std::string > Names
const std::string & getName() const
vector< string > listPropertyDescriptions(const PropertyBag &source, const std::string &separator)
Properties::iterator iterator
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
size_t size() const
def attr(e, n)
Definition: svn2log.py:70
Properties mproperties
const_iterator end() const
std::vector< base::PropertyBase * > Properties
iterator begin()


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