SOFA API  1a4bb3e7
Open source framework for multi-physics simuation
sofa::defaulttype::DataTypeInfo< TDataType > Struct Template Reference

#include <DataTypeInfo.h>

Inheritance diagram for sofa::defaulttype::DataTypeInfo< TDataType >:

Detailed Description

template<class TDataType>
struct sofa::defaulttype::DataTypeInfo< TDataType >

Type traits class for objects stored in Data.

DataTypeInfo is part of the introspection/reflection capabilities of the Sofa scene graph API; it is used to manipulate Data values generically in template code, working transparently with different types of containers (vector, fixed_array, etc), and different types of values (integers, scalars (float, double), strings, etc). For example, it can be used to work with arrays without having to handle all the possible array classes used in Sofa: fixed or dynamic size, CPU or GPU, etc.

Small example

Iterate over the values of a DataType in templated code:

template<DataType>
MyComponent::someMethod(DataType& data) {
for(sofa::Size i = 0; i < dim; ++i) {
// [...] Do something with 'value'
}
}
SReal SReal SReal SReal int SReal int dim
Definition: LCPcalc.h:100
TDataType DataType
Template parameter.
Definition: DataTypeInfo.h:77
DataType ValueType
Type of the final atomic values (i.e. the values indexed by getValue()).
Definition: DataTypeInfo.h:82
static sofa::Size size()
Definition: DataTypeInfo.h:104
static void getValue(const DataType &, Index, T &)
Definition: DataTypeInfo.h:110

Note about size and indices

The getValue() and setValue() methods take an index as a parameter, with the following conventions:

  • If a type is not a container, then the index must be 0.
  • Multi-dimensional containers are abstracted to a single dimension. This allows iterating over any container using a single index, at the price of some limitations.
See also
AbstractTypeInfo provides similar mechanisms to manipulate Data objects generically in non-template code.

Additional Inherited Members

- Static Public Member Functions inherited from sofa::defaulttype::DefaultDataTypeInfo< TDataType >
static sofa::Size size ()
 
static sofa::Size byteSize ()
 
static sofa::Size size (const DataType &)
 
template<typename T >
static void getValue (const DataType &, Index, T &)
 
static bool setSize (DataType &, sofa::Size)
 
template<typename T >
static void setValue (DataType &, Index, const T &)
 
static void getValueString (const DataType &, Index, std::string &)
 
static void setValueString (DataType &, Index, const std::string &)
 
static const void * getValuePtr (const DataType &)
 
static void * getValuePtr (DataType &)
 
static const std::string name ()
 
static const std::string GetTypeName ()