OpenSim  OpenSim 3.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
OpenSim::PropertyTable Class Reference

A property table is the container that an OpenSim Object uses to hold its properties (each derived from base class AbstractProperty). More...

#include <PropertyTable.h>

Public Member Functions

 PropertyTable ()
 Create an empty table.
 ~PropertyTable ()
 The destructor deletes all the property object in this table; any existing references to them or to their values become invalid.
 PropertyTable (const PropertyTable &source)
 Copy constructor performs a deep copy; that is, this table contains new property objects initialized from those in the source.
PropertyTableoperator= (const PropertyTable &source)
 Copy assignment performs a deep copy; this table will be as though it had been copy constructed from the source.
void clear ()
 Delete all the properties currently in this table, restoring the table to its default-constructed state.
bool equals (const PropertyTable &other) const
 Compare this table to another one for equality.
bool operator== (const PropertyTable &other) const
 See equals() for the meaning of this operator.
int adoptProperty (AbstractProperty *prop)
 Add a new property to this table, taking over ownership of the supplied heap-allocated property.
template<class T >
const Property< T > & getProperty (const std::string &name) const
 Return a const reference to a property of known type T from the table by name.
template<class T >
const Property< T > & getProperty (int index) const
 Return a const reference to a property of known type T from the table by its index (numbered in order of addition to the table).
template<class T >
Property< T > & updProperty (const std::string &name)
 Return a writable reference to a property of known type T from the table by name.
template<class T >
Property< T > & updProperty (int index)
 Return a writable reference to a property of known type T from the table by its index (numbered in order of addition to the table).
bool hasProperty (const std::string &name) const
 Return true if there is a property with the given name currently stored in this table.
const AbstractPropertygetPropertyPtr (const std::string &name) const
 Look up a property by name and return a pointer providing const access to the stored AbstractProperty object if present, otherwise null.
AbstractPropertyupdPropertyPtr (const std::string &name)
 Look up a property by name and return a pointer providing writable access to the stored AbstractProperty object if present, otherwise null.
int getNumProperties () const
 Return the number of properties currently in this table.
const AbstractPropertygetAbstractPropertyByIndex (int index) const
 Retrieve a property by its index, which must be in the range 0..getNumProperties()-1.
AbstractPropertyupdAbstractPropertyByIndex (int index)
 Retrieve a writable reference to a property by its index, which must be in the range 0..getNumProperties()-1.
const AbstractPropertygetAbstractPropertyByName (const std::string &name) const
 Retrieve a property by name if it exists, otherwise throw an exception.
AbstractPropertyupdAbstractPropertyByName (const std::string &name)
 Retrieve a writable reference to a property by name if it exists, otherwise throw an exception.
int findPropertyIndex (const std::string &name) const
 Return the property's index if it is present, else -1.

Detailed Description

A property table is the container that an OpenSim Object uses to hold its properties (each derived from base class AbstractProperty).

It provides methods to add properties to the table, and preserves the order with which they are defined. Methods for retrieving properties by name or by ordinal are provided. The table is the owner of the individual property objects and those are deleted when the table is deleted.

Duplicate property names are not allowed in the same property table. Some properties are unnamed, however; that is only allowed when the property holds a single object, and we use the object class name as though it were the property's name (and they can still be looked up by ordinal also). That means no Object can contain two unnamed properties holding the same type of object since that would appear as a duplicate name.

Author
Cassidy Kelly, Michael Sherman
See Also
AbstractProperty, Property, Object

Constructor & Destructor Documentation

OpenSim::PropertyTable::PropertyTable ( )
inline

Create an empty table.

OpenSim::PropertyTable::~PropertyTable ( )

The destructor deletes all the property object in this table; any existing references to them or to their values become invalid.

OpenSim::PropertyTable::PropertyTable ( const PropertyTable source)

Copy constructor performs a deep copy; that is, this table contains new property objects initialized from those in the source.

Member Function Documentation

int OpenSim::PropertyTable::adoptProperty ( AbstractProperty prop)

Add a new property to this table, taking over ownership of the supplied heap-allocated property.

Throws an exception if there is already a property with the same name in the table. Returns an index (ordinal) that can be used to retrieve this property quickly.

void OpenSim::PropertyTable::clear ( )

Delete all the properties currently in this table, restoring the table to its default-constructed state.

bool OpenSim::PropertyTable::equals ( const PropertyTable other) const

Compare this table to another one for equality.

Two tables are defined to be equal if they have the same number of properties, and each property tests equal to the one with the same index.

int OpenSim::PropertyTable::findPropertyIndex ( const std::string &  name) const

Return the property's index if it is present, else -1.

const AbstractProperty& OpenSim::PropertyTable::getAbstractPropertyByIndex ( int  index) const

Retrieve a property by its index, which must be in the range 0..getNumProperties()-1.

The property index is assigned in the order that the properties were added to this table.

const AbstractProperty& OpenSim::PropertyTable::getAbstractPropertyByName ( const std::string &  name) const

Retrieve a property by name if it exists, otherwise throw an exception.

The property is returned as an AbstractProperty; see getProperty<T>() if you know the property type.

int OpenSim::PropertyTable::getNumProperties ( ) const
inline

Return the number of properties currently in this table.

If this returns n, the properties are indexed 0 to n-1, in the order they were added to the table.

template<class T >
const Property< T > & OpenSim::PropertyTable::getProperty ( const std::string &  name) const
inline

Return a const reference to a property of known type T from the table by name.

This will throw an exception if no property with this name is present, or if the property is present but not of type T.

template<class T >
const Property< T > & OpenSim::PropertyTable::getProperty ( int  index) const
inline

Return a const reference to a property of known type T from the table by its index (numbered in order of addition to the table).

This will throw an exception if the index is out of range, or if the property is present but not of type T.

const AbstractProperty* OpenSim::PropertyTable::getPropertyPtr ( const std::string &  name) const
inline

Look up a property by name and return a pointer providing const access to the stored AbstractProperty object if present, otherwise null.

bool OpenSim::PropertyTable::hasProperty ( const std::string &  name) const
inline

Return true if there is a property with the given name currently stored in this table.

PropertyTable& OpenSim::PropertyTable::operator= ( const PropertyTable source)

Copy assignment performs a deep copy; this table will be as though it had been copy constructed from the source.

bool OpenSim::PropertyTable::operator== ( const PropertyTable other) const
inline

See equals() for the meaning of this operator.

AbstractProperty& OpenSim::PropertyTable::updAbstractPropertyByIndex ( int  index)

Retrieve a writable reference to a property by its index, which must be in the range 0..getNumProperties()-1.

The property index is assigned in the order that the properties were added to this table.

AbstractProperty& OpenSim::PropertyTable::updAbstractPropertyByName ( const std::string &  name)

Retrieve a writable reference to a property by name if it exists, otherwise throw an exception.

The property is returned as an AbstractProperty; see updProperty<T>() if you know the property type.

template<class T >
Property< T > & OpenSim::PropertyTable::updProperty ( const std::string &  name)
inline

Return a writable reference to a property of known type T from the table by name.

This will throw an exception if no property with this name is present, or if the property is present but not of type T.

template<class T >
Property< T > & OpenSim::PropertyTable::updProperty ( int  index)
inline

Return a writable reference to a property of known type T from the table by its index (numbered in order of addition to the table).

This will throw an exception if the index is out of range, or if the property is present but not of type T.

AbstractProperty* OpenSim::PropertyTable::updPropertyPtr ( const std::string &  name)
inline

Look up a property by name and return a pointer providing writable access to the stored AbstractProperty object if present, otherwise null.


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