MeVisLab Toolbox Reference
mlTypeTraits.h File Reference
#include "mlInitSystemML.h"
#include "mlRangeCasts.h"
#include <ThirdPartyWarningsDisable.h>
#include <complex>
#include <ThirdPartyWarningsRestore.h>

Go to the source code of this file.

Classes

struct  ml::TypeTraits< T >
 TypeTraits for scalar ML datatypes. More...
 
struct  ml::DataTypeSelector< dataTypeId >
 Helper template so select a data type from its type ID. More...
 
struct  OverloadSelector::SwitchType< b >
 Helper types to switch between implementations of functions by overloading. More...
 

Namespaces

 ml
 Main documentation file for ML users and developers.
 
 OverloadSelector
 

Macros

#define _ML_DECLARE_SCALAR_TYPETRAIT_BODY(TYPE, FLAGS)
 
#define ML_DECLARE_SCALAR_TYPETRAIT(TYPE, FLAGS)    _ML_DECLARE_SCALAR_TYPETRAIT_BODY(TYPE, FLAGS)
 Macro to declare custom type traits. More...
 
#define _ML_DECLARE_EXTENDED_TYPETRAIT_BODY(TYPE, TYPE_ID, COMPONENT_TYPE)
 
#define ML_DECLARE_EXTENDED_TYPETRAIT(TYPE, TYPE_ID, COMPONENT_TYPE)    _ML_DECLARE_EXTENDED_TYPETRAIT_BODY(TYPE, TYPE_ID, COMPONENT_TYPE)
 Macro to declare custom type traits. More...
 
#define ML_DECLARE_FLOAT_VECTOR_TYPETRAIT(TEMPLATE_TYPE, BASE_TYPE, TYPE_ID)    ML_DECLARE_EXTENDED_TYPETRAIT(TEMPLATE_TYPE<BASE_TYPE>, TYPE_ID, BASE_TYPE)
 Declaration of standard integer type traits. More...
 
#define ML_DECLARE_MATRIX_TYPETRAIT(TEMPLATE_TYPE, BASE_TYPE, TYPE_ID)    ML_DECLARE_EXTENDED_TYPETRAIT(TEMPLATE_TYPE<BASE_TYPE>, TYPE_ID, BASE_TYPE)
 
#define INT_VECTOR_EXPANDER(BASE_TYPE, DIM_NUM)   TVectorNDBase<BASE_TYPE, DIM_NUM>
 
#define ML_DECLARE_INT_VECTOR_TYPETRAIT(BASE_TYPE, DIM_NUM, TYPE_ID)    _ML_DECLARE_EXTENDED_TYPETRAIT_BODY(INT_VECTOR_EXPANDER(BASE_TYPE, DIM_NUM), TYPE_ID, BASE_TYPE)
 

Typedefs

typedef SwitchType< true > OverloadSelector::OnTrue
 
typedef SwitchType< false > OverloadSelector::OnFalse
 

Enumerations

enum  { ml::ML_INTEGER_TYPE = 0x01 , ml::ML_FLOAT_TYPE = 0x02 , ml::ML_SIGNED_TYPE = 0x04 }
 

Functions

template<typename T >
SwitchType< ml::TypeTraits< T >::isStandardType > OverloadSelector::isScalarType ()
 The purpose of this function is only to return different result types depending on whether T is a scalar type. More...
 
template<typename T >
SwitchType< ml::TypeTraits< T >::isBuiltInIntegerType > OverloadSelector::isBuiltInIntegerType ()
 
template<typename T >
ml::TypeTraits< T >::ComponentType ml_component_cast (double v)
 Casts the argument to the component type of the template argument. More...
 
template<typename T >
ml::TypeTraits< typename ml::TypeTraits< T >::IntermediateType >::ComponentType ml_scalar_factor_cast (double v)
 Casts the double argument to a type suitable for multiplying with the template type. More...
 
template<typename T >
ml::TypeTraits< typename ml::TypeTraits< T >::IntermediateType >::ComponentType ml_scalar_factor_cast (double v, const T &)
 Same as above with dummy argument of type T (so one does not need to specify T explicitly). More...
 
template<typename T >
T ml_cast_from_scalar (double v)
 Casts the (scalar) argument to the type of the template argument. More...
 
template<typename T >
ml::TypeTraits< T >::IntermediateType ml_cast_to_intermediate_type (const T &v)
 Casts type to an intermediate type suitable for consecutive arithmetic operations; integer types will be cast to double, all other types will be left alone. More...
 
template<typename T , typename S >
ml::TypeTraits< T >::IntermediateType ml_cast_to_intermediate_type_and_multiply (const T &v, S s)
 Same as above, but will also multiply with the second argument. More...
 
template<typename T >
T _ml_cast_from_intermediate_type (const typename ml::TypeTraits< T >::IntermediateType &v, OverloadSelector::OnTrue)
 
template<typename T >
T _ml_cast_from_intermediate_type (const typename ml::TypeTraits< T >::IntermediateType &v, OverloadSelector::OnFalse)
 
template<typename T >
T ml_cast_from_intermediate_type (const typename ml::TypeTraits< T >::IntermediateType &v)
 Casts from an intermediate type to the desired type; performs clamping and rounding for the built-in integer types, for all other types, this is a simple cast. More...
 
template<typename T >
T _ml_cast_from_intermediate_type_without_clamping (const typename ml::TypeTraits< T >::IntermediateType &v, OverloadSelector::OnTrue)
 
template<typename T >
T _ml_cast_from_intermediate_type_without_clamping (const typename ml::TypeTraits< T >::IntermediateType &v, OverloadSelector::OnFalse)
 
template<typename T >
T ml_cast_from_intermediate_type_without_clamping (const typename ml::TypeTraits< T >::IntermediateType &v)
 Casts from an intermediate type to the desired type; performs rounding but no clamping for the built-in integer types, for all other types, this is a simple cast. More...
 

Macro Definition Documentation

◆ _ML_DECLARE_EXTENDED_TYPETRAIT_BODY

#define _ML_DECLARE_EXTENDED_TYPETRAIT_BODY (   TYPE,
  TYPE_ID,
  COMPONENT_TYPE 
)
Value:
template <> struct DataTypeSelector<TYPE_ID> { typedef TYPE Type; }; \
template <> struct TypeTraits<TYPE > { \
typedef COMPONENT_TYPE ComponentType; \
typedef TYPE IntermediateType; \
enum { \
dataType = TYPE_ID, \
isBuiltInFloatType = false, \
isBuiltInIntegerType = false, \
isScalarType = false, \
isStandardType = false, \
isBuiltInSignedType = false, \
is8BitInteger = false, \
is16BitInteger = false, \
is32BitInteger = false, \
is64BitInteger = false, \
is8_16_32BitInteger = false, \
isUnknown = false \
}; \
\
static inline bool matches(MLDataType dt) { return dt == dataType; } \
static inline MLDataType getDataType() { return dataType; } \
};
MLint32 MLDataType
MLDataType.
Definition: mlTypeDefs.h:596

Definition at line 121 of file mlTypeTraits.h.

◆ _ML_DECLARE_SCALAR_TYPETRAIT_BODY

#define _ML_DECLARE_SCALAR_TYPETRAIT_BODY (   TYPE,
  FLAGS 
)
Value:
template <> struct DataTypeSelector<TYPE##Type> { typedef TYPE Type; }; \
template <> struct TypeTraits<TYPE > { \
typedef TYPE ComponentType; \
typedef double IntermediateType; \
enum { \
dataType = TYPE##Type, \
isBuiltInFloatType = (((FLAGS) & ML_FLOAT_TYPE) != 0), \
isBuiltInIntegerType = (((FLAGS) & ML_INTEGER_TYPE) != 0), \
isScalarType = (((FLAGS) & (ML_INTEGER_TYPE | ML_FLOAT_TYPE)) != 0), \
isStandardType = isScalarType, \
isBuiltInSignedType = (((FLAGS) & ML_SIGNED_TYPE) != 0), \
is8BitInteger = ((((FLAGS) & ML_INTEGER_TYPE) != 0) && (sizeof(TYPE)==sizeof(MLuint8)) ), \
is16BitInteger = ((((FLAGS) & ML_INTEGER_TYPE) != 0) && (sizeof(TYPE)==sizeof(MLuint16)) ), \
is32BitInteger = ((((FLAGS) & ML_INTEGER_TYPE) != 0) && (sizeof(TYPE)==sizeof(MLuint32)) ), \
is64BitInteger = ((((FLAGS) & ML_INTEGER_TYPE) != 0) && (sizeof(TYPE)==sizeof(MLuint64)) ), \
is8_16_32BitInteger = ((((FLAGS) & ML_INTEGER_TYPE) != 0) && \
((sizeof(TYPE)==sizeof(MLuint8)) || \
(sizeof(TYPE)==sizeof(MLuint16)) || \
(sizeof(TYPE)==sizeof(MLuint32)))), \
isUnknown = false \
}; \
\
static inline bool matches(MLDataType dt) { return dt == dataType; } \
static inline MLDataType getDataType() { return dataType; } \
};
UINT64 MLuint64
Introduce platform-independent 64-bit unsigned integer type.
Definition: mlTypeDefs.h:425
unsigned int MLuint32
Definition: mlTypeDefs.h:185
unsigned char MLuint8
Definition: mlTypeDefs.h:109
unsigned short MLuint16
Definition: mlTypeDefs.h:142
SwitchType< ml::TypeTraits< T >::isBuiltInIntegerType > isBuiltInIntegerType()
Definition: mlTypeTraits.h:346
SwitchType< ml::TypeTraits< T >::isStandardType > isScalarType()
The purpose of this function is only to return different result types depending on whether T is a sca...
Definition: mlTypeTraits.h:341
@ ML_FLOAT_TYPE
Definition: mlTypeTraits.h:86
@ ML_SIGNED_TYPE
Definition: mlTypeTraits.h:87
@ ML_INTEGER_TYPE
Definition: mlTypeTraits.h:85

Definition at line 90 of file mlTypeTraits.h.

◆ INT_VECTOR_EXPANDER

#define INT_VECTOR_EXPANDER (   BASE_TYPE,
  DIM_NUM 
)    TVectorNDBase<BASE_TYPE, DIM_NUM>

Definition at line 258 of file mlTypeTraits.h.

◆ ML_DECLARE_EXTENDED_TYPETRAIT

#define ML_DECLARE_EXTENDED_TYPETRAIT (   TYPE,
  TYPE_ID,
  COMPONENT_TYPE 
)     _ML_DECLARE_EXTENDED_TYPETRAIT_BODY(TYPE, TYPE_ID, COMPONENT_TYPE)

Macro to declare custom type traits.

Definition at line 146 of file mlTypeTraits.h.

◆ ML_DECLARE_FLOAT_VECTOR_TYPETRAIT

#define ML_DECLARE_FLOAT_VECTOR_TYPETRAIT (   TEMPLATE_TYPE,
  BASE_TYPE,
  TYPE_ID 
)     ML_DECLARE_EXTENDED_TYPETRAIT(TEMPLATE_TYPE<BASE_TYPE>, TYPE_ID, BASE_TYPE)

Declaration of standard integer type traits.

Declaration of standard float type traits

Definition at line 163 of file mlTypeTraits.h.

◆ ML_DECLARE_INT_VECTOR_TYPETRAIT

#define ML_DECLARE_INT_VECTOR_TYPETRAIT (   BASE_TYPE,
  DIM_NUM,
  TYPE_ID 
)     _ML_DECLARE_EXTENDED_TYPETRAIT_BODY(INT_VECTOR_EXPANDER(BASE_TYPE, DIM_NUM), TYPE_ID, BASE_TYPE)

Definition at line 260 of file mlTypeTraits.h.

◆ ML_DECLARE_MATRIX_TYPETRAIT

#define ML_DECLARE_MATRIX_TYPETRAIT (   TEMPLATE_TYPE,
  BASE_TYPE,
  TYPE_ID 
)     ML_DECLARE_EXTENDED_TYPETRAIT(TEMPLATE_TYPE<BASE_TYPE>, TYPE_ID, BASE_TYPE)

Definition at line 228 of file mlTypeTraits.h.

◆ ML_DECLARE_SCALAR_TYPETRAIT

#define ML_DECLARE_SCALAR_TYPETRAIT (   TYPE,
  FLAGS 
)     _ML_DECLARE_SCALAR_TYPETRAIT_BODY(TYPE, FLAGS)

Macro to declare custom type traits.

Definition at line 118 of file mlTypeTraits.h.

Function Documentation

◆ _ml_cast_from_intermediate_type() [1/2]

template<typename T >
T _ml_cast_from_intermediate_type ( const typename ml::TypeTraits< T >::IntermediateType &  v,
OverloadSelector::OnFalse   
)
inline

Definition at line 431 of file mlTypeTraits.h.

References T.

◆ _ml_cast_from_intermediate_type() [2/2]

template<typename T >
T _ml_cast_from_intermediate_type ( const typename ml::TypeTraits< T >::IntermediateType &  v,
OverloadSelector::OnTrue   
)
inline

Definition at line 412 of file mlTypeTraits.h.

References T.

◆ _ml_cast_from_intermediate_type_without_clamping() [1/2]

template<typename T >
T _ml_cast_from_intermediate_type_without_clamping ( const typename ml::TypeTraits< T >::IntermediateType &  v,
OverloadSelector::OnFalse   
)
inline

Definition at line 453 of file mlTypeTraits.h.

References T.

◆ _ml_cast_from_intermediate_type_without_clamping() [2/2]

template<typename T >
T _ml_cast_from_intermediate_type_without_clamping ( const typename ml::TypeTraits< T >::IntermediateType &  v,
OverloadSelector::OnTrue   
)
inline

Definition at line 446 of file mlTypeTraits.h.

References T.

◆ ml_cast_from_intermediate_type()

template<typename T >
T ml_cast_from_intermediate_type ( const typename ml::TypeTraits< T >::IntermediateType &  v)
inline

Casts from an intermediate type to the desired type; performs clamping and rounding for the built-in integer types, for all other types, this is a simple cast.

Definition at line 439 of file mlTypeTraits.h.

◆ ml_cast_from_intermediate_type_without_clamping()

template<typename T >
T ml_cast_from_intermediate_type_without_clamping ( const typename ml::TypeTraits< T >::IntermediateType &  v)
inline

Casts from an intermediate type to the desired type; performs rounding but no clamping for the built-in integer types, for all other types, this is a simple cast.

Use this if you know that the value will always be in the data type's range.

Definition at line 462 of file mlTypeTraits.h.

◆ ml_cast_from_scalar()

template<typename T >
T ml_cast_from_scalar ( double  v)
inline

Casts the (scalar) argument to the type of the template argument.

Definition at line 382 of file mlTypeTraits.h.

References T.

◆ ml_cast_to_intermediate_type()

template<typename T >
ml::TypeTraits<T>::IntermediateType ml_cast_to_intermediate_type ( const T v)
inline

Casts type to an intermediate type suitable for consecutive arithmetic operations; integer types will be cast to double, all other types will be left alone.

Definition at line 390 of file mlTypeTraits.h.

◆ ml_cast_to_intermediate_type_and_multiply()

template<typename T , typename S >
ml::TypeTraits<T>::IntermediateType ml_cast_to_intermediate_type_and_multiply ( const T v,
S  s 
)
inline

Same as above, but will also multiply with the second argument.

Definition at line 398 of file mlTypeTraits.h.

References ml_component_cast().

◆ ml_component_cast()

template<typename T >
ml::TypeTraits<T>::ComponentType ml_component_cast ( double  v)
inline

Casts the argument to the component type of the template argument.

Definition at line 354 of file mlTypeTraits.h.

Referenced by ml_cast_to_intermediate_type_and_multiply().

◆ ml_scalar_factor_cast() [1/2]

template<typename T >
ml::TypeTraits<typename ml::TypeTraits<T>::IntermediateType>::ComponentType ml_scalar_factor_cast ( double  v)
inline

Casts the double argument to a type suitable for multiplying with the template type.

This is double for all scalar types and the component type for all extended datatypes. For example:

T a = b * ml_scalar_factor_cast<T>(0.1)
@ T
Definition: SoKeyGrabber.h:71

Definition at line 367 of file mlTypeTraits.h.

◆ ml_scalar_factor_cast() [2/2]

template<typename T >
ml::TypeTraits<typename ml::TypeTraits<T>::IntermediateType>::ComponentType ml_scalar_factor_cast ( double  v,
const T  
)
inline

Same as above with dummy argument of type T (so one does not need to specify T explicitly).

Definition at line 375 of file mlTypeTraits.h.