diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-05-11 02:01:07 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-05-11 02:01:07 +0300 |
commit | f8f7131cbb7cb1534d5d3f3c63e02e059d809ca6 (patch) | |
tree | e397932aec37fd9a58d509eb11270c38562bfba0 /src/utils | |
parent | 6028612674d621653d96740e62c64e41290c37d0 (diff) | |
download | manaplus-f8f7131cbb7cb1534d5d3f3c63e02e059d809ca6.tar.gz manaplus-f8f7131cbb7cb1534d5d3f3c63e02e059d809ca6.tar.bz2 manaplus-f8f7131cbb7cb1534d5d3f3c63e02e059d809ca6.tar.xz manaplus-f8f7131cbb7cb1534d5d3f3c63e02e059d809ca6.zip |
Define check macroses based on other macroses.
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/checkutils.h | 67 |
1 files changed, 39 insertions, 28 deletions
diff --git a/src/utils/checkutils.h b/src/utils/checkutils.h index 52545e5cb..9966203dc 100644 --- a/src/utils/checkutils.h +++ b/src/utils/checkutils.h @@ -23,25 +23,15 @@ #ifdef ENABLE_ASSERTS -#define reportFalse(val) \ +#define reportFalseReal(val) \ (val ? true : (reportStack(__FILE__, __LINE__, __func__, \ "Detected false value", #val), false)) -#define reportTrue(val) \ +#define reportTrueReal(val) \ (val ? (reportStack(__FILE__, __LINE__, __func__, \ "Detected false value", #val), true) : false) -#define failFalse(val) \ - (val ? true : (reportStack(__FILE__, __LINE__, __func__, \ - "Detected false value", #val), \ - throw new std::exception(), false)) - -#define failTrue(val) \ - (val ? (reportStack(__FILE__, __LINE__, __func__, \ - "Detected false value", #val), \ - throw new std::exception(), true) : false) - -#define returnFalseV(val) \ +#define returnFalseVReal(val) \ if (!val) \ { \ reportStack(__FILE__, __LINE__, __func__, \ @@ -49,7 +39,7 @@ return; \ } -#define returnTrueV(val) \ +#define returnTrueVReal(val) \ if (val) \ { \ reportStack(__FILE__, __LINE__, __func__, \ @@ -57,7 +47,7 @@ return; \ } -#define returnFalse(ret, val) \ +#define returnFalseReal(ret, val) \ if (!val) \ { \ reportStack(__FILE__, __LINE__, __func__, \ @@ -65,7 +55,7 @@ return ret; \ } -#define returnTrue(ret, val) \ +#define returnTrueReal(ret, val) \ if (val) \ { \ reportStack(__FILE__, __LINE__, __func__, \ @@ -73,7 +63,7 @@ return ret; \ } -#define returnNullptrV(val) \ +#define returnNullptrVReal(val) \ if ((val) == nullptr) \ { \ reportStack(__FILE__, __LINE__, __func__, \ @@ -81,7 +71,7 @@ return; \ } -#define returnNullptr(ret, val) \ +#define returnNullptrReal(ret, val) \ if ((val) == nullptr) \ { \ reportStack(__FILE__, __LINE__, __func__, \ @@ -89,6 +79,16 @@ return ret; \ } +#define failFalse(val) \ + (val ? true : (reportStack(__FILE__, __LINE__, __func__, \ + "Detected false value", #val), \ + throw new std::exception(), false)) + +#define failTrue(val) \ + (val ? (reportStack(__FILE__, __LINE__, __func__, \ + "Detected false value", #val), \ + throw new std::exception(), true) : false) + void reportStack(const char *const file, const unsigned int line, const char *const func, @@ -97,34 +97,45 @@ void reportStack(const char *const file, #else // ENABLE_ASSERTS -#define reportFalse(val) (val) -#define reportTrue(val) (val) -#define failFalse(val) (val) -#define failTrue(val) (val) +#define reportFalseReal(val) (val) +#define reportTrueReal(val) (val) -#define returnFalseV(val) \ +#define returnFalseVReal(val) \ if (!val) \ return; -#define returnTrueV(val) \ +#define returnTrueVReal(val) \ if (val) \ return; -#define returnFalse(ret, val) \ +#define returnFalseReal(ret, val) \ if (!val) \ return ret; -#define returnTrue(ret, val) \ +#define returnTrueReal(ret, val) \ if (val) \ return ret; -#define returnNullptrV(val) \ +#define returnNullptrVReal(val) \ if ((val) == nullptr) \ return; \ -#define returnNullptr(ret, val) \ +#define returnNullptrReal(ret, val) \ if ((val) == nullptr) \ return ret; \ +#define failFalse(val) (val) +#define failTrue(val) (val) + #endif // ENABLE_ASSERTS + +#define reportFalse(val) reportFalseReal(val) +#define reportTrue(val) reportTrueReal(val) +#define returnFalseV(val) returnFalseVReal(val) +#define returnTrueV(val) returnTrueVReal(val) +#define returnFalse(ret, val) returnFalseReal(ret, val) +#define returnTrue(ret, val) returnTrueReal(ret, val) +#define returnNullptrV(val) returnNullptrVReal(val) +#define returnNullptr(ret, val) returnNullptrReal(ret, val) + #endif // UTILS_CHECKUTILS_H |