PropertyBag Class Reference
[Property Interface]

#include <rtt/PropertyBag.hpp>

List of all members.


Detailed Description

A container for holding references to properties.

Introduction

This class groups properties of different types into a single container. A PropertyBag object can handed to a Marshaller object which will serialize the contents of the PropertyBag.

All operations on a PropertyBag are non recursive. The PropertyBag itself is not aware of the possible hierarchical structure. You need to use the global scope functions for handling hierarchical structures.

A PropertyBag is not the owner of the properties within. It defines a group of properties, nothing more. When this group of properties contains another PropertyBag, this bag is considered as a 'pointer' to other properties. Even such a bag is not owned by the PropertyBag.

Constructing PropertyBags

It can happen in an application that a PropertyBag is filled with dynamically created Property objects. The bag is not responsible for cleaning up these objects once they are no longer needed. The application which uses the PropertyBag has to find a way of deleting the possible dangling pointers.

Warning:
The elements in a PropertyBag are unordered. Operations on the bag may change the relative order of the elements.

Using PropertyBags

To add a Property<ClassT> prop to a PropertyBag bag, use
     bag.add(&prop).
     
To retrieve this property, either use find or getProperty to retrieve a Property by name :
     PropertyBase* pb = bag.find( "name" ).
     Property<ClassT> pb = bag.getProperty<ClassT>( "name" ).
     
Both will return null if no such property exists.
See also:
PropertyBase, Property, BagOperations

Definition at line 98 of file PropertyBag.hpp.


Public Types

typedef std::vector
< PropertyBase * > 
Properties
 The container in which the properties are stored.
typedef Properties PropertyContainerType
 Deprecated, use Properties.
typedef Properties::iterator iterator
 An iterator over the Properties.
typedef Properties::const_iterator const_iterator
 A const iterator over the Properties.
typedef std::vector< std::string > Names
 The container to hold names of Properties.

Public Member Functions

 PropertyBag ()
 The default constructor.
 PropertyBag (const std::string &_type)
 The typed constructor.
 PropertyBag (const PropertyBag &orig)
 The copy constructor.
 ~PropertyBag ()
 Destroy this object and destroy all owned properties.
void add (PropertyBase *p)
 Add a valid property to the container.
void remove (PropertyBase *p)
 Remove a property from the container.
bool addProperty (PropertyBase *p)
 Add a valid property to the container.
bool removeProperty (PropertyBase *p)
 Remove a property from the container.
bool ownProperty (PropertyBase *p)
 Set a property to be owned by this bag.
bool ownsProperty (PropertyBase *p)
 Returns true if this property is owned by this Bag.
void clear ()
 Removes all PropertyBases from this bag, without deleting them.
void list (Names &names) const
 List the names of all properties.
Names list () const
 List the names of all properties.
bool empty () const
 Return true if no properties are present in this bag.
template<class T>
Property< T > * getProperty (const std::string &name) const
 Get a Property<T> with name name.
PropertyBasegetItem (int i) const
 Returns the i'th Property, starting from 0.
size_t size () const
 Get the number of Properties in this bag.
void identify (PropertyIntrospection *pi) const
 Identify the contents of this bag through introspection.
void identify (PropertyBagVisitor *pi) const
 Identify the contents of this bag through introspection.
PropertyBasefind (const std::string &name) const
 Find the PropertyBase with name name.
PropertyBagoperator= (const PropertyBag &orig)
 This assignment assigns all PropertyBases of another bag in this bag, making an exact copy or the original.
PropertyBagoperator<<= (const PropertyBag &source)
 The update operator.
PropertyBagoperator<< (PropertyBase *item)
 The 'add' operator.
const std::string & getType () const
void setType (const std::string &newtype)
PropertiesgetProperties ()
 Returns a list of all the property objects in this bag.
const PropertiesgetProperties () const
 Returns a list of all the property objects in this bag.
Properties getProperties (const std::string &name) const
 Returns a list of all property objects with the name name.
Names getPropertyNames () const
 Returns a list of all the names of the properties in this bag.
iterator begin ()
const_iterator begin () const
iterator end ()
const_iterator end () const

Protected Attributes

Properties mproperties
Properties mowned_props
std::string type

Classes

struct  FindProp
 A function object for finding a Property by name. More...

Constructor & Destructor Documentation

