cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
cmnTypeTraits< _elementType > Class Template Reference

A collection of useful information about the C++ basic types, represented in a generic programming way. More...

#include <cmnTypeTraits.h>

Public Types

typedef _elementType Type
 
typedef bool BoolType
 
typedef cmnVaArgPromotion
< _elementType >::Type 
VaArgPromotion
 

Public Member Functions

template<>
bool HasSign (void)
 
template<>
bool HasSign (void)
 
template<>
bool HasSign (void)
 
template<>
bool HasSign (void)
 
template<>
bool HasSign (void)
 
template<>
bool HasSign (void)
 
template<>
bool HasSign (void)
 
template<>
bool HasSign (void)
 
template<>
bool HasSign (void)
 
template<>
bool HasSign (void)
 
template<>
bool HasInfinity (void)
 
template<>
bool HasInfinity (void)
 
template<>
bool HasInfinity (void)
 
template<>
bool HasInfinity (void)
 
template<>
bool HasInfinity (void)
 
template<>
bool HasInfinity (void)
 
template<>
bool HasInfinity (void)
 
template<>
bool HasInfinity (void)
 
template<>
bool HasInfinity (void)
 
template<>
bool HasInfinity (void)
 
template<>
bool IsFinite (const float &value)
 
template<>
bool IsFinite (const double &value)
 
template<>
bool IsFinite (const long long int &CMN_UNUSED(value))
 
template<>
bool IsFinite (const int &CMN_UNUSED(value))
 
template<>
bool IsFinite (const short &CMN_UNUSED(value))
 
template<>
bool IsFinite (const char &CMN_UNUSED(value))
 
template<>
bool IsFinite (const unsigned long long int &CMN_UNUSED(value))
 
template<>
bool IsFinite (const unsigned int &CMN_UNUSED(value))
 
template<>
bool IsFinite (const unsigned short &CMN_UNUSED(value))
 
template<>
bool IsFinite (const unsigned char &CMN_UNUSED(value))
 
template<>
bool HasNaN (void)
 
template<>
bool HasNaN (void)
 
template<>
bool HasNaN (void)
 
template<>
bool HasNaN (void)
 
template<>
bool HasNaN (void)
 
template<>
bool HasNaN (void)
 
template<>
bool HasNaN (void)
 
template<>
bool HasNaN (void)
 
template<>
bool HasNaN (void)
 
template<>
bool HasNaN (void)
 
template<>
bool IsNaN (const float &value)
 
template<>
bool IsNaN (const double &value)
 
template<>
bool IsNaN (const long long int &CMN_UNUSED(value))
 
template<>
bool IsNaN (const int &CMN_UNUSED(value))
 
template<>
bool IsNaN (const short &CMN_UNUSED(value))
 
template<>
bool IsNaN (const char &CMN_UNUSED(value))
 
template<>
bool IsNaN (const unsigned long long int &CMN_UNUSED(value))
 
template<>
bool IsNaN (const unsigned int &CMN_UNUSED(value))
 
template<>
bool IsNaN (const unsigned short &CMN_UNUSED(value))
 
template<>
bool IsNaN (const unsigned char &CMN_UNUSED(value))
 

Static Public Member Functions

static Type Tolerance (void)
 
static void SetTolerance (Type tolerance)
 
static CISST_EXPORT std::string TypeName (void)
 
static Type PlusInfinityOrMax (void)
 
static Type MinusInfinityOrMin (void)
 
static CISST_EXPORT Type MaxPositiveValue (void)
 
static CISST_EXPORT Type MinPositiveValue (void)
 
static CISST_EXPORT Type MaxNegativeValue (void)
 
static CISST_EXPORT Type MinNegativeValue (void)
 
static CISST_EXPORT Type PlusInfinity (void)
 
static CISST_EXPORT Type MinusInfinity (void)
 
static CISST_EXPORT bool HasSign (void)
 
static bool HasInfinity (void)
 
static bool IsFinite (const Type &value)
 
static CISST_EXPORT Type NaN (void)
 
static CISST_EXPORT bool IsNaN (const Type &value)
 
static bool HasNaN (void)
 

Static Public Attributes

static CISST_EXPORT const Type DefaultTolerance
 

Detailed Description

template<class _elementType>
class cmnTypeTraits< _elementType >

A collection of useful information about the C++ basic types, represented in a generic programming way.

When using generic programming, there is a lot of type information to consider. For example, numeric tolerance values, type promotions, the name of the type, numerical limits, and so on. The standard C++ headers contain this information, but it is not organized in an accessible manner for generic programming. The purpose of this class is to provide a common representation for type-dependent information.

For example, to check that the result of a computation is correct within the accepted numerical tolerance for the type of operands, write something like

_elementType myVariable;
doSomething();
};

The default tolerance for a float is set to 1.0e-5f and for a double it is set to 1.0e-9.

The macros va_list, va_arg, etc. can be used with an ellipsis "..." to declare a method or function with an undetermined number of arguments. To retrieve an argument from the stack, it is then required to provided the type of the data used, e.g. myVariable = va_arg(myArgs, double). To use va_arg in a templated class such as:

