ML 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.
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. | |
#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.
#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...
Definition at line 36 of file mlRangeCasts.h.
Referenced by _MLFloatRangeCheck< float, double >::checked_cast(), _MLRangeCheck< false, true, Target, Source >::checked_cast(), _MLIntegerRangeCheck< true, true, Target, Source >::checked_cast(), _MLIntegerRangeCheck< false, true, Target, Source >::checked_cast(), and _MLIntegerRangeCheck< true, false, Target, Source >::checked_cast().
#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.
|
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.