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

#include <DataTypeInfo.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);

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 const AbstractTypeInfoBaseType () const =0
 
virtual const AbstractTypeInfoValueType () const =0
 
virtual std::string name () const =0
 Returns the name of this type. More...
 
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 size_t size () const =0
 
virtual size_t byteSize () const =0
 
virtual size_t size (const void *data) const =0
 
virtual bool setSize (void *data, size_t size) const =0
 Resize data to size elements, if relevant. More...
 
virtual long long getIntegerValue (const void *data, size_t index) const =0
 
virtual double getScalarValue (const void *data, size_t index) const =0
 
virtual std::string getTextValue (const void *data, size_t index) const =0
 Get the value at index of data as a string. More...
 
virtual void setIntegerValue (void *data, size_t index, long long value) const =0
 Set the value at index of data from an integer value. More...
 
virtual void setScalarValue (void *data, size_t index, double value) const =0
 Set the value at index of data from a scalar value. More...
 
virtual void setTextValue (void *data, size_t 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...
 

Protected Member Functions

 AbstractTypeInfo ()
 
virtual ~AbstractTypeInfo ()
 

Constructor details

sofa::defaulttype::AbstractTypeInfo::AbstractTypeInfo ( )
inlineprotected
virtual sofa::defaulttype::AbstractTypeInfo::~AbstractTypeInfo ( )
inlineprotectedvirtual

Function details

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::VirtualTypeInfo< TDataType >.

virtual size_t 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::VirtualTypeInfo< TDataType >.

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::VirtualTypeInfo< TDataType >.

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

True iff this type uses copy-on-write.

Implemented in sofa::defaulttype::VirtualTypeInfo< TDataType >.

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::VirtualTypeInfo< TDataType >.

virtual long long sofa::defaulttype::AbstractTypeInfo::getIntegerValue ( const void *  data,
size_t  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::VirtualTypeInfo< TDataType >.

virtual double sofa::defaulttype::AbstractTypeInfo::getScalarValue ( const void *  data,
size_t  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::VirtualTypeInfo< TDataType >.

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

Get the value at index of data as a string.

Implemented in sofa::defaulttype::VirtualTypeInfo< TDataType >.

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::VirtualTypeInfo< TDataType >.

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::VirtualTypeInfo< TDataType >.

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

True iff this type uses integer values.

Implemented in sofa::defaulttype::VirtualTypeInfo< TDataType >.

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

Returns the name of this type.

Implemented in sofa::defaulttype::VirtualTypeInfo< TDataType >.

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

True iff this type uses scalar values.

Implemented in sofa::defaulttype::VirtualTypeInfo< TDataType >.

virtual void sofa::defaulttype::AbstractTypeInfo::setIntegerValue ( void *  data,
size_t  index,
long long  value 
) const
pure virtual

Set the value at index of data from an integer value.

Implemented in sofa::defaulttype::VirtualTypeInfo< TDataType >.

virtual void sofa::defaulttype::AbstractTypeInfo::setScalarValue ( void *  data,
size_t  index,
double  value 
) const
pure virtual

Set the value at index of data from a scalar value.

Implemented in sofa::defaulttype::VirtualTypeInfo< TDataType >.

virtual bool sofa::defaulttype::AbstractTypeInfo::setSize ( void *  data,
size_t  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::VirtualTypeInfo< TDataType >.

virtual void sofa::defaulttype::AbstractTypeInfo::setTextValue ( void *  data,
size_t  index,
const std::string &  value 
) const
pure virtual

Set the value at index of data from a string value.

Implemented in sofa::defaulttype::VirtualTypeInfo< TDataType >.

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

True iff copying the data can be done with a memcpy().

Implemented in sofa::defaulttype::VirtualTypeInfo< TDataType >.

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::VirtualTypeInfo< TDataType >.

virtual size_t 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::VirtualTypeInfo< TDataType >.

virtual size_t 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::VirtualTypeInfo< TDataType >.

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

True iff this type uses text values.

Implemented in sofa::defaulttype::VirtualTypeInfo< TDataType >.

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

Get the type_info for this type.

Implemented in sofa::defaulttype::VirtualTypeInfo< TDataType >.

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::VirtualTypeInfo< TDataType >.

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::VirtualTypeInfo< TDataType >.

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::VirtualTypeInfo< TDataType >.