API  4.3
For MATLAB, Python, Java, and C++ users
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...

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...
 
PropertyTableoperator= (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 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. More...
 
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. More...
 
int getNumProperties () const
 Return the number of properties currently in this table. More...
 
const AbstractPropertygetAbstractPropertyByIndex (int index) const
 Retrieve a property by its index, which must be in the range 0..getNumProperties()-1. More...
 
AbstractPropertyupdAbstractPropertyByIndex (int index)
 Retrieve a writable reference to a property by its index, which must be in the range 0..getNumProperties()-1. More...
 
const AbstractPropertygetAbstractPropertyByName (const std::string &name) const
 Retrieve a property by name if it exists, otherwise throw an exception. More...
 
AbstractPropertyupdAbstractPropertyByName (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...
 

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

◆ PropertyTable() [1/2]

OpenSim::PropertyTable::PropertyTable ( )
inline

Create an empty table.

◆ ~PropertyTable()

OpenSim::PropertyTable::~PropertyTable ( )

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

◆ PropertyTable() [2/2]

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

◆ adoptProperty()

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.

◆ clear()

void OpenSim::PropertyTable::clear ( )

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

◆ equals()

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.

◆ findPropertyIndex()

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

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

◆ getAbstractPropertyByIndex()

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().

◆ getAbstractPropertyByName()

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().

◆ getNumProperties()

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.

◆ getProperty() [1/2]

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.

References getAbstractPropertyByName(), and OpenSim::Property< T >::getAs().

◆ getProperty() [2/2]

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.

References getAbstractPropertyByIndex(), and OpenSim::Property< T >::getAs().

◆ getPropertyPtr()

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.

◆ hasProperty()

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.

◆ operator=()

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.

◆ operator==()

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

See equals() for the meaning of this operator.

◆ updAbstractPropertyByIndex()

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().

◆ updAbstractPropertyByName()

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().

◆ updProperty() [1/2]

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.

References updAbstractPropertyByName(), and OpenSim::Property< T >::updAs().

◆ updProperty() [2/2]

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.

References updAbstractPropertyByIndex(), and OpenSim::Property< T >::updAs().

◆ updPropertyPtr()

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: