src/macros.h

Tue, 22 Jul 2014 19:22:31 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Tue, 22 Jul 2014 19:22:31 +0300
changeset 140
04a6eb68f226
parent 139
cf11621ae422
permissions
-rw-r--r--

- having fun with version macros..

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
140
04a6eb68f226 - having fun with version macros..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
48 #if VERSION_PATCH > 0
04a6eb68f226 - having fun with version macros..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
49 # define VERSION_STRING MACRO_TO_STRING(VERSION_MAJOR) \
04a6eb68f226 - having fun with version macros..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
50 "." MACRO_TO_STRING(VERSION_MINOR) \
04a6eb68f226 - having fun with version macros..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
51 "." MACRO_TO_STRING(VERSION_PATCH)
04a6eb68f226 - having fun with version macros..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
52 #else
04a6eb68f226 - having fun with version macros..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
53 # define VERSION_STRING MACRO_TO_STRING(VERSION_MAJOR) \
04a6eb68f226 - having fun with version macros..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
54 "." MACRO_TO_STRING(VERSION_MINOR)
04a6eb68f226 - having fun with version macros..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
55 #endif
04a6eb68f226 - having fun with version macros..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
56
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 // On Windows, files are case-insensitive
134
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
58 #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
59 # define FILE_CASEINSENSITIVE
119
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
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 #define named_enum enum
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 #define elif else if
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 #define types public
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 #define countof(A) ((int) (sizeof A / sizeof *A))
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 #ifndef __GNUC__
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 # define __attribute__(X)
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 #endif
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70
125
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
71 #define deprecated __attribute__ ((deprecated))
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
72
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
73 template<typename... argtypes>
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
74 void error (const char* fmtstr, const argtypes&... args);
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
75
134
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
76 #ifndef RELEASE
129
54f27fa8f32f - expand the asserts into nothingness if not in a debug build
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
77 # 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
78 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
79 #else
54f27fa8f32f - expand the asserts into nothingness if not in a debug build
Teemu Piippo <crimsondusk64@gmail.com>
parents: 125
diff changeset
80 # 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
81 #endif
125
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 #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
84 #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
85 #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
86 #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
87 #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
88 #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
89 #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
90 #define ASSERT(A) ASSERT_EQ (A, true)
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
91
139
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
92 #define DELETE_COPY(T) \
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
93 public: \
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
94 T (T& other) = delete; \
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
95 T& operator= (T& other) = delete;
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
96
125
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
97 #endif // BOTC_MACROS_H

mercurial