API  4.5.1
For C++ developers
OpenSim::AbstractDataTable Class Referenceabstract

AbstractDataTable is the base-class of all DataTable_(templated) allowing storage of DataTable_ templated on different types to be stored in a container like std::vector. More...

+ Inheritance diagram for OpenSim::AbstractDataTable:

Public Member Functions

 AbstractDataTable ()=default
 
 AbstractDataTable (const AbstractDataTable &)=default
 
 AbstractDataTable (AbstractDataTable &&)=default
 
AbstractDataTableoperator= (const AbstractDataTable &)=default
 
AbstractDataTableoperator= (AbstractDataTable &&)=default
 
virtual std::shared_ptr< AbstractDataTableclone () const =0
 
virtual ~AbstractDataTable ()=default
 
virtual unsigned numComponentsPerElement () const =0
 Get number of components per element of the DataTable. More...
 
size_t getNumRows () const
 Get number of rows. More...
 
size_t getNumColumns () const
 Get number of dependent columns. More...
 
bool hasColumn (const size_t columnIndex) const
 Check if the table has a column with the given index. More...
 
MetaData accessors/mutators.
template<typename Value >
void addTableMetaData (const std::string &key, const Value &value)
 Add key-value pair to the table metadata. More...
 
bool hasTableMetaDataKey (const std::string &key) const
 Whether or not table metadata for the given key exists. More...
 
template<typename Value >
Value getTableMetaData (const std::string &key) const
 Get table metadata for a given key. More...
 
std::string getTableMetaDataAsString (const std::string &key) const
 Get table metadata for a given key as a string. More...
 
void removeTableMetaDataKey (const std::string &key)
 Remove key-value pair associated with the given key from table metadata. More...
 
std::vector< std::string > getTableMetaDataKeys () const
 Get table metadata keys. More...
 
const TableMetaDatagetTableMetaData () const
 Get metadata associated with the table. More...
 
TableMetaDataupdTableMetaData ()
 Update metadata associated with the table. More...
 
const IndependentMetaDatagetIndependentMetaData () const
 Get metadata associated with the independent column. More...
 
void setIndependentMetaData (const IndependentMetaData &independentMetaData)
 Set metadata associated with the independent column. More...
 
const DependentsMetaDatagetDependentsMetaData () const
 Get metadata associated with the dependent columns. More...
 
void setDependentsMetaData (const DependentsMetaData &dependentsMetaData)
 Set metadata associated with the dependent columns. More...
 
void removeDependentsMetaDataForKey (const std::string &key)
 Remove key-value pair associated with the given key from dependents metadata. More...
 
Column-labels related accessors/mutators.

Following functions operate on column labels of dependent columns only excluding the independent column.

Following are examples on using setColumnLabels(). If you have a sequence of strings, you can pretty much call setColumnLabels() on it.

// Simplest way to set column labels is to provide them directly to
// setColumnLabels.
table.setColumnLabels({"col1", "col2", "col3"});
// if you have a sequence container like std::vector or std::list of
// std::string holding column labels, pass the container directly to
// setColumnLabels.
std::list<std::string> columnLabels{"col1", "col2", "col3"};
table.setColumnLabels(columnLabels);
// If you have a sequence container like std::vector or std::list of
// std::string holding column labels but you want to use only a subset
// of them to set column labels of the table, use iterators like below.
std::vector<std::string> columnLabels{"col-not-used1",
"col1", "col2", "col3",
"col-not-used2"};
table.setColumnLabels(columnLabels.begin() + 1,
columnLabels.end() - 1);
bool hasColumnLabels () const
 Does the table have non-zero number of column labels. More...
 
std::vector< std::string > getColumnLabels () const
 Get column labels. More...
 
const std::string & getColumnLabel (const size_t columnIndex) const
 Get column label of a given column. More...
 
template<typename InputIt >
void setColumnLabels (InputIt first, InputIt last)
 Set column labels using a pair of iterators. More...
 
