8 #ifndef TurtleBrains_Defines_hpp
9 #define TurtleBrains_Defines_hpp
12 #include <type_traits>
14 #include <turtle_brains/core/tb_configuration.hpp>
15 #include <turtle_brains/core/tb_error.hpp>
25 #define tb_unused(parameter) ((void)parameter);
35 template <
typename Type>
void SafeDelete(Type*& objectPointer) {
if (
nullptr != objectPointer) {
delete objectPointer; objectPointer =
nullptr; } }
41 template <
typename Type>
void SafeDeleteArray(Type*& arrayPointer) {
if (
nullptr != arrayPointer) {
delete[] arrayPointer; arrayPointer =
nullptr; } }
52 template <
typename ReturnType,
typename InitialType> ReturnType
RangedCast(
const InitialType& value)
54 #if defined(tb_visual_cpp)
64 #pragma warning(disable: 4127)
65 #pragma warning(disable: 4018)
66 #elif defined(__GNUC__)
67 #pragma GCC diagnostic push
68 #pragma GCC diagnostic ignored "-Wsign-compare"
70 if ((std::is_signed<ReturnType>::value == std::is_signed<InitialType>::value))
72 tb_error_if(value < std::numeric_limits<ReturnType>::min() || value > std::numeric_limits<ReturnType>::max(),
73 "tbCastingError: Value is outside the range of the following cast.");
75 else if (std::is_signed<InitialType>::value)
77 tb_error_if(value < 0,
"tbCastingError: Signed value is less than 0 going to unsigned-value.");
79 #if defined(tb_visual_cpp)
81 #elif defined(__GNUC__)
82 #pragma GCC diagnostic pop
84 return static_cast<ReturnType
>(value);
98 template <
typename ReturnType,
typename InitialType> ReturnType
ClampedCast(
const InitialType& value,
const ReturnType& minimum,
const ReturnType& maximum)
100 tb_error_if(minimum > maximum,
"tbError: Minimum should never be larger than Maximum.");
101 ReturnType unclamped = RangedCast<ReturnType>(value);
102 if (unclamped < minimum)
106 if (unclamped > maximum)
ReturnType RangedCast(const InitialType &value)
Definition: tb_defines.hpp:52
Here is some information about the primary namespace.
Definition: tb_application_dialog.hpp:21
ReturnType ClampedCast(const InitialType &value, const ReturnType &minimum, const ReturnType &maximum)
Definition: tb_defines.hpp:98
void SafeDeleteArray(Type *&arrayPointer)
Definition: tb_defines.hpp:41
void SafeDelete(Type *&objectPointer)
Definition: tb_defines.hpp:35
Contains core functionality for each component of the API.
Definition: tb_debug_logger.hpp:88
#define tb_error_if(errorTest, message,...)
Definition: tb_error.hpp:42