SOFA API  59c939c2
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(size_t i = 0; i < dim; ++i) {
// [...] Do something with 'value'
}
}

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 size_t size ()
 
static size_t byteSize ()
 
static size_t size (const DataType &)
 
template<typename T >
static void getValue (const DataType &, size_t, T &)
 
static bool setSize (DataType &, size_t)
 
template<typename T >
static void setValue (DataType &, size_t, const T &)
 
static void getValueString (const DataType &, size_t, std::string &)
 
static void setValueString (DataType &, size_t, const std::string &)
 
static const void * getValuePtr (const DataType &)
 
static void * getValuePtr (DataType &)
 
static const char * name ()