template<typename Container >
void setColumnLabels (const Container &columnLabels)
 Set column labels using a sequence container. More...
 
void setColumnLabels (const std::initializer_list< std::string > &columnLabels)
 Set column labels using a std::initializer_list. More...
 
void setColumnLabel (const size_t columnIndex, const std::string &columnLabel)
 Set the label for a column. More...
 
size_t getColumnIndex (const std::string &columnLabel) const
 Get index of a column label. More...
 
bool hasColumn (const std::string &columnLabel) const
 Check if the table has a column with the given label. More...
 

Public Types

typedef ValueArrayDictionary TableMetaData
 
typedef ValueArrayDictionary DependentsMetaData
 
typedef ValueArrayDictionary IndependentMetaData
 

Protected Member Functions

void appendColumnLabel (const std::string &columnLabel)
 Append column-label. More...
 
virtual size_t implementGetNumRows () const =0
 Get number of rows. More...
 
virtual size_t implementGetNumColumns () const =0
 Get number of columns. More...
 
virtual void validateIndependentMetaData () const =0
 Check if metadata for independent column is valid. More...
 
virtual void validateDependentsMetaData () const =0
 Check if metadata for dependent column is valid. More...
 

Protected Attributes

TableMetaData _tableMetaData
 
DependentsMetaData _dependentsMetaData
 
IndependentMetaData _independentMetaData
 

Detailed Description

AbstractDataTable is the base-class of all DataTable_(templated) allowing storage of DataTable_ templated on different types to be stored in a container like std::vector.

DataTable_ represents a matrix and an additional column. The columns of the matrix are dependent columns. The additional column is the independent column. All dependent columns and the independent column can have metadata. AbstractDataTable offers:

  • Interface to access metadata of independent column and dependent columns.
  • A heterogeneous container to store metadata associated with the DataTable_ in the form of key-value pairs where key is of type std::string and value can be of any type.

This class is abstract and cannot be used directly. Create instances of DataTable_ instead. See DataTable_ for details on usage.

Member Typedef Documentation

◆ DependentsMetaData

◆ IndependentMetaData

◆ TableMetaData

Constructor & Destructor Documentation

◆ AbstractDataTable() [1/3]

OpenSim::AbstractDataTable::AbstractDataTable ( )
default

◆ AbstractDataTable() [2/3]

OpenSim::AbstractDataTable::AbstractDataTable ( const AbstractDataTable )
default

◆ AbstractDataTable() [3/3]

OpenSim::AbstractDataTable::AbstractDataTable ( AbstractDataTable &&  )
default

◆ ~AbstractDataTable()

virtual OpenSim::AbstractDataTable::~AbstractDataTable ( )
virtualdefault

Member Function Documentation

◆ addTableMetaData()

template<typename Value >
void OpenSim::AbstractDataTable::addTableMetaData ( const std::string &  key,
const Value &  value 
)
inline

Add key-value pair to the table metadata.

If using this function from Python/Java/Matlab, use:

addTableMetaDataString(key, value)

where both 'key' and 'value' are strings. The above call translates to C++ as:

addTableMetaData<std::string>(key, value)
Template Parameters
ValueType of the value. This need not be specified explicitly in most cases. It will be deduced automatically.
Exceptions
KeyExistsIf the key provided already exists in table metadata.
Examples:
exampleTracking.cpp.

◆ appendColumnLabel()

void OpenSim::AbstractDataTable::appendColumnLabel ( const std::string &  columnLabel)
protected

◆ clone()

◆ getColumnIndex()

size_t OpenSim::AbstractDataTable::getColumnIndex ( const std::string &  columnLabel) const

Get index of a column label.

Exceptions
NoColumnLabelsIf table has no column labels.
KeyNotFoundIf columnLabel is not found to be label for any column.

Referenced by OpenSim::TableSource_< ET >::getColumnAtTime(), OpenSim::DataTable_< double, SimTK::Real >::getDependentColumn(), and OpenSim::DataTable_< double, SimTK::Real >::updDependentColumn().

◆ getColumnLabel()

const std::string& OpenSim::AbstractDataTable::getColumnLabel ( const size_t  columnIndex) const

Get column label of a given column.

Exceptions
ColumnIndexOutOfRangeIf columnIndex is out of range of number of columns.
NoColumnLabelsIf column labels have not be set for the table.

◆ getColumnLabels()

◆ getDependentsMetaData()

const DependentsMetaData& OpenSim::AbstractDataTable::getDependentsMetaData ( ) const

Get metadata associated with the dependent columns.

◆ getIndependentMetaData()

const IndependentMetaData& OpenSim::AbstractDataTable::getIndependentMetaData ( ) const

Get metadata associated with the independent column.

◆ getNumColumns()

◆ getNumRows()

◆ getTableMetaData() [1/2]

template<typename Value >
Value OpenSim::AbstractDataTable::getTableMetaData ( const std::string &  key) const
inline

Get table metadata for a given key.

If using this function from Python/Java/Matlab, use the following table:

C++ Python / Java / Matlab Example
getTableMetaData<std::string> getTableMetaDataString Marker table read from a C3D file could contain quantities DataRate and Units that can be retrieved with this method.
getTableMetaData<std::vector<SimTK::Matrix_<double>>> getTableMetaDataVectorMatrix Forces table read from a C3D file could contain quantities Calibration Matrices, Force Plate Corners and Force Plate Origins that can be retrieved with this method.
getTableMetaData<std::vector<unsigned>> getTableMetaDataVectorUnsigned Forces table read from a C3D file could contain quantity Force Plate Types that can be retrieved with this method
Template Parameters
ValueType of the value to be retrieved. For example if the metadata contains key-value pair ("sample-rate", 200), this could be specified as 'unsigned'.
Exceptions
KeyNotFoundIf the key provided is not found in table metadata.

◆ getTableMetaData() [2/2]

const TableMetaData& OpenSim::AbstractDataTable::getTableMetaData ( ) const

Get metadata associated with the table.

◆ getTableMetaDataAsString()

std::string OpenSim::AbstractDataTable::getTableMetaDataAsString ( const std::string &  key) const
inline

Get table metadata for a given key as a string.

Exceptions
KeyNotFoundIf the key provided is not found in table metadata.

◆ getTableMetaDataKeys()

std::vector<std::string> OpenSim::AbstractDataTable::getTableMetaDataKeys ( ) const

Get table metadata keys.

◆ hasColumn() [1/2]

bool OpenSim::AbstractDataTable::hasColumn ( const std::string &  columnLabel) const

Check if the table has a column with the given label.

Exceptions
NoColumnLabelsIf table has no column labels.

Referenced by OpenSim::DataTable_< double, SimTK::Real >::appendColumn().

◆ hasColumn() [2/2]

bool OpenSim::AbstractDataTable::hasColumn ( const size_t  columnIndex) const

Check if the table has a column with the given index.

◆ hasColumnLabels()

bool OpenSim::AbstractDataTable::hasColumnLabels ( ) const

Does the table have non-zero number of column labels.

Referenced by OpenSim::TableReporter_< InputT, ValueT >::clearTable().

◆ hasTableMetaDataKey()

bool OpenSim::AbstractDataTable::hasTableMetaDataKey ( const std::string &  key) const
inline

Whether or not table metadata for the given key exists.

◆ implementGetNumColumns()

◆ implementGetNumRows()

◆ numComponentsPerElement()

virtual unsigned OpenSim::AbstractDataTable::numComponentsPerElement ( ) const
pure virtual

◆ operator=() [1/2]

AbstractDataTable& OpenSim::AbstractDataTable::operator= ( const AbstractDataTable )
default

◆ operator=() [2/2]

AbstractDataTable& OpenSim::AbstractDataTable::operator= ( AbstractDataTable &&  )
default

◆ removeDependentsMetaDataForKey()

void OpenSim::AbstractDataTable::removeDependentsMetaDataForKey ( const std::string &  key)

Remove key-value pair associated with the given key from dependents metadata.

Referenced by OpenSim::TimeSeriesTable_< SimTK::Vec3 >::TimeSeriesTable_().

◆ removeTableMetaDataKey()

void OpenSim::AbstractDataTable::removeTableMetaDataKey ( const std::string &  key)

Remove key-value pair associated with the given key from table metadata.

◆ setColumnLabel()

void OpenSim::AbstractDataTable::setColumnLabel ( const size_t  columnIndex,
const std::string &  columnLabel 
)

Set the label for a column.

Exceptions
NoColumnLabelsIf table has no column labels.
ColumnIndexOutOfRangeIf columnIndex is out of range for number of columns in the table.

◆ setColumnLabels() [1/3]

template<typename InputIt >
void OpenSim::AbstractDataTable::setColumnLabels ( InputIt  first,
InputIt  last 
)
inline

Set column labels using a pair of iterators.

Example:

std::vector<std::string> labels{"col1", "col2", "col3", "col4", "col5"};
// Use subsequence of vector as labels.
setColumnLabels(labels.begin() + 2, labels.end());
Parameters
firstInputIterator representing the beginning of the sequence of labels.
lastInputIterator representing the sentinel or one past the end of sequence of labels.
Exceptions
IncorrectMetaDataLengthIf length of the input sequence of labels is incorrect – does not match the number of columns in the table.
Examples:
exampleMarkerTracking.cpp.

References OpenSim::ValueArray< T >::upd().

Referenced by OpenSim::TableReporter_< InputT, ValueT >::clearTable(), OpenSim::DataTable_< double, SimTK::Real >::DataTable_(), OpenSim::TableReporter_< InputT, ValueT >::extendFinalizeConnections(), OpenSim::TabOpUseAbsoluteStateNames::operate(), and OpenSim::DataTable_< double, SimTK::Real >::removeColumnAtIndex().

◆ setColumnLabels() [2/3]

template<typename Container >
void OpenSim::AbstractDataTable::setColumnLabels ( const Container &  columnLabels)
inline

Set column labels using a sequence container.

Example:

std::vector<std::string> columnLabels{"col1", "col2", "col3"};
setColumnLabels(columnLabels);
Template Parameters
ContainerAny container type (like std::vector, std::list or your own) that supports begin() and end(). Type of the values produced by iterator should be std::string.
Exceptions
IncorrectMetaDataLengthIf length of the input sequence of labels is incorrect – does not match the number of columns in the table.

◆ setColumnLabels() [3/3]

void OpenSim::AbstractDataTable::setColumnLabels ( const std::initializer_list< std::string > &  columnLabels)

Set column labels using a std::initializer_list.

Example:

setColumnLabels({"col1", "col2", "col3"});


Exceptions
IncorrectMetaDataLengthIf length of the input sequence of labels is incorrect – does not match the number of columns in the table.

◆ setDependentsMetaData()

void OpenSim::AbstractDataTable::setDependentsMetaData ( const DependentsMetaData dependentsMetaData)

Set metadata associated with the dependent columns.

◆ setIndependentMetaData()

void OpenSim::AbstractDataTable::setIndependentMetaData ( const IndependentMetaData independentMetaData)

Set metadata associated with the independent column.

◆ updTableMetaData()

TableMetaData& OpenSim::AbstractDataTable::updTableMetaData ( )

Update metadata associated with the table.

◆ validateDependentsMetaData()

virtual void OpenSim::AbstractDataTable::validateDependentsMetaData ( ) const
protectedpure virtual

◆ validateIndependentMetaData()

virtual void OpenSim::AbstractDataTable::validateIndependentMetaData ( ) const
protectedpure virtual

Member Data Documentation

◆ _dependentsMetaData

◆ _independentMetaData

IndependentMetaData OpenSim::AbstractDataTable::_independentMetaData
protected

◆ _tableMetaData

TableMetaData OpenSim::AbstractDataTable::_tableMetaData
protected

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