RobWorkProject  23.9.11-
Classes | Public Types | Public Member Functions | List of all members
PropertyMap Class Reference

Container for a collection of Property Objects. More...

#include <PropertyMap.hpp>

Public Types

typedef rw::core::Ptr< PropertyMapPtr
 smart pointer type to this class
 
typedef std::function< void(PropertyMap *, rw::core::PropertyBase *)> PropertyChangedListener
 Method signature for a callback function.
 
typedef MapType::const_iterator iterator
 Iterator for const PropertyBase::Ptr.
 
typedef rw::core::iter_pair< iteratorRange
 Type for a range of properties.
 

Public Member Functions

 PropertyMap ()
 Constructor.
 
 PropertyMap (std::string name)
 constructor More...
 
 ~PropertyMap ()
 Destructor.
 
 PropertyMap (const PropertyMap &other)
 Copy constructor.
 
PropertyMapoperator= (const PropertyMap &other)
 Assignment operator.
 
void swap (PropertyMap &other)
 swap operator.
 
void clear ()
 Clear the content of the property map.
 
const std::string & getName () const
 get the name of this propertymap More...
 
template<class T >
rw::core::Ptr< rw::core::Property< T > > set (const std::string &identifier, const T &value)
 Set the value of a property. More...
 
template<typename T >
rw::core::Ptr< rw::core::Property< T > > add (const std::string &identifier, const std::string &description, const T &value)
 Add a property to the map. If a property with the same identifier already exists then nothing is added/changed and the existing property is returned. More...
 
template<typename T >
rw::core::Ptr< rw::core::Property< T > > addForce (const std::string &identifier, const std::string &description, const T &value)
 Add a property to the map. If a property with the same identifier already exists then the value and description are changed and the existing property is returned. More...
 
bool add (rw::core::PropertyBase::Ptr property)
 Adds a property to the map. More...
 
template<class T >
T * getPtr (const std::string &identifier)
 Get the value of a property or NULL if no such property. More...
 
template<class T >
const T * getPtr (const std::string &identifier) const
 Get the value of a property or NULL if no such property. More...
 
template<class T >
T & get (const std::string &identifier)
 Get the value of a property. More...
 
template<class T >
const T & get (const std::string &identifier) const
 Get the value of a property. More...
 
template<class T >
T & get (const std::string &identifier, const T &defval)
 Get the value of a property if it exists. More...
 
template<class T >
const T & get (const std::string &identifier, const T &defval) const
 Get the value of a property. More...
 
bool has (const std::string &identifier) const
 True if a specific property exists. More...
 
size_t size () const
 The number of properties.
 
bool empty () const
 True iff the property map contains no properties.
 
bool erase (const std::string &identifier)
 Remove a property. More...
 
template<class T >
rw::core::Ptr< rw::core::Property< T > > findProperty (const std::string &identifier) const
 Find the property for an identifier. More...
 
rw::core::PropertyBase::Ptr findPropertyBase (const std::string &identifier)
 Find the property base for an identifier. More...
 
const rw::core::PropertyBase::Ptr findPropertyBase (const std::string &identifier) const
 Find the property base for an identifier. More...
 
void addChangedListener (PropertyChangedListener callback)
 Add listener to be call, when the property changes. More...
 
void clearChangedListeners ()
 Clears the list of changed listeners.
 
void notifyListeners (rw::core::PropertyBase *base=NULL)
 Notifies listeners about a change in the Property.
 
void propertyChangedListener (rw::core::PropertyBase *base)
 used for listening for property changes in the map More...
 
Range getProperties () const
 Range of all PropertyBase* objects stored. More...
 
template<>
rw::core::Ptr< Property< rw::math::Q > > findProperty (const std::string &identifier) const
 Find the property for an identifier. More...
 

Detailed Description

Container for a collection of Property Objects.

This container is used to bind various user information to for example Frame.

Example: Getting a string property with ID "Camera" from a frame

const std::string* ptr = frame.getPropertyMap().getPtr<std::string>("Camera");
if (ptr) {
std::cout << "Property 'Camera' has value " << *ptr << "\n";
}

Constructor & Destructor Documentation

◆ PropertyMap()

PropertyMap ( std::string  name)
inline

constructor

Parameters
name[in] name of this propertymap

Member Function Documentation

◆ add() [1/2]

rw::core::Ptr<rw::core::Property<T> > add ( const std::string &  identifier,
const std::string &  description,
const T &  value 
)
inline

Add a property to the map. If a property with the same identifier already exists then nothing is added/changed and the existing property is returned.

This will fire a PropertyChangedEvent (if a new property is added).

Parameters
identifier[in] Property identifier.
description[in] Property description.
value[in] Property value.
Returns
The property if added or the existing property if the identifier is already in use.

◆ add() [2/2]

bool add ( rw::core::PropertyBase::Ptr  property)

Adds a property to the map.

This will fire a PropertyChangedEvent.

Parameters
property[in] Property to add
Returns
True if added, false if property already exists.