template <class _elementType>
myClass {
}

one could imagine a call like va_arg(myArgs, _elementType). Unfortunatly, some types are automatically promoted (see ANSI C 89). For example, to get a char, one has to use int and to get a float, use a double.

By default, the internal type VaArgPromotion is the same as the template parameter. The class is specialized for the types which require a promotion.

The class can then be used in the following way:

_elementType myVariable;
myVariable = static_cast<_elementType>(va_arg(nextArg, typename cmnTypeTraits<_elementType>::VaArgPromotion));
Parameters
_elementTypeThe template parameter which defined the type.

Member Typedef Documentation

template<class _elementType>
typedef bool cmnTypeTraits< _elementType >::BoolType

Boolean type. This has been added to delay the instantiation of some templated code by gcc 4.0. This type is used to define vctDynamicConstVectorBase::BoolVectorValueType and vctDynamicConstMatrixBase::BoolMatrixValueType.

template<class _elementType>
typedef _elementType cmnTypeTraits< _elementType >::Type

The type in question

template<class _elementType>
typedef cmnVaArgPromotion<_elementType>::Type cmnTypeTraits< _elementType >::VaArgPromotion

The promotion of the type when passed in a va_arg list

Member Function Documentation

template<class _elementType>
static bool cmnTypeTraits< _elementType >::HasInfinity ( void  )
inlinestatic

Check if this type has a meaningful positive infinity and negative infinity.

template<>
bool cmnTypeTraits< float >::HasInfinity ( void  )
inline
template<>
bool cmnTypeTraits< double >::HasInfinity ( void  )
inline
template<>
bool cmnTypeTraits< long long int >::HasInfinity ( void  )
inline
template<>
bool cmnTypeTraits< int >::HasInfinity ( void  )
inline
template<>
bool cmnTypeTraits< short >::HasInfinity ( void  )
inline
template<>
bool cmnTypeTraits< char >::HasInfinity ( void  )
inline
template<>
bool cmnTypeTraits< unsigned long long int >::HasInfinity ( void  )
inline
template<>
bool cmnTypeTraits< unsigned int >::HasInfinity ( void  )
inline
template<>
bool cmnTypeTraits< unsigned short >::HasInfinity ( void  )
inline
template<>
bool cmnTypeTraits< unsigned char >::HasInfinity ( void  )
inline
template<class _elementType>
static bool cmnTypeTraits< _elementType >::HasNaN ( void  )
inlinestatic

Check if this type has a meaningful Not A Number.

template<>
bool cmnTypeTraits< float >::HasNaN ( void  )
inline
template<>
bool cmnTypeTraits< double >::HasNaN ( void  )
inline
template<>
bool cmnTypeTraits< long long int >::HasNaN ( void  )
inline
template<>
bool cmnTypeTraits< int >::HasNaN ( void  )
inline
template<>
bool cmnTypeTraits< short >::HasNaN ( void  )
inline
template<>
bool cmnTypeTraits< char >::HasNaN ( void  )
inline
template<>
bool cmnTypeTraits< unsigned long long int >::HasNaN ( void  )
inline
template<>
bool cmnTypeTraits< unsigned int >::HasNaN ( void  )
inline
template<>
bool cmnTypeTraits< unsigned short >::HasNaN ( void  )
inline
template<>
bool cmnTypeTraits< unsigned char >::HasNaN ( void  )
inline
template<class _elementType>
static CISST_EXPORT bool cmnTypeTraits< _elementType >::HasSign ( void  )
static

Return true if this type has signed, e.g., for signed int, double, etc. Return false if this type is unsigned.

template<>
bool cmnTypeTraits< float >::HasSign ( void  )
inline
template<>
bool cmnTypeTraits< double >::HasSign ( void  )
inline
template<>
bool cmnTypeTraits< long long int >::HasSign ( void  )
inline
template<>
bool cmnTypeTraits< int >::HasSign ( void  )
inline
template<>
bool cmnTypeTraits< short >::HasSign ( void  )
inline
template<>
bool cmnTypeTraits< char >::HasSign ( void  )
inline
template<>
bool cmnTypeTraits< unsigned long long int >::HasSign ( void  )
inline
template<>
bool cmnTypeTraits< unsigned int >::HasSign ( void  )
inline
template<>
bool cmnTypeTraits< unsigned short >::HasSign ( void  )
inline
template<>
bool cmnTypeTraits< unsigned char >::HasSign ( void  )
inline
template<class _elementType>
static bool cmnTypeTraits< _elementType >::IsFinite ( const Type value)
static

Test if the value is finite.

template<>
bool cmnTypeTraits< float >::IsFinite ( const float &  value)
inline
template<>
bool cmnTypeTraits< double >::IsFinite ( const double &  value)
inline
template<>
bool cmnTypeTraits< long long int >::IsFinite ( const long long int &  CMN_UNUSEDvalue)
inline
template<>
bool cmnTypeTraits< int >::IsFinite ( const int &  CMN_UNUSEDvalue)
inline
template<>
bool cmnTypeTraits< short >::IsFinite ( const short &  CMN_UNUSEDvalue)
inline
template<>
bool cmnTypeTraits< char >::IsFinite ( const char &  CMN_UNUSEDvalue)
inline
template<>
bool cmnTypeTraits< unsigned long long int >::IsFinite ( const unsigned long long int &  CMN_UNUSEDvalue)
inline
template<>
bool cmnTypeTraits< unsigned int >::IsFinite ( const unsigned int &  CMN_UNUSEDvalue)
inline
template<>
bool cmnTypeTraits< unsigned short >::IsFinite ( const unsigned short &  CMN_UNUSEDvalue)
inline
template<>
bool cmnTypeTraits< unsigned char >::IsFinite ( const unsigned char &  CMN_UNUSEDvalue)
inline
template<class _elementType>
static CISST_EXPORT bool cmnTypeTraits< _elementType >::IsNaN ( const Type value)
static

Test if the value is nan.

template<>
bool cmnTypeTraits< float >::IsNaN ( const float &  value)
inline
template<>
bool cmnTypeTraits< double >::IsNaN ( const double &  value)
inline
template<>
bool cmnTypeTraits< long long int >::IsNaN ( const long long int &  CMN_UNUSEDvalue)
inline
template<>
bool cmnTypeTraits< int >::IsNaN ( const int &  CMN_UNUSEDvalue)
inline
template<>
bool cmnTypeTraits< short >::IsNaN ( const short &  CMN_UNUSEDvalue)
inline
template<>
bool cmnTypeTraits< char >::IsNaN ( const char &  CMN_UNUSEDvalue)
inline
template<>
bool cmnTypeTraits< unsigned long long int >::IsNaN ( const unsigned long long int &  CMN_UNUSEDvalue)
inline
template<>
bool cmnTypeTraits< unsigned int >::IsNaN ( const unsigned int &  CMN_UNUSEDvalue)
inline
template<>
bool cmnTypeTraits< unsigned short >::IsNaN ( const unsigned short &  CMN_UNUSEDvalue)
inline
template<>
bool cmnTypeTraits< unsigned char >::IsNaN ( const unsigned char &  CMN_UNUSEDvalue)
inline
template<class _elementType>
static CISST_EXPORT Type cmnTypeTraits< _elementType >::MaxNegativeValue ( void  )
static

The greatest negative value possible for the type (minus one for integral types, a small negative fraction for floating point types).

template<class _elementType>
static CISST_EXPORT Type cmnTypeTraits< _elementType >::MaxPositiveValue ( void  )
static

The greatest positive value possible for the type.

template<class _elementType>
static CISST_EXPORT Type cmnTypeTraits< _elementType >::MinNegativeValue ( void  )
static

The smallest negative value possible for the type, that is, the negative value of greatest magnitude.

template<class _elementType>
static CISST_EXPORT Type cmnTypeTraits< _elementType >::MinPositiveValue ( void  )
static

The smallest positive value possible for the type (one for integral types, a small positive fraction for floating point types).

template<class _elementType>
static CISST_EXPORT Type cmnTypeTraits< _elementType >::MinusInfinity ( void  )
static

Negative infinity special value, defined for floating point types For templated code, one can use HasInfinity to check if this method is meaningful.

template<class _elementType>
static Type cmnTypeTraits< _elementType >::MinusInfinityOrMin ( void  )
inlinestatic

Return a negative number which is infinity, if available, or the smallest possible negative value otherwise. This function is useful for ``idempotent max'' operation.

template<class _elementType>
static CISST_EXPORT Type cmnTypeTraits< _elementType >::NaN ( void  )
static

Special Not a Number value, defined for floating point types. For templated code, one can use HasNaN to check if this method is meaningful.

template<class _elementType>
static CISST_EXPORT Type cmnTypeTraits< _elementType >::PlusInfinity ( void  )
static

Positive infinity special value, defined for floating point types. For templated code, one can use HasInfinity to check if this method is meaningful.

template<class _elementType>
static Type cmnTypeTraits< _elementType >::PlusInfinityOrMax ( void  )
inlinestatic

Return a positive number which is infinity, if available, or the greatest possible positive value otherwise. This function is useful for ``idempotent min'' operation.

template<class _elementType>
static void cmnTypeTraits< _elementType >::SetTolerance ( Type  tolerance)
inlinestatic

Set the numerical tolerance for this type.

template<class _elementType>
static Type cmnTypeTraits< _elementType >::Tolerance ( void  )
inlinestatic

Return the numerical tolerance value for computation results.

template<class _elementType>
static CISST_EXPORT std::string cmnTypeTraits< _elementType >::TypeName ( void  )
static

The name of the type.

Member Data Documentation

template<class _elementType>
CISST_EXPORT const Type cmnTypeTraits< _elementType >::DefaultTolerance
static

The tolerance for the specific type.


The documentation for this class was generated from the following file: