ML Reference
mlRangeCasts.h File Reference
#include "mlTypeDefs.h"
#include "mlErrorMacros.h"
#include "mlErrorOutput.h"
#include <ThirdPartyWarningsDisable.h>
#include <climits>
#include <ThirdPartyWarningsRestore.h>

Go to the source code of this file.

Classes

struct  _ml_numeric_limits< unsigned char >
 
struct  _ml_numeric_limits< signed char >
 
struct  _ml_numeric_limits< char >
 
struct  _ml_numeric_limits< unsigned short >
 
struct  _ml_numeric_limits< short >
 
struct  _ml_numeric_limits< unsigned int >
 
struct  _ml_numeric_limits< int >
 
struct  _ml_numeric_limits< unsigned long >
 
struct  _ml_numeric_limits< long >
 
struct  _ml_numeric_limits< unsigned long long >
 
struct  _ml_numeric_limits< long long >
 
struct  _ml_numeric_limits< float >
 
struct  _ml_numeric_limits< double >
 
struct  _MLIntegerRangeCheck< true, true, Target, Source >
 
struct  _MLIntegerRangeCheck< false, true, Target, Source >
 
struct  _MLIntegerRangeCheck< true, false, Target, Source >
 
struct  _MLIntegerRangeCheck< false, false, Target, Source >
 
struct  _MLFloatRangeCheck< Target, Source >
 
struct  _MLFloatRangeCheck< float, double >
 
struct  _MLRangeCheck< false, false, Target, Source >
 
struct  _MLRangeCheck< true, false, Target, Source >
 
struct  _MLRangeCheck< false, true, Target, Source >
 
struct  _MLRangeCheck< true, true, Target, Source >
 

Macros

#define _ML_COMPILE_RANGE_CASTS_WITH_CHECKS
 Configurable collection of safe casts for data value conversions.
 
#define _ML_RANGE_ERROR_TYPE   ML_PRINT_FATAL_ERROR
 This definition determines which error type is used to report range errors; the default are fatal errors.
 
#define _ML_OUTPUT_RANGE_ERROR    _ML_RANGE_ERROR_TYPE("_MLRangeCheck::checked_cast", ML_OUT_OF_RANGE, "Invalid numeric cast (range check failed).");
 To avoid duplication...
 

Functions

template<typename Target , typename Source >
Target mlrange_cast (Source arg)
 Generic version of checked ML casts.
 

Macro Definition Documentation

◆ _ML_COMPILE_RANGE_CASTS_WITH_CHECKS

#define _ML_COMPILE_RANGE_CASTS_WITH_CHECKS

Configurable collection of safe casts for data value conversions.

If this flag is enabled then range casts are compiled as pure casts to suppress precision warnings. If this flag is enabled then range casts are compiled as inline functions which casts the values and apply checks for valid ranges.

Definition at line 30 of file mlRangeCasts.h.

◆ _ML_OUTPUT_RANGE_ERROR

◆ _ML_RANGE_ERROR_TYPE

#define _ML_RANGE_ERROR_TYPE   ML_PRINT_FATAL_ERROR

This definition determines which error type is used to report range errors; the default are fatal errors.

Definition at line 33 of file mlRangeCasts.h.

Function Documentation

◆ mlrange_cast()

template<typename Target , typename Source >
Target mlrange_cast ( Source arg)
inline

Generic version of checked ML casts.

Do a cast to the given target type, with a range check whether the value can be represented by the target type (otherwise a fatal error occurs). No clamping is done in the error case! This is defined for all basic types (except long double). Note: When casting from float types to integer types, the values are rounded to the nearest integer first. When casting from integer types to float types, no check is performed, since a float will always be sufficient to hold an integer value (though not necessarily precisely).

Definition at line 332 of file mlRangeCasts.h.