DataType Class Reference

#include <datatypebase.h>

Inheritance diagram for DataType:

Classes

class  Primary
 

Public Types

enum class  BASE_OF_MODE {
  NONE ,
  ORDERED_TYPE_ONLY ,
  UNORDERED_BY_NAME ,
  GENERIC_DOWNCAST
}
 
using Conversion = Delegate< Result< void >(const DataPtr &dest, const ConstDataPtr &src)>
 

Public Member Functions

 DataType ()=default
 
 DataType (const DataTypeImpl *ptr)
 
 DataType (std::nullptr_t)=delete
 
 operator Bool () const
 
Bool operator== (const DataType &other) const
 
Bool operator!= (const DataType &other) const
 
HashInt GetHashCode () const
 
UniqueHash GetUniqueHashCode () const
 
const DataTypeImploperator-> () const
 
const IdGetId () const
 
String ToString (const FormatStatement *formatStatement=nullptr) const
 
Int GetSize () const
 
Int GetAlignment () const
 
VALUEKIND GetValueKind () const
 
Bool CheckValueKind (VALUEKIND test) const
 
const DataTypeGetUnqualifiedType () const
 
const DataTypeResolveRecursiveType () const
 
const DataTypeGetUnderlyingType () const
 
const DataTypeGetElementType () const
 
const DataTypeGetDecayedType () const
 
Bool HasTypeArguments () const
 
const TypeArgumentsGetTypeArguments () const
 
const ParametricTypeInterfaceGetParametricType () const
 
const TupleDataTypeGetTupleType () const
 
Result< void > AddConversion (const DataType &src, CONVERSION_FLAGS kind, Conversion &&func) const
 
Result< void > Convert (Generic &dest, const ConstDataPtr &src, CONVERSION_FLAGS ignore=CONVERSION_FLAGS::NONE) const
 
template<typename T >
void AssertType () const
 
template<typename T >
Bool Is () const
 
Bool IsCastableFrom (const DataType &other) const
 
template<typename T >
Bool IsCastableFrom () const
 
template<typename T >
Bool IsCastableTo () const
 
enum maxon::DataType::BASE_OF_MODE MAXON_ENUM_FLAGS_CLASS (BASE_OF_MODE)
 
Bool IsBaseOfOrSame (const DataType &other, BASE_OF_MODE mode=BASE_OF_MODE::NONE) const
 
Bool IsSimilar (const DataType &other) const
 
ConstDataPtr GetNullValue () const
 
void Reset ()
 
const DataTypeImplPrivateGetPointer () const
 
template<typename DEST , typename SRC >
Result< void > AddConversion (CONVERSION_FLAGS kind, Result< void >(*conversion)(DEST &, const SRC &))
 

Static Public Member Functions

static MAXON_ATTRIBUTE_FORCE_INLINE const DataTypeNullValue ()
 
static Result< DataTypeGet (const Id &typeId)
 
template<typename DEST , typename SRC >
static Result< void > AddConversion (CONVERSION_FLAGS kind, Result< void >(*conversion)(DEST &dest, const SRC &src))
 

Private Member Functions

void AddReference () const
 
void RemoveReference () const
 
Bool IsBaseOfOrSameImpl (const DataType &other, BASE_OF_MODE mode) const
 
Bool IsBaseOfOrSameImpl (const DataType *other, BASE_OF_MODE mode) const
 

Private Attributes

StrongRef< const DataTypeImpl_ptr
 

Friends

class Data
 
class DataTypeImpl
 
class DataTypePtr
 
class StrongRefHandler
 

Member Typedef Documentation

◆ Conversion

using Conversion = Delegate<Result<void>(const DataPtr& dest, const ConstDataPtr& src)>

A Conversion delegate defines a conversion from a source type to a destination type (such as from Int to Float). You can register Conversion delegates from a source type at the DataType object of the destination type.

See also
AddConversion

Member Enumeration Documentation

◆ BASE_OF_MODE

enum BASE_OF_MODE
strong

Match mode for IsBaseOfOrSame.

Enumerator
NONE 
ORDERED_TYPE_ONLY 

When tuple or container types are compared, members have to match only in order and type, their names are ignored.

UNORDERED_BY_NAME 

When tuple or container types are compared, members are matched by name, so their order is ignored.

GENERIC_DOWNCAST 

Consider the instantiation of a generic type the same as the generic type.

Constructor & Destructor Documentation

◆ DataType() [1/3]

DataType ( )
default

◆ DataType() [2/3]

DataType ( const DataTypeImpl ptr)
explicit

◆ DataType() [3/3]

DataType ( std::nullptr_t  )
explicitdelete

