SOFA API  d36dcf8a
Open source framework for multi-physics simuation
sofa::defaulttype::AbstractTypeInfo Class Referenceabstract

#include <AbstractTypeInfo.h>

Inheritance diagram for sofa::defaulttype::AbstractTypeInfo:

Detailed Description

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.

Using TypeInfo

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:

BaseData *data = getADataFromSomewhere();
const AbstractTypeInfo *typeinfo = data->getValueTypeInfo();
const void* ptr = data->getValueVoidPtr();
for (int i = 0 ; i < typeinfo->size(ptr) ; i++)
std::string value = typeinfo->getTextValue(ptr, 0);
AbstractTypeInfo()
Definition: AbstractTypeInfo.h:177

Note about size and indices

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.

See also
DataTypeInfo provides similar mechanisms to manipulate Data objects generically in template code.

Public Member Functions

virtual ~AbstractTypeInfo ()=default
 
virtual const AbstractTypeInfoBaseType () const =0
 
virtual const AbstractTypeInfoValueType () 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 TypeInfoIdgetBaseTypeId () const =0
 
virtual const TypeInfoIdgetValueTypeId () const =0
 

Constructor details

◆ ~AbstractTypeInfo()

virtual sofa::defaulttype::AbstractTypeInfo::~AbstractTypeInfo ( )
virtualdefault

◆ AbstractTypeInfo()

sofa::defaulttype::AbstractTypeInfo::AbstractTypeInfo ( )
inlineprotected

Function details

◆ BaseType()

virtual const AbstractTypeInfo* sofa::defaulttype::AbstractTypeInfo::BaseType ( ) const
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 >.

◆ byteSize()

virtual sofa::Size sofa::defaulttype::AbstractTypeInfo::byteSize ( ) const
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 >.

◆ Container()

virtual bool sofa::defaulttype::AbstractTypeInfo::Container ( ) const
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 >.

◆ CopyOnWrite()

virtual bool sofa::defaulttype::AbstractTypeInfo::CopyOnWrite ( ) const
pure virtual

◆ FixedSize()

virtual bool sofa::defaulttype::AbstractTypeInfo::FixedSize ( ) const
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 >.

◆ getBaseTypeId()

virtual const TypeInfoId& sofa::defaulttype::AbstractTypeInfo::getBaseTypeId ( ) const
protectedpure virtual

◆ getCompilationTarget()

const std::string& sofa::defaulttype::AbstractTypeInfo::getCompilationTarget ( ) const
inline

◆ getIntegerValue()

virtual long long sofa::defaulttype::AbstractTypeInfo::getIntegerValue ( const void *  data,
Index  index 
) const
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.

◆ getScalarValue()

virtual double sofa::defaulttype::AbstractTypeInfo::getScalarValue ( const void *  data,
Index  index 
) const
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.

◆ getTextValue()

virtual std::string sofa::defaulttype::AbstractTypeInfo::getTextValue ( const void *  data,
Index  index 
) const
pure virtual

◆ getTypeName()

virtual std::string sofa::defaulttype::AbstractTypeInfo::getTypeName ( ) const
pure virtual

◆ getValuePtr() [1/2]

virtual const void* sofa::defaulttype::AbstractTypeInfo::getValuePtr ( const void *  type) const
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.

◆ getValuePtr() [2/2]

virtual void* sofa::defaulttype::AbstractTypeInfo::getValuePtr ( void *  type) const
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.

◆ getValueTypeId()

virtual const TypeInfoId& sofa::defaulttype::AbstractTypeInfo::getValueTypeId ( ) const
protectedpure virtual

◆ Integer()

virtual bool sofa::defaulttype::AbstractTypeInfo::Integer ( ) const
pure virtual

◆ name()

virtual std::string sofa::defaulttype::AbstractTypeInfo::name ( ) const
pure virtual

◆ Scalar()

virtual bool sofa::defaulttype::AbstractTypeInfo::Scalar ( ) const
pure virtual

◆ setCompilationTarget()

void sofa::defaulttype::AbstractTypeInfo::setCompilationTarget ( const std::string &  target)
inline

◆ setIntegerValue()

virtual void sofa::defaulttype::AbstractTypeInfo::setIntegerValue ( void *  data,
Index  index,
long long  value 
) const
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.

◆ setScalarValue()

virtual void sofa::defaulttype::AbstractTypeInfo::setScalarValue ( void *  data,
Index  index,
double  value 
) const
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.

◆ setSize()

virtual bool sofa::defaulttype::AbstractTypeInfo::setSize ( void *  data,
sofa::Size  size 
) const
pure virtual

Resize data to size elements, if relevant.

But resizing is not always relevant, for example:

  • nothing happens if FixedSize() is true;
  • sets can't be resized; they are cleared instead;
  • nothing happens for vectors containing resizable values (i.e. when BaseType()::FixedSize() is false), because of the "single index" abstraction;

Returns true iff the data was resizable

Implemented in sofa::defaulttype::DataTypeInfoDynamicWrapper< Info >, sofa::defaulttype::NoTypeInfo, and sofa::defaulttype::NameOnlyTypeInfo.

◆ setTextValue()

virtual void sofa::defaulttype::AbstractTypeInfo::setTextValue ( void *  data,
Index  index,
const std::string &  value 
) const
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.

◆ SimpleCopy()

virtual bool sofa::defaulttype::AbstractTypeInfo::SimpleCopy ( ) const
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 >.

◆ SimpleLayout()

virtual bool sofa::defaulttype::AbstractTypeInfo::SimpleLayout ( ) const
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 >.

◆ size() [1/2]

virtual sofa::Size sofa::defaulttype::AbstractTypeInfo::size ( ) const
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 >.

◆ size() [2/2]

virtual sofa::Size sofa::defaulttype::AbstractTypeInfo::size ( const void *  data) const
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.

◆ Text()

virtual bool sofa::defaulttype::AbstractTypeInfo::Text ( ) const
pure virtual

◆ type_info()

virtual const std::type_info* sofa::defaulttype::AbstractTypeInfo::type_info ( ) const
pure virtual

◆ ValidInfo()

virtual bool sofa::defaulttype::AbstractTypeInfo::ValidInfo ( ) const
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 >.

◆ ValueType()

virtual const AbstractTypeInfo* sofa::defaulttype::AbstractTypeInfo::ValueType ( ) const
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 >.

◆ ZeroConstructor()

virtual bool sofa::defaulttype::AbstractTypeInfo::ZeroConstructor ( ) const
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 >.