src/macros.h

changeset 1217
314e12e23c3a
parent 1010
969b48eddd6b
child 1222
34def2630300
equal deleted inserted replaced
1216:12f9ea615cbc 1217:314e12e23c3a
22 #ifndef __GNUC__ 22 #ifndef __GNUC__
23 # define __attribute__(X) 23 # define __attribute__(X)
24 #endif 24 #endif
25 25
26 template <typename T, size_t N> 26 template <typename T, size_t N>
27 char (&countofHelper (T(&)[N]))[N]; 27 char(&countofHelper(T(&)[N]))[N];
28 #define countof(x) ((int) sizeof (countofHelper(x))) 28 #define countof(x)((int) sizeof(countofHelper(x)))
29 29
30 #define DEFINE_CLASS(SELF, SUPER) \ 30 #define DEFINE_CLASS(SELF, SUPER) \
31 public: \ 31 public: \
32 using Self = SELF; \ 32 using Self = SELF; \
33 using Super = SUPER; 33 using Super = SUPER;
38 #else // WIN32 38 #else // WIN32
39 # define DIRSLASH "/" 39 # define DIRSLASH "/"
40 # define DIRSLASH_CHAR '/' 40 # define DIRSLASH_CHAR '/'
41 #endif // WIN32 41 #endif // WIN32
42 42
43 #define dvalof(A) dprint ("value of '%1' = %2\n", #A, A) 43 #define dvalof(A) dprint("value of '%1' = %2\n", #A, A)
44 #define for_axes(AX) for (const Axis AX : std::initializer_list<const Axis> ({X, Y, Z})) 44 #define for_axes(AX) for (const Axis AX : std::initializer_list<const Axis>({X, Y, Z}))
45 45
46 #define MAKE_ITERABLE_ENUM(T) \ 46 #define MAKE_ITERABLE_ENUM(T) \
47 inline T operator++ (T& a) { a = (T) ((int) a + 1); return a; } \ 47 inline T operator++(T& a) { a = (T)((int) a + 1); return a; } \
48 inline T operator-- (T& a) { a = (T) ((int) a - 1); return a; } \ 48 inline T operator--(T& a) { a = (T)((int) a - 1); return a; } \
49 inline T operator++ (T& a, int) { T result = a; a = (T) ((int) a + 1); return result; } \ 49 inline T operator++(T& a, int) { T result = a; a = (T)((int) a + 1); return result; } \
50 inline T operator-- (T& a, int) { T result = a; a = (T) ((int) a - 1); return result; } 50 inline T operator--(T& a, int) { T result = a; a = (T)((int) a - 1); return result; }
51 51
52 #if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0) 52 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
53 # define USE_QT5 53 # define USE_QT5
54 #endif 54 #endif
55 55
56 #define FOR_ENUM_NAME_HELPER(LINE) enum_iterator_ ## LINE 56 #define FOR_ENUM_NAME_HELPER(LINE) enum_iterator_ ## LINE
57 #define FOR_ENUM_NAME(LINE) FOR_ENUM_NAME_HELPER(LINE) 57 #define FOR_ENUM_NAME(LINE) FOR_ENUM_NAME_HELPER(LINE)
58 58
59 #define for_enum(ENUM, NAME) \ 59 #define for_enum(ENUM, NAME) \
60 for (std::underlying_type<ENUM>::type FOR_ENUM_NAME (__LINE__) = \ 60 for (std::underlying_type<ENUM>::type FOR_ENUM_NAME(__LINE__) = \
61 std::underlying_type<ENUM>::type (ENUM::FirstValue); \ 61 std::underlying_type<ENUM>::type(ENUM::FirstValue); \
62 FOR_ENUM_NAME (__LINE__) < std::underlying_type<ENUM>::type (ENUM::NumValues); \ 62 FOR_ENUM_NAME(__LINE__) < std::underlying_type<ENUM>::type(ENUM::NumValues); \
63 ++FOR_ENUM_NAME (__LINE__)) \ 63 ++FOR_ENUM_NAME(__LINE__)) \
64 for (ENUM NAME = ENUM (FOR_ENUM_NAME (__LINE__)); NAME != ENUM::NumValues; \ 64 for (ENUM NAME = ENUM(FOR_ENUM_NAME(__LINE__)); NAME != ENUM::NumValues; \
65 NAME = ENUM::NumValues) 65 NAME = ENUM::NumValues)
66 66
67 #define ConfigOption(...) 67 #define ConfigOption(...)

mercurial