Member Function Documentation

◆ NullValue()

static MAXON_ATTRIBUTE_FORCE_INLINE const DataType& NullValue ( )
static

◆ operator Bool()

operator Bool ( ) const
explicit

◆ operator==()

Bool operator== ( const DataType other) const

◆ operator!=()

Bool operator!= ( const DataType other) const

◆ GetHashCode()

HashInt GetHashCode ( ) const

◆ GetUniqueHashCode()

UniqueHash GetUniqueHashCode ( ) const

◆ operator->()

const DataTypeImpl* operator-> ( ) const

◆ GetId()

const Id& GetId ( ) const

Returns the identifier of this data type. Data type identifiers of primary types look like int32, pointer types are identified by a * suffix as in {float64*}, tuple types by a parenthesized list of its member types as in {(int32,float64*)}.

Returns
Unique identifier of this type.

◆ ToString()

String ToString ( const FormatStatement formatStatement = nullptr) const

Returns a String representation of this @CLASS.

Parameters
[in]formatStatementNullptr or additional formatting instruction.
Returns
String representation of this @CLASS.

◆ GetSize()

Int GetSize ( ) const

Returns the size of values of this data type.

Returns
Size of values.

◆ GetAlignment()

Int GetAlignment ( ) const

Returns the alignment of values of this data type. This might by an extended alignment.

Returns
Alignment of values.

◆ GetValueKind()

VALUEKIND GetValueKind ( ) const

Returns the kind of values of this data type. This is a coarse classification to distinguish between e.g. value types, pointers, references, arrays and tuples.

Returns
Kind of values.

◆ CheckValueKind()

Bool CheckValueKind ( VALUEKIND  test) const

Tests the value kind of this data type for the given flags (by using the bitwise and).

Parameters
[in]testThe flags to test.
Returns
True if the value kind of this data type has one of the given flags, false otherwise.

◆ GetUnqualifiedType()

const DataType& GetUnqualifiedType ( ) const

Returns the unqualified type of this data type. Currently the only possible qualification is a const qualification. So when this data type represents const T, the returned data type represents T. If the type is already an unqualified type, this functions returns the type itself.

Returns
This type with any qualifications removed (or this type itself if it is already unqualified).

◆ ResolveRecursiveType()

const DataType& ResolveRecursiveType ( ) const

◆ GetUnderlyingType()

const DataType& GetUnderlyingType ( ) const

Returns the underlying type of this data type. The underlying data type is a layout-compatible more fundamental type, such as the unqualified version T for const T, or the tuple type Tuple<T, T, T> for Vec3<T>.

Returns
The underlying type of this type, or nullptr.

◆ GetElementType()

const DataType& GetElementType ( ) const

Returns the element type of this data type. The element type is used for some parametric types such as pointers or references, so for example the element type of {T*} or {StrongRef<T>} is T.

Returns
The element type of this type, or nullptr.

◆ GetDecayedType()

const DataType& GetDecayedType ( ) const

Returns the decayed type of this data type (in the sense of std::decay). I.e., at first this removes any l- or r-value-reference-qualification, and then it returns the unqualified type of the result.

Returns
The decayed type of this type, maybe this type itself.

◆ HasTypeArguments()

Bool HasTypeArguments ( ) const

Returns true if this data type has valid type arguments, so that it is legal to call GetTypeArguments().

Returns
True if this type has valid type arguments, false otherwise.

◆ GetTypeArguments()

const TypeArguments& GetTypeArguments ( ) const

Returns the type arguments of this data type. Type arguments are set for some instantiations of parametric types. For example, the 3-dimensional Vector is an instantiation of the parametric type Vec with the arguments (Float, 3).

Returns
The type arguments of this type.

◆ GetParametricType()

const ParametricTypeInterface* GetParametricType ( ) const

Returns the parametric type which instantiated this type. For example if this type is Vector, the function returns the parametric type Vec.

Returns
The parametric type which instantiated this type, or nullptr.

◆ Get()

static Result<DataType> Get ( const Id typeId)
static

Returns the DataType identified by typeId. This supports primary data types as well as compound data types which are based on other types. E.g., the id "(int64,net.maxon.parametrictype.vec<3,float64>,{net.maxon.interface.functionsignature,net.maxon.interface.genericfunction})[]" identifies an array of tuples with Int64, Vector64 and object members where the object has to implement FunctionSignatureInterface and GenericFunctionInterface.

This function just forwards to DataTypeLib::GetDataType.

Parameters
[in]typeIdType identifier.
Returns
DataType for the given id.

◆ GetTupleType()

const TupleDataType& GetTupleType ( ) const