PropertyBag ( const std::string &  _type  ) 

The typed constructor.

Parameters:
type The type of PropertyBag.

Definition at line 53 of file PropertyBag.cpp.

PropertyBag ( const PropertyBag orig  ) 

The copy constructor.

The copy constructor of the PropertyBag makes non-deep copies of its elements.

Definition at line 57 of file PropertyBag.cpp.


Member Function Documentation

void add ( PropertyBase p  ) 

Add a valid property to the container.

Analogous to addProperty.

Parameters:
p Pointer to the property to be added.

Definition at line 67 of file PropertyBag.cpp.

References PropertyBag::addProperty().

Referenced by AttributeRepository::addProperty(), RTT::copyProperties(), RTT::decomposeProperty(), RTT::flattenPropertyBag(), PropertyBagIntrospector::introspect(), and RTT::updateProperties().

void remove ( PropertyBase p  ) 

Remove a property from the container.

Analogous to removeProperty.

Parameters:
p Pointer to the property to be removed.

Definition at line 72 of file PropertyBag.cpp.

References PropertyBag::removeProperty().

Referenced by AttributeRepository::removeProperty().

bool addProperty ( PropertyBase p  ) 

Add a valid property to the container.

Parameters:
p Pointer to the property to be added.
Returns:
false if ! p->ready(), true otherwise.

Definition at line 95 of file PropertyBag.cpp.

References PropertyBase::ready().

Referenced by PropertyBag::add(), and RTT::updateProperty().

bool removeProperty ( PropertyBase p  ) 

Remove a property from the container.

Parameters:
p Pointer to the property to be removed.

Definition at line 103 of file PropertyBag.cpp.

Referenced by PropertyBag::ownProperty(), and PropertyBag::remove().

void clear (  ) 

Removes all PropertyBases from this bag, without deleting them.

This is a not recursive function.

Definition at line 118 of file PropertyBag.cpp.

Referenced by TaskContext::clear(), RTT::deleteProperties(), RTT::deletePropertyBag(), PropertyBag::operator=(), and PropertyBag::~PropertyBag().

void list ( Names names  )  const

List the names of all properties.

Parameters:
names The container which will be used to store all available property names in.

Definition at line 130 of file PropertyBag.cpp.

Referenced by RTT::updateProperties().

std::vector< std::string > list (  )  const

List the names of all properties.

Returns:
A container of names.

Definition at line 140 of file PropertyBag.cpp.

Property<T>* getProperty ( const std::string &  name  )  const [inline]

Get a Property<T> with name name.

Parameters:
T The type of which this property is.
name The name of the property to search for.
Returns:
The Property<T> with this name, zero if it does not exist ( no such T or no such name )

Definition at line 217 of file PropertyBag.hpp.

PropertyBase* getItem ( int  i  )  const [inline]

Returns the i'th Property, starting from 0.

Returns:
zero if i is out of range.

Definition at line 229 of file PropertyBag.hpp.

Referenced by RTT::composeProperty(), and RTT::refreshProperties().

PropertyBase * find ( const std::string &  name  )  const

Find the PropertyBase with name name.

Parameters:
name The name of the property to search for.
Returns:
The PropertyBase with this name, zero if it does not exist.

Definition at line 186 of file PropertyBag.cpp.

Referenced by AttributeRepository::addProperty(), RTT::composeProperty(), RTT::findProperty(), AttributeRepository::hasProperty(), PropertyBag::operator<<=(), RTT::refreshProperties(), RTT::refreshProperty(), AttributeRepository::removeProperty(), and RTT::updateProperty().

PropertyBag & operator<<= ( const PropertyBag source  ) 

The update operator.

It updates this bag so it contains all PropertyBases of another bag, removing own PropertyBases if duplicate names exist in the source bag.

Definition at line 208 of file PropertyBag.cpp.

References PropertyBag::find(), PropertyBag::getProperties(), and PropertyBag::getType().

PropertyBag& operator<< ( PropertyBase item  )  [inline]

The 'add' operator.

Equivalent to add().

Parameters:
item The Property to add to this bag.

Definition at line 280 of file PropertyBag.hpp.


The documentation for this class was generated from the following files:

Generated on Mon Jan 19 16:53:58 2009 for OrocosReal-TimeToolkit by  doxygen 1.5.6