1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #pragma once19 20 #include <sstream>21 #include "../MathBuildConfig.h"22 #include "[MathNamespace.h]"23 #include <stdio.h>24 #include "[myassert.h]"25 #include "[MathLog.h]"26 27 #ifndef MARK_UNUSED28 29 #define MARK_UNUSED(x) ((void)x)30 #endif31 32 #ifdef __GNUC__33 34 35 #define DONT_WARN_UNUSED __attribute__((unused))36 #else37 #define DONT_WARN_UNUSED38 #endif39 40 #ifndef ARRAY_LENGTH41 #define ARRAY_LENGTH(x) (sizeof((x))/sizeof((x)[0]))42 #endif43 44 45 46 47 48 49 50 51 52 53 54 [MATH_BEGIN_NAMESPACE]55 56 57 void [SetMathBreakOnAssume](bool isEnabled);58 59 60 61 bool [MathBreakOnAssume]();62 63 64 65 bool [AssumeFailed]();66 67 template<typename T>68 inline std::string [ObjToString](const T &obj)69 {70 return obj.ToString();71 }72 73 74 75 76 77 78 79 template<>80 inline std::string ObjToString<std::string>(const std::string &obj)81 {82 return obj;83 }84 85 template<>86 inline std::string [ObjToString<float>](const float &obj)87 {88 std::stringstream ss;89 ss << obj;90 return ss.str();91 }92 93 template<>94 inline std::string [ObjToString<int>](const int &obj)95 {96 std::stringstream ss;97 ss << obj;98 return ss.str();99 }100 101 template<>102 inline std::string [ObjToString<bool>](const bool &obj)103 {104 std::stringstream ss;105 ss << obj;106 return ss.str();107 }108 109 template<>110 inline std::string [ObjToString<u32>](const u32 &obj)111 {112 std::stringstream ss;113 ss << obj;114 return ss.str();115 }116 117 [MATH_END_NAMESPACE]118 119 120 121 122 123 124 125 #ifdef FAIL_USING_EXCEPTIONS126 #include <stdexcept>127 #define assume_failed(message) throw std::runtime_error((message))128 #elif defined(MATH_ASSERT_ON_ASSUME)129 #define assume(x) assert(x)130 #define assume_failed(message) assert(false && #message)131 #elif defined(MATH_SILENT_ASSUME)132 #define assume(x) ((void)0)133 #define assume_failed(message) ((void)0)134 #else135 #define assume_failed(message) LOGE("Assumption \"%s\" failed! in file %s, line %d!", message, __FILE__, __LINE__)136 #endif137 138 #ifndef assume139 #define assume(x) \140 MULTI_LINE_MACRO_BEGIN \141 if (!(x)) \142 assume_failed(#x " in " __FILE__ ":" STRINGIZE(__LINE__)); \143 MULTI_LINE_MACRO_END144 #endif145 146 147 #define assume1(x, print1) \148 MULTI_LINE_MACRO_BEGIN \149 if (!(x)) \150 assume_failed(((#x ", " #print1 ": ") + MATH_NS::ObjToString(print1) + \151 (" in " __FILE__ ":" STRINGIZE(__LINE__))).c_str()); \152 MULTI_LINE_MACRO_END153 #define assert1 assume1154 155 #define assume2(x, print1, print2) \156 MULTI_LINE_MACRO_BEGIN \157 if (!(x)) \158 assume_failed(((#x ", " #print1 ": ") + MATH_NS::ObjToString(print1) + \159 (", " #print2 ": ") + MATH_NS::ObjToString(print2) + \160 (" in " __FILE__ ":" STRINGIZE(__LINE__))).c_str()); \161 MULTI_LINE_MACRO_END162 #define assert2 assume2163 164 #define assume3(x, print1, print2, print3) \165 MULTI_LINE_MACRO_BEGIN \166 if (!(x)) \167 assume_failed(((#x ", " #print1 ": ") + MATH_NS::ObjToString(print1) + \168 (", " #print2 ": ") + MATH_NS::ObjToString(print2) + \169 (", " #print3 ": ") + MATH_NS::ObjToString(print3) + \170 (" in " __FILE__ ":" STRINGIZE(__LINE__))).c_str()); \171 MULTI_LINE_MACRO_END172 #define assert3 assume3173 174 #define assume4(x, print1, print2, print3, print4) \175 MULTI_LINE_MACRO_BEGIN \176 if (!(x)) \177 assume_failed(((#x ", " #print1 ": ") + MATH_NS::ObjToString(print1) + \178 (", " #print2 ": ") + MATH_NS::ObjToString(print2) + \179 (", " #print3 ": ") + MATH_NS::ObjToString(print3) + \180 (", " #print4 ": ") + MATH_NS::ObjToString(print4) + \181 (" in " __FILE__ ":" STRINGIZE(__LINE__))).c_str()); \182 MULTI_LINE_MACRO_END183 #define assert4 assume4184 185 186 187 #ifdef MATH_ASSERT_CORRECTNESS188 #define mathassert(x) assert(x)189 #else190 #define mathassert(x) ((void)0)191 #endif192 193 194 #ifdef OPTIMIZED_RELEASE195 #ifdef assume196 #undef assume197 #endif198 #ifdef mathassert199 #undef mathassert200 #endif201 #define assume(x) ((void)0)202 #define mathassert(x) ((void)0)203 #endif Go back to previous page