Developer Documentation
|
The properties storage class. More...
#include <ObjectTypes/Skeleton/Properties.hh>
Classes | |
class | BaseProperty |
The base class for all property template instances. More... | |
class | PropertyT |
A container storing a single property for all objects. More... | |
Public Member Functions | |
Property management | |
Use these to edit the properties themself, not their values. | |
template<typename T > | |
bool | add_property (PropertyHandleT< T > &_hProp, std::string _name) |
Adds a new property. More... | |
template<typename T > | |
bool | get_property (PropertyHandleT< T > &_hProp, std::string _name) |
Initiates the property handle. More... | |
bool | has_property (std::string _name) |
Returns true if a property with the given name exists. More... | |
template<typename T > | |
bool | remove_property (PropertyHandleT< T > &_hProp) |
Deletes a property including all values. More... | |
void | clear_properties () |
Deletes all properties, including their values. More... | |
Property access | |
Edit the properties values. | |
template<typename T > | |
T & | property (PropertyHandleT< T > &_hProp, int _index) |
Direct access to the properties values. More... | |
Protected Member Functions | |
Synchronization | |
Call these methods to keep the property indices in sync with the objects they are bound to. | |
void | insert_property_at (int _index) |
Inserts a property for a new object at the given index. More... | |
void | remove_property_at (int _index) |
Removes a property for an object that is being deleted from the derived class. More... | |
void | clean_properties () |
While preserving the properties themself, all values in the property are deleted. More... | |
Protected Attributes | |
std::map< std::string, int > | property_names_ |
The property names, key holding the name, value the properties index in Properties::properties_. | |
std::vector< BaseProperty * > | properties_ |
A vector holding the properties. More... | |
unsigned long | size_ |
The number of fields in each property, used when new properties have to be created. | |
The properties storage class.
This class is equipped with all methods you need to access the properties. Derive your class from it, then call the Properties::insert_property_at and Properties::remove_property_at members, whenever the vector holding the objects this property class refers to changes. The properties are bound to objects by their integer based index.
Definition at line 100 of file Properties.hh.
bool Properties::add_property | ( | PropertyHandleT< T > & | _hProp, |
std::string | _name | ||
) |
Adds a new property.
Give the property type as template parameter of the property handle. Assign a unique name to the property, to be able to access it later. The property is created an the property handle is updated. After this call it is directly ready for use. Returns false if a property with this name already exists. In that case the property handle will point to that property.
_hProp | A new unused property handle. When the method returns it will always point to a property. |
_name | The properties name, has to be unique. |
Definition at line 72 of file PropertiesT.cc.
|
protected |
While preserving the properties themself, all values in the property are deleted.
This method preserves the properties, the property handles remain valid. Call this method if all objects in the derived class are deleted, so there is no object left that has properties attached to it. Notice the difference to Properties::clear_properties.
Definition at line 79 of file Properties.cc.
void Properties::clear_properties | ( | ) |
Deletes all properties, including their values.
Notice the difference to Properties::clean_properties, which preserves the properties and only deletes the values inside them.
Definition at line 93 of file Properties.cc.
bool Properties::get_property | ( | PropertyHandleT< T > & | _hProp, |
std::string | _name | ||
) |
Initiates the property handle.
If this call is successful and there is a property with the given name, the property handle will point to it. If not, this method returns false.
_hProp | A new, unused property handle |
_name | The properties name |
Definition at line 113 of file PropertiesT.cc.
bool Properties::has_property | ( | std::string | _name | ) |
Returns true if a property with the given name exists.
_name | The properties name |
Definition at line 145 of file Properties.cc.
|
protected |
Inserts a property for a new object at the given index.
If the derived class inserts a new object at the given index, the properties have to insert a new property, to keep it in sync. This is done by calling this method. To append at the end simply give the size of the vector holding the objects as parameter.
_index | Index of the new object, all the property indices for objects with index >= _index are increased by one |
Definition at line 113 of file Properties.cc.
T & Properties::property | ( | PropertyHandleT< T > & | _hProp, |
int | _index | ||
) |
Direct access to the properties values.
Access the property by using the same index as you use for the corresponding object in the derived class. This method returns a reference to the type given by the property handle. Make sure you use the right template parameter, otherwise the result is undefined (most likely a zero-reference).
_hProp | A valid handle to a property |
_index | The index of the property, corresponds to the index of the object in the derived class this property refers to |
Definition at line 178 of file PropertiesT.cc.
bool Properties::remove_property | ( | PropertyHandleT< T > & | _hProp | ) |
Deletes a property including all values.
Call this method to remove the property identified by the handle.
_hProp | A valid property handle pointing to a property |
Definition at line 137 of file PropertiesT.cc.
|
protected |
Removes a property for an object that is being deleted from the derived class.
The same as for Properties::insert_property_at, just the other way around.
_index | Index of the new object, all the property indices for objects with index >= _index are decremented by one |
Definition at line 130 of file Properties.cc.
|
protected |
A vector holding the properties.
Access them using a property handle, that in turn is storing a index derived from Properties::property_names_. If a property is deleted its position in the vector is deleted and set to zero. If a new property is added it will either take a place in the vector that is zero or append itself to the end. This way the property handles stay valid all the time.
Definition at line 199 of file Properties.hh.