Returns the underlying tuple type of this type (if it exists). It exists for value types like Vector whose underlying tuple type is composed of the members (x, y, z for Vector).

Returns
Underlying tuple type of this type, or nullptr if this doesn't exist.

◆ AddConversion() [1/2]

Result<void> AddConversion ( const DataType src,
CONVERSION_FLAGS  kind,
Conversion &&  func 
) const

Registers a Conversion delegate func from the source type src at this DataType. The Conversion delegate has to convert values of type src to values of this DataType.

Parameters
[in]srcThe source type of the conversion function.
[in]kindThe kind of the conversion.
[in]funcThe conversion delegate.
Returns
OK on success.

◆ AddConversion() [2/2]

static Result<void> AddConversion ( CONVERSION_FLAGS  kind,
Result< void >(*)(DEST &dest, const SRC &src conversion 
)
static

Registers a conversion function conversion from type SRC to type DEST at the DataType of SRC.

Parameters
[in]conversionThe conversion function.
Returns
OK on success.

◆ Convert()

Result<void> Convert ( Generic &  dest,
const ConstDataPtr src,
CONVERSION_FLAGS  ignore = CONVERSION_FLAGS::NONE 
) const

Converts the value src to the value #dest (the type of which has to match this DataType). This uses the conversion delegates which have been registered with AddConversion, or ParametricTypeInterface::Convert if this DataType is an instance of a parametric type.

Parameters
[in]destThe destination value.
[in]srcThe source value.
[in]ignoreOnly those conversions are taken into account whose conversion flags aren't set in #ignore.
Returns
OK on success. If there is no conversion from the source type at all, an UnsupportedArgumentError is returned. For narrowing conversions other errors may occur, such as when the representable range is exceeded.

◆ IsCastableFrom()

Bool IsCastableFrom ( const DataType other) const

Checks if a value of the other type can be cast safely to a value of this type. This holds if either both types are the same, or this type is Generic, or both types are reference or pointer types and the type to which this type points is a base type of the type to which the other type points (see IsBaseOfOrSame).

Parameters
[in]otherAnother data type.
Returns
True if a value of this data type can be safely cast from a value of the other type.

◆ MAXON_ENUM_FLAGS_CLASS()

enum maxon::DataType::BASE_OF_MODE MAXON_ENUM_FLAGS_CLASS ( BASE_OF_MODE  )

◆ IsBaseOfOrSame()

Bool IsBaseOfOrSame ( const DataType other,
BASE_OF_MODE  mode = BASE_OF_MODE::NONE 
) const

Checks if this type is a base type of the other type (or the same). This takes into account

  • the hierarchy of virtual interfaces
  • const qualification
  • and the element types of Result, ArrayInterface, Block, pointers and references.

For example, const Int is a base type of Int, but not vice versa. const Result<ObjectRef>* is a base type of Result<IoHandler>*.

Parameters
[in]otherAnother data type.
[in]modeFlags for the check.
Returns
True if this type is a base type of the other type.

◆ IsSimilar()

Bool IsSimilar ( const DataType other) const

Checks if this type is similar to the other type. Two types are similar if they are the same except for differences in const qualifiers. For example, Result<Block<const Int>>* is similar to const Result<Block<Int>>*.

Parameters
[in]otherAnother data type.
Returns
True if both types are similar.

◆ GetNullValue()

ConstDataPtr GetNullValue ( ) const

Returns a ConstDataPtr which points to a default-constructed object of this type.

Returns
ConstDataPtr for a default-constructed object of this type, or an empty ConstDataPtr in case of an error (for example if type is abstract).

◆ Reset()

void Reset ( )

Resets this @CLASS to the state it has right after default construction. This includes freeing all resources held by this @CLASS.

◆ PrivateGetPointer()

const DataTypeImpl* PrivateGetPointer ( ) const

◆ AddReference()

void AddReference ( ) const
private

◆ RemoveReference()

void RemoveReference ( ) const
private

◆ IsBaseOfOrSameImpl() [1/2]

Bool IsBaseOfOrSameImpl ( const DataType other,
BASE_OF_MODE  mode 
) const
private

◆ IsBaseOfOrSameImpl() [2/2]

Bool IsBaseOfOrSameImpl ( const DataType other,
BASE_OF_MODE  mode 
) const
private

Friends And Related Function Documentation

◆ Data

friend class Data
friend

◆ DataTypeImpl

friend class DataTypeImpl
friend

◆ DataTypePtr

friend class DataTypePtr
friend

◆ StrongRefHandler

friend class StrongRefHandler
friend

Member Data Documentation

◆ _ptr

StrongRef<const DataTypeImpl> _ptr
private

the data type