src/macros.h

changeset 967
eb586d3e1a6a
parent 958
1dc890c73e01
child 968
4b93b7963456
equal deleted inserted replaced
966:a834e43a57da 967:eb586d3e1a6a
21 21
22 #ifndef __GNUC__ 22 #ifndef __GNUC__
23 # define __attribute__(X) 23 # define __attribute__(X)
24 #endif 24 #endif
25 25
26 // ============================================================================= 26 template <typename T, size_t N>
27 // 27 char (&countofHelper (T(&)[N]))[N];
28 #define countof(A) (safeCountOf<std::is_array<decltype(A)>::value, (sizeof A / sizeof *A)>()) 28 #define countof(x) ((int) sizeof (countofHelper(x)))
29 29
30 template<bool isArray, size_t elems>
31 inline constexpr int safeCountOf() __attribute__ ((always_inline));
32
33 template<bool isArray, size_t elems>
34 inline constexpr int safeCountOf()
35 {
36 static_assert (isArray, "parameter to countof must be an array");
37 return elems;
38 }
39
40 // =============================================================================
41 //
42 #define PROPERTY(ACCESS, TYPE, READ, WRITE, WRITETYPE) \ 30 #define PROPERTY(ACCESS, TYPE, READ, WRITE, WRITETYPE) \
43 private: \ 31 private: \
44 TYPE m_##READ; \ 32 TYPE m_##READ; \
45 \ 33 \
46 public: \ 34 public: \
58 } 46 }
59 47
60 #define PROPERTY_CUSTOM_WRITE(READ) \ 48 #define PROPERTY_CUSTOM_WRITE(READ) \
61 ; 49 ;
62 50
63 #define readAccess(A) inline decltype(_##A) A() const { return _##A; }
64 #define writeAccess(A,B) inline void B (decltype(_##A) const& a) const { _##A = a; }
65
66 #define DEFINE_CLASS(SELF, SUPER) \ 51 #define DEFINE_CLASS(SELF, SUPER) \
67 public: \ 52 public: \
68 using Self = SELF; \ 53 using Self = SELF; \
69 using Super = SUPER; 54 using Super = SUPER;
70 55
71 // =============================================================================
72 //
73 #define elif(A) else if (A)
74 #define unless(A) if (not (A))
75 #define until(A) while (not (A))
76
77 // =============================================================================
78 //
79 #ifdef WIN32 56 #ifdef WIN32
80 # define DIRSLASH "\\" 57 # define DIRSLASH "\\"
81 # define DIRSLASH_CHAR '\\' 58 # define DIRSLASH_CHAR '\\'
82 #else // WIN32 59 #else // WIN32
83 # define DIRSLASH "/" 60 # define DIRSLASH "/"
84 # define DIRSLASH_CHAR '/' 61 # define DIRSLASH_CHAR '/'
85 #endif // WIN32 62 #endif // WIN32
86 63
87 // =============================================================================
88 //
89 #ifdef __GNUC__
90 #define FUNCNAME __PRETTY_FUNCTION__
91 #else
92 #define FUNCNAME __func__
93 #endif // __GNUC__
94
95 #define dvalof(A) dprint ("value of '%1' = %2\n", #A, A) 64 #define dvalof(A) dprint ("value of '%1' = %2\n", #A, A)
96 #define for_axes(AX) for (const Axis AX : std::initializer_list<const Axis> ({X, Y, Z})) 65 #define for_axes(AX) for (const Axis AX : std::initializer_list<const Axis> ({X, Y, Z}))
97 66
98 #define NUMERIC_ENUM_OPERATORS(T) \ 67 #define MAKE_ITERABLE_ENUM(T) \
99 inline T operator++ (T& a) { a = (T) ((int) a + 1); return a; } \ 68 inline T operator++ (T& a) { a = (T) ((int) a + 1); return a; } \
100 inline T operator-- (T& a) { a = (T) ((int) a - 1); return a; } \ 69 inline T operator-- (T& a) { a = (T) ((int) a - 1); return a; } \
101 inline T operator++ (T& a, int) { T result = a; a = (T) ((int) a + 1); return result; } \ 70 inline T operator++ (T& a, int) { T result = a; a = (T) ((int) a + 1); return result; } \
102 inline T operator-- (T& a, int) { T result = a; a = (T) ((int) a - 1); return result; } 71 inline T operator-- (T& a, int) { T result = a; a = (T) ((int) a - 1); return result; }
103 72
113 std::underlying_type<ENUM>::type (ENUM::FirstValue); \ 82 std::underlying_type<ENUM>::type (ENUM::FirstValue); \
114 FOR_ENUM_NAME (__LINE__) < std::underlying_type<ENUM>::type (ENUM::NumValues); \ 83 FOR_ENUM_NAME (__LINE__) < std::underlying_type<ENUM>::type (ENUM::NumValues); \
115 ++FOR_ENUM_NAME (__LINE__)) \ 84 ++FOR_ENUM_NAME (__LINE__)) \
116 for (ENUM NAME = ENUM (FOR_ENUM_NAME (__LINE__)); NAME != ENUM::NumValues; \ 85 for (ENUM NAME = ENUM (FOR_ENUM_NAME (__LINE__)); NAME != ENUM::NumValues; \
117 NAME = ENUM::NumValues) 86 NAME = ENUM::NumValues)
118
119 // =============================================================================
120 #ifdef IN_IDE_PARSER // KDevelop workarounds:
121 # error IN_IDE_PARSER is defined (this code is only for KDevelop workarounds)
122 # define COMPILE_DATE "14-01-10 10:31:09"
123
124 # ifndef va_start
125 # define va_start(va, arg)
126 # endif // va_start
127
128 # ifndef va_end
129 # define va_end(va)
130 # endif // va_end
131
132 static const char* __func__ = ""; // Current function name
133 typedef void FILE; // :|
134 #endif // IN_IDE_PARSER

mercurial