Developer Documentation
Properties Class Reference

The properties storage class. More...

#include <Type-Skeleton/ObjectTypes/Skeleton/Properties.hh>

Inheritance diagram for Properties:
SkeletonT< PointT >

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.
 

Detailed Description

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 92 of file Properties.hh.

Member Function Documentation

◆ add_property()

template<typename T >
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.

Parameters
_hPropA new unused property handle. When the method returns it will always point to a property.
_nameThe properties name, has to be unique.
Returns
true if a new property was created, false if an existing is returned.

Definition at line 66 of file PropertiesT_impl.hh.

◆ clean_properties()

void Properties::clean_properties ( )
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 71 of file Properties.cc.

◆ clear_properties()

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 85 of file Properties.cc.

◆ get_property()

template<typename T >
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.

Parameters
_hPropA new, unused property handle
_nameThe properties name
Returns
true if the property exists and _hProp is now valid, false otherwise

Definition at line 107 of file PropertiesT_impl.hh.

◆ has_property()

bool Properties::has_property ( std::string  _name)

Returns true if a property with the given name exists.

Parameters
_nameThe properties name
Returns
true if the property exists, false otherwise

Definition at line 137 of file Properties.cc.

◆ insert_property_at()

void Properties::insert_property_at ( int  _index)
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.

Parameters
_indexIndex of the new object, all the property indices for objects with index >= _index are increased by one

Definition at line 105 of file Properties.cc.

◆ property()

template<typename T >
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).

Parameters
_hPropA valid handle to a property
_indexThe index of the property, corresponds to the index of the object in the derived class this property refers to

Definition at line 172 of file PropertiesT_impl.hh.

◆ remove_property()

template<typename T >
bool Properties::remove_property ( PropertyHandleT< T > &  _hProp)

Deletes a property including all values.

Call this method to remove the property identified by the handle.

Parameters
_hPropA valid property handle pointing to a property
Returns
true if the handle was valid and a property was deleted, false otherwise

Definition at line 131 of file PropertiesT_impl.hh.

◆ remove_property_at()

void Properties::remove_property_at ( int  _index)
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.

Parameters
_indexIndex of the new object, all the property indices for objects with index >= _index are decremented by one

Definition at line 122 of file Properties.cc.

Member Data Documentation

◆ properties_

Properties::properties_
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 191 of file Properties.hh.


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