API
4.0
For C++ developers
|
A property table is the container that an OpenSim Object uses to hold its properties (each derived from base class AbstractProperty). More...
Public Member Functions | |
PropertyTable () | |
Create an empty table. More... | |
~PropertyTable () | |
The destructor deletes all the property object in this table; any existing references to them or to their values become invalid. More... | |
PropertyTable (const PropertyTable &source) | |
Copy constructor performs a deep copy; that is, this table contains new property objects initialized from those in the source. More... | |
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. More... | |
void | clear () |
Delete all the properties currently in this table, restoring the table to its default-constructed state. More... | |
bool | equals (const PropertyTable &other) const |
Compare this table to another one for equality. More... | |
bool | operator== (const PropertyTable &other) const |
See equals() for the meaning of this operator. More... | |
int | adoptProperty (AbstractProperty *prop) |
Add a new property to this table, taking over ownership of the supplied heap-allocated property. More... | |
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. More... | |
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). More... | |
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. More... | |
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). More... | |
bool | hasProperty (const std::string &name) const |
Return true if there is a property with the given name currently stored in this table. More... | |
const AbstractProperty * | getPropertyPtr (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. More... | |
AbstractProperty * | updPropertyPtr (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. More... | |
int | getNumProperties () const |
Return the number of properties currently in this table. More... | |
const AbstractProperty & | getAbstractPropertyByIndex (int index) const |
Retrieve a property by its index, which must be in the range 0..getNumProperties()-1. More... | |
AbstractProperty & | updAbstractPropertyByIndex (int index) |
Retrieve a writable reference to a property by its index, which must be in the range 0..getNumProperties()-1. More... | |
const AbstractProperty & | getAbstractPropertyByName (const std::string &name) const |
Retrieve a property by name if it exists, otherwise throw an exception. More... | |
AbstractProperty & | updAbstractPropertyByName (const std::string &name) |
Retrieve a writable reference to a property by name if it exists, otherwise throw an exception. More... | |
int | findPropertyIndex (const std::string &name) const |
Return the property's index if it is present, else -1. More... | |
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.
|
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.
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.
Referenced by getProperty().
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.
Referenced by getProperty().
|
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.
|
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.
References getAbstractPropertyByName(), and OpenSim::Property< T >::getAs().
|
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.
References getAbstractPropertyByIndex(), and OpenSim::Property< T >::getAs().
|
inline |
Look up a property by name and return a pointer providing const access to the stored AbstractProperty object if present, otherwise null.
|
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.
|
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.
Referenced by updProperty().
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.
Referenced by updProperty().
|
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.
References updAbstractPropertyByName(), and OpenSim::Property< T >::updAs().
|
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.
References updAbstractPropertyByIndex(), and OpenSim::Property< T >::updAs().
|
inline |
Look up a property by name and return a pointer providing writable access to the stored AbstractProperty object if present, otherwise null.