DataType Class Reference Data Types

#include <datatypebase.h>

Inheritance diagram for DataType:

Classes

class   Primary

Public Types

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

公共成员函数

  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
const DataTypeImpl operator-> () const
const Id GetId () const
String   ToString (const FormatStatement *formatStatement=nullptr) const
Int   GetSize () const
Int   GetAlignment () const
VALUEKIND   GetValueKind () const
Bool   CheckValueKind ( VALUEKIND test) const
const DataType GetUnqualifiedType () const
const DataType ResolveRecursiveType () const
const DataType GetUnderlyingType () const
const DataType GetElementType () const
const DataType GetDecayedType () const
Bool   HasTypeArguments () const
const TypeArguments GetTypeArguments () const
const ParametricTypeInterface GetParametricType () const
const TupleDataType GetTupleType () const
Result < void >  AddConversion (const DataType & src , CONVERSION_FLAGS kind, Conversion &&func) const
Result < void >  转换 (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
void  重置 ()
const DataTypeImpl PrivateGetPointer () const
template<typename DEST , typename SRC >
Result < void >  AddConversion ( CONVERSION_FLAGS kind, Result < void >(*conversion)(DEST &, const SRC &))

静态公共成员函数

static const DataType NullValue ()
static Result < DataType Get (const Id &typeId)
template<typename DEST , typename SRC >
static Result < void >  AddConversion ( CONVERSION_FLAGS kind, Result < void >(*conversion)(DEST &dest, const SRC & src ))

私有成员函数

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  数据
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.

另请参阅
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.

构造函数 & 析构函数文档编制

◆  DataType() [1/3]

DataType ( )
default

◆  DataType() [2/3]

DataType ( const DataTypeImpl ptr )
explicit

◆  DataType() [3/3]

DataType ( std::nullptr_t  )
explicit delete

成员函数文档编制

◆  NullValue()

static 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

◆  operator->()

const DataTypeImpl * operator-> ( ) const

◆  GetId()

const Id & GetId ( ) const

Returns the identifier of this data type. 数据 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*)}.

返回
Unique identifier of this type.

◆  ToString()

String ToString ( const FormatStatement formatStatement = nullptr ) const

Returns a String representation of this @CLASS.

参数
[in] formatStatement Nullptr or additional formatting instruction.
返回
String representation of this @CLASS.

◆  GetSize()

Int GetSize ( ) const

Returns the size of values of this data type.

返回
Size of values.

◆  GetAlignment()

Int GetAlignment ( ) const

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

返回
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.

返回
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).

参数
[in] test The flags to test.
返回
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.

返回
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>.

返回
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 .

返回
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.

返回
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() .

返回
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).

返回
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.

返回
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 .

参数
[in] typeId Type identifier.
返回
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 向量 whose underlying tuple type is composed of the members ( x , y , z for 向量 ).

返回
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 .

参数
[in] src The source type of the conversion function.
[in] kind The kind of the conversion.
[in] func The conversion delegate.
返回
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 .

参数
[in] conversion The conversion function.
返回
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.

参数
[in] dest The destination value.
[in] src The source value.
[in] ignore Only those conversions are taken into account whose conversion flags aren't also set in #ignore.
返回
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).

参数
[in] other Another data type.
返回
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

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

参数
[in] other Another data type.
[in] mode Flags for the check.
返回
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> >*.

参数
[in] other Another data type.
返回
True if both types are similar.

◆  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

◆  数据

friend class 数据
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