src/macros.h

changeset 125
85814c0918c5
parent 119
bdf8d46c145f
child 129
54f27fa8f32f
--- a/src/macros.h	Fri May 02 20:37:27 2014 +0300
+++ b/src/macros.h	Fri May 02 21:37:18 2014 +0300
@@ -26,7 +26,8 @@
 	THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-#pragma once
+#ifndef BOTC_MACROS_H
+#define BOTC_MACROS_H
 
 #if !defined (__cplusplus) || __cplusplus < 201103L
 # error botc requires a C++11-compliant compiler to be built
@@ -43,7 +44,7 @@
 
 // On Windows, files are case-insensitive
 #if (defined(WIN32) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__)
-#define FILE_CASEINSENSITIVE
+# define FILE_CASEINSENSITIVE
 #endif
 
 #define named_enum enum
@@ -55,4 +56,21 @@
 # define __attribute__(X)
 #endif
 
-#define deprecated __attribute__ ((deprecated))
\ No newline at end of file
+#define deprecated __attribute__ ((deprecated))
+
+template<typename... argtypes>
+void error (const char* fmtstr, const argtypes&... args);
+
+#define BOTC_GENERIC_ASSERT(A,B,OP,COMPLAINT) ((A OP B) ? (void) 0 : \
+	error ("assertion failed at " __FILE__ ":%1: " #A " (%2) " COMPLAINT " " #B " (%3)", __LINE__, A, B));
+
+#define ASSERT_EQ(A,B) BOTC_GENERIC_ASSERT (A, B, ==, "does not equal")
+#define ASSERT_NE(A,B) BOTC_GENERIC_ASSERT (A, B, !=, "is no different from")
+#define ASSERT_LT(A,B) BOTC_GENERIC_ASSERT (A, B, <, "is not less than")
+#define ASSERT_GT(A,B) BOTC_GENERIC_ASSERT (A, B, >, "is not greater than")
+#define ASSERT_LT_EQ(A,B) BOTC_GENERIC_ASSERT (A, B, <=, "is not at most")
+#define ASSERT_GT_EQ(A,B) BOTC_GENERIC_ASSERT (A, B, >=, "is not at least")
+#define ASSERT_RANGE(A,MIN,MAX) { ASSERT_LT_EQ(A, MAX); ASSERT_GT_EQ(A, MIN); }
+#define ASSERT(A) ASSERT_EQ (A, true)
+
+#endif // BOTC_MACROS_H

mercurial