Xonotic
misc.qh
Go to the documentation of this file.
1 #pragma once
2 
3 #ifdef __STDC__
4  #define EVAL(...) EVAL1(EVAL1(EVAL1(__VA_ARGS__)))
5  #define EVAL1(...) EVAL2(EVAL2(EVAL2(__VA_ARGS__)))
6  #define EVAL2(...) EVAL3(EVAL3(EVAL3(__VA_ARGS__)))
7  #define EVAL3(...) EVAL4(EVAL4(EVAL4(__VA_ARGS__)))
8  #define EVAL4(...) EVAL5(EVAL5(EVAL5(__VA_ARGS__)))
9  #define EVAL5(...) __VA_ARGS__
10 
11  #include "p99.qh"
12  #define OVERLOAD(F, ...) P99_IF_EMPTY(__VA_ARGS__)(P99_PASTE2(F, _00)())(P99_PASTE3(F, _, P00_NARG(__VA_ARGS__))(__VA_ARGS__))
13 
14  #define OVERLOAD_(F, ...) P99_IF_EMPTY(__VA_ARGS__)(P99_PASTE2(F, _00)())(P99_PASTE3(F, _, P00_NARG(__VA_ARGS__))(__VA_ARGS__))
15  #define OVERLOAD__(F, ...) P99_IF_EMPTY(__VA_ARGS__)(P99_PASTE2(F, _00)())(P99_PASTE3(F, _, P00_NARG(__VA_ARGS__))(__VA_ARGS__))
16 #else
17  #define EVAL(...) __VA_ARGS__
18 
19  #define OVERLOAD(F, ...) F##_##__VA_COUNT__(__VA_ARGS__)
20  #define OVERLOAD_(F, ...) F##_##__VA_COUNT__(__VA_ARGS__)
21  #define OVERLOAD__(F, ...) F##_##__VA_COUNT__(__VA_ARGS__)
22 #endif
23 
24 #if defined(CSQC)
25  #define etof(e) num_for_edict(e)
26  #define ftoe(i) entitybyindex(i)
27 #elif defined(SVQC)
28  #define etof(e) num_for_edict(e)
29  #define ftoe(i) edict_num(i)
30 #elif defined(MENUQC)
31  // already defined
32 #endif
33 
34 #define GET(name) name##get
35 #define GETTER(type, name) type GET(name)() { return name; }
36 #define PROPERTY(type, name) type name; GETTER(type, name)
37 #define LAMBDA(...) { __VA_ARGS__; }
38 
39 // With block may not contain continue or break
40 #define WITH(type, name, value, block) \
41  MACRO_BEGIN \
42  type __with_save = (name); \
43  name = (value); \
44  LAMBDA(block) \
45  name = __with_save; \
46  MACRO_END