src/macros.h

Sun, 20 Jul 2014 17:25:36 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 20 Jul 2014 17:25:36 +0300
changeset 134
eca2fc0acaa2
parent 133
dbbdb870c835
child 139
cf11621ae422
permissions
-rw-r--r--

- massive refactoring

119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
133
dbbdb870c835 - changed all source files to use my correct legal name instead of my calling name
Teemu Piippo <crimsondusk64@gmail.com>
parents: 130
diff changeset
2 Copyright 2012-2014 Teemu Piippo
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 All rights reserved.
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 Redistribution and use in source and binary forms, with or without
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 modification, are permitted provided that the following conditions
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 are met:
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 1. Redistributions of source code must retain the above copyright
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 notice, this list of conditions and the following disclaimer.
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 2. Redistributions in binary form must reproduce the above copyright
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 notice, this list of conditions and the following disclaimer in the
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 documentation and/or other materials provided with the distribution.
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 3. The name of the author may not be used to endorse or promote products
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 derived from this software without specific prior written permission.
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 */
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28
125
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
29 #ifndef BOTC_MACROS_H
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
30 #define BOTC_MACROS_H
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31
134
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
32 #if !defined (__cplusplus) or __cplusplus < 201103L
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 # error botc requires a C++11-compliant compiler to be built
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 #endif
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 // Application name and version
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 #define APPNAME "botc"
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 #define VERSION_MAJOR 1
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 #define VERSION_MINOR 0
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 #define VERSION_PATCH 0
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41
130
885fd60e8bf1 - add macro to string
Teemu Piippo <crimsondusk64@gmail.com>
parents: 129
diff changeset
42 #define MACRO_TO_STRING_HELPER(A) #A
885fd60e8bf1 - add macro to string
Teemu Piippo <crimsondusk64@gmail.com>
parents: 129
diff changeset
43 #define MACRO_TO_STRING(A) MACRO_TO_STRING_HELPER(A)
885fd60e8bf1 - add macro to string
Teemu Piippo <crimsondusk64@gmail.com>
parents: 129
diff changeset
44
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 #define MAKE_VERSION_NUMBER(MAJ, MIN, PAT) ((MAJ * 10000) + (MIN * 100) + PAT)
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 #define VERSION_NUMBER MAKE_VERSION_NUMBER (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH)
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 // On Windows, files are case-insensitive
134
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
49 #if (defined(WIN32) or defined(_WIN32) or defined(__WIN32)) and !defined(__CYGWIN__)
125
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
50 # define FILE_CASEINSENSITIVE
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 #endif
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 #define named_enum enum
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 #define elif else if
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 #define types public
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 #define countof(A) ((int) (sizeof A / sizeof *A))
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 #ifndef __GNUC__
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 # define __attribute__(X)
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 #endif
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61
125
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
62 #define deprecated __attribute__ ((deprecated))
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
63
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
64 template<typename... argtypes>
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
65 void error (const char* fmtstr, const argtypes&... args);
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
66
134
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
67 #ifndef RELEASE
129
54f27fa8f32f - expand the asserts into nothingness if not in a debug build
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
68 # define BOTC_GENERIC_ASSERT(A,B,OP,COMPLAINT) ((A OP B) ? (void) 0 : \
130
885fd60e8bf1 - add macro to string
Teemu Piippo <crimsondusk64@gmail.com>
parents: 129
diff changeset
69 error ("assertion failed at " __FILE__ ":" MACRO_TO_STRING(__LINE__) ": " #A " (%1) " COMPLAINT " " #B " (%2)", A, B));
129
54f27fa8f32f - expand the asserts into nothingness if not in a debug build
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
70 #else
54f27fa8f32f - expand the asserts into nothingness if not in a debug build
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
71 # define BOTC_GENERIC_ASSERT(A,B,OP,COMPLAINT) {}
54f27fa8f32f - expand the asserts into nothingness if not in a debug build
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
72 #endif
125
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
73
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
74 #define ASSERT_EQ(A,B) BOTC_GENERIC_ASSERT (A, B, ==, "does not equal")
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
75 #define ASSERT_NE(A,B) BOTC_GENERIC_ASSERT (A, B, !=, "is no different from")
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
76 #define ASSERT_LT(A,B) BOTC_GENERIC_ASSERT (A, B, <, "is not less than")
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
77 #define ASSERT_GT(A,B) BOTC_GENERIC_ASSERT (A, B, >, "is not greater than")
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
78 #define ASSERT_LT_EQ(A,B) BOTC_GENERIC_ASSERT (A, B, <=, "is not at most")
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
79 #define ASSERT_GT_EQ(A,B) BOTC_GENERIC_ASSERT (A, B, >=, "is not at least")
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
80 #define ASSERT_RANGE(A,MIN,MAX) { ASSERT_LT_EQ(A, MAX); ASSERT_GT_EQ(A, MIN); }
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
81 #define ASSERT(A) ASSERT_EQ (A, true)
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
82
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
83 #endif // BOTC_MACROS_H

mercurial