◆ addChangedListener()

void addChangedListener ( PropertyChangedListener  callback)

Add listener to be call, when the property changes.

Parameters
callback[in] Callback method

◆ addForce()

rw::core::Ptr<rw::core::Property<T> > addForce ( const std::string &  identifier,
const std::string &  description,
const T &  value 
)
inline

Add a property to the map. If a property with the same identifier already exists then the value and description are changed and the existing property is returned.

This will fire a PropertyChangedEvent.

Parameters
identifier[in] Property identifier.
description[in] Property description.
value[in] Property value.
Returns
The property if added or the existing property if the identifier is already in use.

◆ erase()

bool erase ( const std::string &  identifier)

Remove a property.

Returns
true if the property was successfully removed.

◆ findProperty() [1/2]

rw::core::Ptr<rw::core::Property<T> > findProperty ( const std::string &  identifier) const
inline

Find the property for an identifier.

The method finds the Property<T> object having a given identifier. If no property with that identifier exists or if the value of the property is not of type T then NULL is returned.

Parameters
identifier[in] property identifier
Returns
Property object with that identifier

◆ findProperty() [2/2]

rw::core::Ptr<Property<rw::math::Q> > findProperty ( const std::string &  identifier) const

Find the property for an identifier.

The method finds the Property<T> object having a given identifier. If no property with that identifier exists or if the value of the property is not of type T then NULL is returned.

Parameters
identifier[in] property identifier
Returns
Property object with that identifier

◆ findPropertyBase() [1/2]

rw::core::PropertyBase::Ptr findPropertyBase ( const std::string &  identifier)

Find the property base for an identifier.

The find methods returns pointer to PropertyBase object or NULL if a property base with that identifier does not exist.

Parameters
identifier[in] identifier for the property base to find.

◆ findPropertyBase() [2/2]

const rw::core::PropertyBase::Ptr findPropertyBase ( const std::string &  identifier) const

Find the property base for an identifier.

The find methods returns pointer to PropertyBase object or NULL if a property base with that identifier does not exist.

Parameters
identifier[in] identifier for the property base to find.

◆ get() [1/4]

T& get ( const std::string &  identifier)
inline

Get the value of a property.

If a property of the given identifier and type cannot be found, the method throws an exception

Parameters
identifier[in] the identifier of the property
Returns
the value of the property

◆ get() [2/4]

const T& get ( const std::string &  identifier) const
inline

Get the value of a property.

If a property of the given identifier and type cannot be found, the method throws an exception

Parameters
identifier[in] the identifier of the property
Returns
the value of the property

◆ get() [3/4]

T& get ( const std::string &  identifier,
const T &  defval 
)
inline

Get the value of a property if it exists.

If a property of the given identifier and type cannot be found, the method returns the default value defval.

example int iterations = map.get<int>("Iterations", 20);

This will fire a PropertyChangedEvent if a new property is added. Notice that a new property is inserted in the map with the default value if it does not already exist.

Parameters
identifier[in] the identifier of the property
defval[in] the value that will be returned if property with identifier is not found.
Returns
the value of the property if it exists, else defval is returned

◆ get() [4/4]

const T& get ( const std::string &  identifier,
const T &  defval 
) const
inline

Get the value of a property.

If a property of the given identifier and type cannot be found method throws an exception

example int iterations = map.get<int>("Iterations", 20);

Parameters
identifier[in] the identifier of the property
defval[in] the value that will be returned if property with identifier is not found.
Returns
the value of the property if it exists, else defval is returned

◆ getName()

const std::string& getName ( ) const
inline

get the name of this propertymap

Returns
name of this propertymap

◆ getProperties()

Range getProperties ( ) const

Range of all PropertyBase* objects stored.

Note that this low-level interface does permits the PropertyBase values to be modified even though the method itself is declared const.

◆ getPtr() [1/2]

T* getPtr ( const std::string &  identifier)
inline

Get the value of a property or NULL if no such property.

If a property of the given identifier and type cannot be found, the method returns NULL.

Parameters
identifier[in] the identifier of the property
Returns
the value of the property

◆ getPtr() [2/2]

const T* getPtr ( const std::string &  identifier) const
inline

Get the value of a property or NULL if no such property.

If a property of the given identifier and type cannot be found, the method returns NULL.

Parameters
identifier[in] the identifier of the property
Returns
the value of the property

◆ has()

bool has ( const std::string &  identifier) const

True if a specific property exists.

Parameters
identifier[in] The identifier of the property
Returns
true if the property exists

◆ propertyChangedListener()

void propertyChangedListener ( rw::core::PropertyBase base)

used for listening for property changes in the map

Parameters
base

◆ set()

rw::core::Ptr<rw::core::Property<T> > set ( const std::string &  identifier,
const T &  value 
)
inline

Set the value of a property.

If a property with the given identifier cannot be found, a new property with no description is created and inserted.

This will fire a PropertyChangedEvent.

Parameters
identifier[in] the property identifier
value[in] the new value

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