#include <AbstractTypeInfo.h>
Information about the type of a value stored in a Data.
AbstractTypeInfo is part of the introspection/reflection capabilities of the Sofa scene graph API. It provides information about the type of the content of Data objects (Is it a simple type? A container? How much memory should be allocated to copy it?), and allows manipulating Data generically, without knowing their exact type.
This class is primarily used to copy information accross BaseData objects, for example when there exists a link between two instances of BaseData. E.g. this mecanism allows you to copy the content of a Data<vector<int>> into a Data<vector<double>>, because there is an acceptable conversion between integer and double, and because both Data use a resizable container.
Use BaseData::getValueTypeInfo() to get a pointer to an AbtractTypeInfo, and BaseData::getValueVoidPtr() to get a pointer to the content of a Data. You can then use the methods of AbtractTypeInfo to access the Data generically.
Very basic example:
All the getValue() and setValue() methods take an index as a parameter, which means that every type is abstracted to a one-dimensional container. See the detailed description of DataTypeInfo for more explanations.
Public Member Functions | |
virtual | ~AbstractTypeInfo ()=default |
virtual const AbstractTypeInfo * | BaseType () const =0 |
virtual const AbstractTypeInfo * | ValueType () const =0 |
virtual std::string | name () const =0 |
Returns the name of this type. More... | |
virtual std::string | getTypeName () const =0 |
virtual bool | ValidInfo () const =0 |
virtual bool | FixedSize () const =0 |
virtual bool | ZeroConstructor () const =0 |
True iff the default constructor of this type is equivalent to setting the memory to 0. More... | |
virtual bool | SimpleCopy () const =0 |
True iff copying the data can be done with a memcpy(). More... | |
virtual bool | SimpleLayout () const =0 |
virtual bool | Integer () const =0 |
True iff this type uses integer values. More... | |
virtual bool | Scalar () const =0 |
True iff this type uses scalar values. More... | |
virtual bool | Text () const =0 |
True iff this type uses text values. More... | |
virtual bool | CopyOnWrite () const =0 |
True iff this type uses copy-on-write. More... | |
virtual bool | Container () const =0 |
virtual sofa::Size | size () const =0 |
virtual sofa::Size | byteSize () const =0 |
virtual sofa::Size | size (const void *data) const =0 |
virtual bool | setSize (void *data, sofa::Size size) const =0 |
Resize data to size elements, if relevant. More... | |
virtual long long | getIntegerValue (const void *data, Index index) const =0 |
virtual double | getScalarValue (const void *data, Index index) const =0 |
virtual std::string | getTextValue (const void *data, Index index) const =0 |
Get the value at index of data as a string. More... | |
virtual void | setIntegerValue (void *data, Index index, long long value) const =0 |
Set the value at index of data from an integer value. More... | |
virtual void | setScalarValue (void *data, Index index, double value) const =0 |
Set the value at index of data from a scalar value. More... | |
virtual void | setTextValue (void *data, Index index, const std::string &value) const =0 |
Set the value at index of data from a string value. More... | |
virtual const void * | getValuePtr (const void *type) const =0 |
virtual void * | getValuePtr (void *type) const =0 |
virtual const std::type_info * | type_info () const =0 |
Get the type_info for this type. More... | |
const std::string & | getCompilationTarget () const |
void | setCompilationTarget (const std::string &target) |
Protected Member Functions | |
AbstractTypeInfo () | |
virtual const TypeInfoId & | getBaseTypeId () const =0 |
virtual const TypeInfoId & | getValueTypeId () const =0 |
|
virtualdefault |
|
inlineprotected |
|
pure virtual |
If the type is a container, returns the TypeInfo for the type of the values inside this container. For example, if the type is fixed_array<fixed_array<int, 2> 3>
, it returns the TypeInfo for fixed_array<int, 2>
.
Implemented in sofa::defaulttype::NoTypeInfo, sofa::defaulttype::NameOnlyTypeInfo, and sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >.
|
pure virtual |
The size in bytes of the ValueType For example, the size of a fixed_array<fixed_array<int, 2>, 3>` is 4 on most systems, as it is the byte size of the smallest dimension in the array (int -> 32bit)
Implemented in sofa::defaulttype::NoTypeInfo, sofa::defaulttype::NameOnlyTypeInfo, and sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >.
|
pure virtual |
True iff this type is a container of some sort.
That is, if it can contain several values. In particular, strings are not considered containers.
Implemented in sofa::defaulttype::NoTypeInfo, sofa::defaulttype::NameOnlyTypeInfo, and sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >.
|
pure virtual |
True iff this type uses copy-on-write.
Implemented in sofa::defaulttype::NoTypeInfo, sofa::defaulttype::NameOnlyTypeInfo, and sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >.
|
pure virtual |
True iff this type has a fixed size. (It cannot be resized)
Implemented in sofa::defaulttype::NoTypeInfo, sofa::defaulttype::NameOnlyTypeInfo, and sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >.
|
protectedpure virtual |
|
inline |
|
pure virtual |
Get the value at index of data as an integer. Relevant only if this type can be casted to long long
.
Implemented in sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >, sofa::defaulttype::NoTypeInfo, and sofa::defaulttype::NameOnlyTypeInfo.
|
pure virtual |
Get the value at index of data as a scalar. Relevant only if this type can be casted to double
.
Implemented in sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >, sofa::defaulttype::NoTypeInfo, and sofa::defaulttype::NameOnlyTypeInfo.
|
pure virtual |
Get the value at index of data as a string.
Implemented in sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >, sofa::defaulttype::NoTypeInfo, and sofa::defaulttype::NameOnlyTypeInfo.
|
pure virtual |
|
pure virtual |
Get a read pointer to the underlying memory Relevant only if this type is SimpleLayout
Implemented in sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >, sofa::defaulttype::NoTypeInfo, and sofa::defaulttype::NameOnlyTypeInfo.
|
pure virtual |
Get a write pointer to the underlying memory Relevant only if this type is SimpleLayout
Implemented in sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >, sofa::defaulttype::NoTypeInfo, and sofa::defaulttype::NameOnlyTypeInfo.
|
protectedpure virtual |
|
pure virtual |
True iff this type uses integer values.
Implemented in sofa::defaulttype::NoTypeInfo, sofa::defaulttype::NameOnlyTypeInfo, and sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >.
|
pure virtual |
Returns the name of this type.
Implemented in sofa::defaulttype::NoTypeInfo, sofa::defaulttype::NameOnlyTypeInfo, and sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >.
|
pure virtual |
True iff this type uses scalar values.
Implemented in sofa::defaulttype::NoTypeInfo, sofa::defaulttype::NameOnlyTypeInfo, and sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >.
|
inline |
|
pure virtual |
Set the value at index of data from an integer value.
Implemented in sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >, sofa::defaulttype::NoTypeInfo, and sofa::defaulttype::NameOnlyTypeInfo.
|
pure virtual |
Set the value at index of data from a scalar value.
Implemented in sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >, sofa::defaulttype::NoTypeInfo, and sofa::defaulttype::NameOnlyTypeInfo.
|
pure virtual |
Resize data to size elements, if relevant.
But resizing is not always relevant, for example:
Returns true iff the data was resizable
Implemented in sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >, sofa::defaulttype::NoTypeInfo, and sofa::defaulttype::NameOnlyTypeInfo.
|
pure virtual |
Set the value at index of data from a string value.
Implemented in sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >, sofa::defaulttype::NoTypeInfo, and sofa::defaulttype::NameOnlyTypeInfo.
|
pure virtual |
True iff copying the data can be done with a memcpy().
Implemented in sofa::defaulttype::NoTypeInfo, sofa::defaulttype::NameOnlyTypeInfo, and sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >.
|
pure virtual |
True iff the layout in memory is simply N values of the same base type. It means that you can use the abstract index system to iterate over the elements of the type. (It doesn't mean that the BaseType is of a fixed size)
Implemented in sofa::defaulttype::NoTypeInfo, sofa::defaulttype::NameOnlyTypeInfo, and sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >.
|
pure virtual |
The size of this type, in number of elements. For example, the size of a fixed_array<fixed_array<int, 2>, 3>
is 6, and those six elements are conceptually numbered from 0 to 5. This is relevant only if FixedSize() is true. I FixedSize() is false, the return value will be equivalent to the one of byteSize()
Implemented in sofa::defaulttype::NoTypeInfo, sofa::defaulttype::NameOnlyTypeInfo, and sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >.
|
pure virtual |
The size of data, in number of iterable elements (For containers, that'll be the number of elements in the 1st dimension). For example, with type == `
Implemented in sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >, sofa::defaulttype::NoTypeInfo, and sofa::defaulttype::NameOnlyTypeInfo.
|
pure virtual |
True iff this type uses text values.
Implemented in sofa::defaulttype::NoTypeInfo, sofa::defaulttype::NameOnlyTypeInfo, and sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >.
|
pure virtual |
Get the type_info for this type.
Implemented in sofa::defaulttype::NoTypeInfo, sofa::defaulttype::NameOnlyTypeInfo, and sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >.
|
pure virtual |
True iff the TypeInfo for this type contains valid information. A Type is considered "Valid" if there's at least one specialization of the ValueType
Implemented in sofa::defaulttype::NoTypeInfo, sofa::defaulttype::NameOnlyTypeInfo, and sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >.
|
pure virtual |
Returns the TypeInfo for the type of the values accessible by the get*Value() functions. For example, if the type is fixed_array<fixed_array<int, 2> 3>
, it returns the TypeInfo for int
.
Implemented in sofa::defaulttype::NoTypeInfo, sofa::defaulttype::NameOnlyTypeInfo, and sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >.
|
pure virtual |
True iff the default constructor of this type is equivalent to setting the memory to 0.
Implemented in sofa::defaulttype::NoTypeInfo, sofa::defaulttype::NameOnlyTypeInfo, and sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >.