ML Reference
mlTypeTraits.h File Reference
#include "mlInitSystemML.h"
#include "mlRangeCasts.h"
#include "mlSystemWarningsDisable.h"
#include <complex>
#include "mlSystemWarningsRestore.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...
 
class  ml::TQuaternion< DT >
 Declaration of complex type traits: More...
 
class  ml::Tvec2< DT >
 Declaration of float vector type traits: More...
 
class  ml::Tvec3< DT >
 A three dimensional vector class for floating point types. More...
 
class  ml::Tvec4< DT >
 A four dimensional vector class for floating point types. More...
 
class  ml::Tvec5< DT >
 A five dimensional vector class for floating point types. More...
 
class  ml::Tvec6< DT >
 A six dimensional vector class for floating point types. More...
 
class  ml::Tvec7< DT >
 An seven dimensional vector class for floating point types. More...
 
class  ml::Tvec8< DT >
 An eight dimensional vector class for floating point types. More...
 
class  ml::Tvec9< DT >
 An nine dimensional vector class for floating point types. More...
 
class  ml::Tvec10< DT >
 An ten dimensional vector class for floating point types. More...
 
class  ml::Tvec16< DT >
 A 16 dimensional vector class for floating point types. More...
 
class  ml::Tvec32< DT >
 A 32 dimensional vector class for floating point types. More...
 
class  ml::Tvec64< DT >
 A 64 dimensional vector class for floating point types. More...
 
class  ml::Tmat2< DT >
 Declaration of matrix type traits: More...
 
class  ml::Tmat3< DT >
 A three by three matrix class of three row vectors. More...
 
class  ml::Tmat4< DT >
 A four by four matrix class consisting of 4 row vectors. More...
 
class  ml::Tmat5< DT >
 A five by five matrix class of five row vectors. More...
 
class  ml::Tmat6< DT >
 A six by six matrix class of six row vectors. More...
 
class  ml::TVectorNDBase< CompIntType, NumDim >
 Declaration of integer vector type traits: More...
 
struct  OverloadSelector::SwitchType< b >
 helper types to switch between implementations of functions by overloading More...
 

Namespaces

 ml
 Define the namespace name like in the ML. Default is ml.
 
 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 own 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 own 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 only is to return different result types depending on if T is a scalar type or not. More...
 
template<typename T >
SwitchType< ml::TypeTraits< T >::isBuiltInIntegerType > OverloadSelector::isBuiltInIntegerType ()
 
template<typename T >
ml::TypeTraits< T >::ComponentType ml_component_cast (double v)
 cast 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)
 cast 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 data types), e.g. 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 doesn't need to specify T explicitly) More...
 
template<typename T >
ml_cast_from_scalar (double v)
 cast 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)
 cast 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 >
_ml_cast_from_intermediate_type (const typename ml::TypeTraits< T >::IntermediateType &v, OverloadSelector::OnTrue)
 
template<typename T >
_ml_cast_from_intermediate_type (const typename ml::TypeTraits< T >::IntermediateType &v, OverloadSelector::OnFalse)
 
template<typename T >
ml_cast_from_intermediate_type (const typename ml::TypeTraits< T >::IntermediateType &v)
 cast from an intermediate type to the desired type; does clamping and rounding for the built-in integer types, for all other types this is a simple cast More...
 
template<typename T >
_ml_cast_from_intermediate_type_without_clamping (const typename ml::TypeTraits< T >::IntermediateType &v, OverloadSelector::OnTrue)
 
template<typename T >
_ml_cast_from_intermediate_type_without_clamping (const typename ml::TypeTraits< T >::IntermediateType &v, OverloadSelector::OnFalse)
 
template<typename T >
ml_cast_from_intermediate_type_without_clamping (const typename ml::TypeTraits< T >::IntermediateType &v)
 cast from an intermediate type to the desired type; does 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) More...
 

Detailed Description

Author
Florian Link
Date
09/2009

Definition in file mlTypeTraits.h.

Macro Definition Documentation

#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, \
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:692
SwitchType< ml::TypeTraits< T >::isBuiltInIntegerType > isBuiltInIntegerType()
Definition: mlTypeTraits.h:342
SwitchType< ml::TypeTraits< T >::isStandardType > isScalarType()
The purpose of this function only is to return different result types depending on if T is a scalar t...
Definition: mlTypeTraits.h:337

Definition at line 117 of file mlTypeTraits.h.

#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; } \
};
MLint32 MLDataType
MLDataType.
Definition: mlTypeDefs.h:692
unsigned short MLuint16
Definition: mlTypeDefs.h:170
UINT64 MLuint64
Introduce platform independent 64 bit unsigned integer type.
Definition: mlTypeDefs.h:487
SwitchType< ml::TypeTraits< T >::isBuiltInIntegerType > isBuiltInIntegerType()
Definition: mlTypeTraits.h:342
SwitchType< ml::TypeTraits< T >::isStandardType > isScalarType()
The purpose of this function only is to return different result types depending on if T is a scalar t...
Definition: mlTypeTraits.h:337
unsigned int MLuint32
Definition: mlTypeDefs.h:213
unsigned char MLuint8
Definition: mlTypeDefs.h:137

Definition at line 86 of file mlTypeTraits.h.

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

Definition at line 254 of file mlTypeTraits.h.

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

Macro to declare own type traits.

Definition at line 142 of file mlTypeTraits.h.

#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 159 of file mlTypeTraits.h.

#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 256 of file mlTypeTraits.h.

#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 224 of file mlTypeTraits.h.

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

Macro to declare own type traits.

Definition at line 114 of file mlTypeTraits.h.

Function Documentation

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

Definition at line 400 of file mlTypeTraits.h.

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

Definition at line 415 of file mlTypeTraits.h.

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

Definition at line 430 of file mlTypeTraits.h.

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

Definition at line 437 of file mlTypeTraits.h.

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

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

Definition at line 423 of file mlTypeTraits.h.

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

cast from an intermediate type to the desired type; does 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 446 of file mlTypeTraits.h.

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

cast the (scalar) argument to the type of the template argument

Definition at line 376 of file mlTypeTraits.h.

References ml_component_cast().

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

cast 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 384 of file mlTypeTraits.h.

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

same as above, but will also multiply with the second argument

Definition at line 392 of file mlTypeTraits.h.

References ml_component_cast().

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

cast the argument to the component type of the template argument

Definition at line 350 of file mlTypeTraits.h.

Referenced by ml_cast_from_scalar(), ml_cast_to_intermediate_type_and_multiply(), and ml_scalar_factor_cast().

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

cast 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 data types), e.g.

T a = b * ml_scalar_factor_cast<T>(0.1)

Definition at line 361 of file mlTypeTraits.h.

References ml_component_cast().

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 doesn't need to specify T explicitly)

Definition at line 369 of file mlTypeTraits.h.

References ml_component_cast().