File macros.h
Go to the source code of this file
Utility macros for debugging, iteration, and variadic operations. More...
Macros
| Type | Name |
|---|---|
| define | DEBUG (x) No-op in release builds (DEBUG stripped). |
| define | DEBUGS (x) No-op in release builds (DEBUGS stripped). |
| define | GLDEBUG No-op in release builds (GLDEBUG stripped). |
| define | ISIN (...) [**VA\_NARGS\_CALL\_OVERLOAD**](macros_8h.md#define-va_nargs_call_overload)(\_VA\_ISIN, \_\_VA\_ARGS\_\_)Check if value equals any of the provided arguments. |
| define | LOOP (x) [**LOOP\_N**](macros_8h.md#define-loop_n)(x, i)Loop from 0 to x-1 using iterator 'i'. |
| define | LOOP_N (x, n) for(int n = 0; n < int(x); n++)Loop from 0 to x-1 with custom iterator name. |
| define | OPTIONS (...) std::vector<std::string>{\_\_VA\_ARGS\_\_}Create std::vector<std::string> from variadic arguments. |
| define | SCREEN_H 810Default screen height for initialization. |
| define | SCREEN_W 1740Default screen width for initialization. |
| define | VA_NARGS_CALL_OVERLOAD (name, ...) [**\_VA\_NARGS\_GLUE**](macros_8h.md#define-_va_nargs_glue)([**\_VA\_NARGS\_OVERLOAD\_MACRO**](macros_8h.md#define-_va_nargs_overload_macro)(name, [**VA\_NARGS\_COUNT**](macros_8h.md#define-va_nargs_count)(\_\_VA\_ARGS\_\_)), (\_\_VA\_ARGS\_\_))Call macro overload based on argument count. |
| define | VA_NARGS_COUNT (...) /* multi line expression */Count variadic macro arguments at compile-time. |
| define | _VA_ISIN2 (v, a) ((v) == (a))Check if v equals a (2-argument base case). |
| define | _VA_ISIN3 (v, a, b) ([**\_VA\_ISIN2**](macros_8h.md#define-_va_isin2)(v, a) \|\| [**\_VA\_ISIN2**](macros_8h.md#define-_va_isin2)(v, b))Check if v equals a or b (3-argument case). |
| define | _VA_ISIN4 (v, a, b, c) ([**\_VA\_ISIN3**](macros_8h.md#define-_va_isin3)(v, a, b) \|\| [**\_VA\_ISIN2**](macros_8h.md#define-_va_isin2)(v, c))Check if v equals a, b, or c (4-argument case). |
| define | _VA_ISIN5 (v, a, b, c, d) ([**\_VA\_ISIN4**](macros_8h.md#define-_va_isin4)(v, a, b, c) \|\| [**\_VA\_ISIN2**](macros_8h.md#define-_va_isin2)(v, d))Check if v equals a, b, c, or d (5-argument case). |
| define | _VA_ISIN6 (v, a, b, c, d, e) ([**\_VA\_ISIN5**](macros_8h.md#define-_va_isin5)(v, a, b, c, d) \|\| [**\_VA\_ISIN2**](macros_8h.md#define-_va_isin2)(v, e))Check if v equals a, b, c, d, or e (6-argument case). |
| define | _VA_ISIN7 (v, a, b, c, d, e, f) ([**\_VA\_ISIN6**](macros_8h.md#define-_va_isin6)(v, a, b, c, d, e) \|\| [**\_VA\_ISIN2**](macros_8h.md#define-_va_isin2)(v, f))Check if v equals a, b, c, d, e, or f (7-argument case). |
| define | _VA_ISIN8 (v, a, b, c, d, e, f, g) ([**\_VA\_ISIN7**](macros_8h.md#define-_va_isin7)(v, a, b, c, d, e, f) \|\| [**\_VA\_ISIN2**](macros_8h.md#define-_va_isin2)(v, g))Check if v equals a, b, c, d, e, f, or g (8-argument case). |
| define | _VA_NARGS_EXPAND (args) [**\_VA\_NARGS\_RETURN\_COUNT**](macros_8h.md#define-_va_nargs_return_count) argsInternal expansion helper for argument counting. |
| define | _VA_NARGS_GLUE (x, y) x yInternal macro concatenation helper. |
| define | _VA_NARGS_OVERLOAD_MACRO (name, count) [**\_VA\_NARGS\_OVERLOAD\_MACRO1**](macros_8h.md#define-_va_nargs_overload_macro1)(name, count)Internal macro overload dispatcher. |
| define | _VA_NARGS_OVERLOAD_MACRO1 (name, count) [**\_VA\_NARGS\_OVERLOAD\_MACRO2**](macros_8h.md#define-_va_nargs_overload_macro2)(name, count)Internal macro overload helper (level 1). |
| define | _VA_NARGS_OVERLOAD_MACRO2 (name, count) name##countInternal macro overload helper (level 2). |
| define | _VA_NARGS_RETURN_COUNT (_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, _9_, _10_, _11_, _12_, _13_, _14_, _15_, _16_, _17_, _18_, _19_, _20_, _21_, _22_, _23_, _24_, _25_, _26_, _27_, _28_, _29_, _30_, _31_, _32_, _33_, _34_, _35_, _36_, _37_, _38_, _39_, _40_, _41_, _42_, _43_, _44_, _45_, _46_, _47_, _48_, _49_, _50_, _51_, _52_, _53_, _54_, _55_, _56_, _57_, _58_, _59_, _60_, _61_, _62_, _63_, _64_, count, ...) countInternal argument counter helper. |
Detailed Description
This header provides commonly used preprocessor macros for development convenience: * Debug output macros (conditionally compiled in DEBUG builds) * OpenGL error checking and reporting * Loop iteration shortcuts * Variadic macro helpers for argument counting and overloading
Architecture: * Debug macros compile to no-ops in RELEASE builds (zero overhead) * OpenGL debugging helps catch state errors during development * Variadic macros enable template-like macro overloading
Design Principles: * Minimize runtime overhead (most macros are compile-time only) * Debug output only in _DEBUG builds * Use inline functions where possible for type safety
Note:
All debug macros are no-ops in release builds to eliminate overhead.
Note:
OpenGL error checking is expensive - use sparingly in hot paths.
Macro Definition Documentation
define DEBUG
No-op in release builds (DEBUG stripped).
#define DEBUG (
x
)
define DEBUGS
No-op in release builds (DEBUGS stripped).
#define DEBUGS (
x
)
define GLDEBUG
No-op in release builds (GLDEBUG stripped).
#define GLDEBUG
define ISIN
Check if value equals any of the provided arguments.
#define ISIN (
...
) `VA_NARGS_CALL_OVERLOAD (_VA_ISIN, __VA_ARGS__)`
Variadic macro that checks if the first argument equals any of the remaining arguments. Automatically selects correct overload based on argument count.
Parameters:
vValue to check...Set of values to compare against
Returns:
Boolean expression (compile-time evaluated)
Note:
Supports 2-8 arguments (value + 1-7 comparisons).
Note:
Uses short-circuit evaluation for efficiency.
Example:
if (ISIN(type, TYPE_MESH, TYPE_CAMERA, TYPE_LIGHT)) {
// Handle renderable object types
}
define LOOP
Loop from 0 to x-1 using iterator 'i'.
#define LOOP (
x
) `LOOP_N (x, i)`
Convenience macro for simple loops with default iterator name.
Parameters:
xUpper bound (exclusive)
Example:
LOOP(vertices.size()) {
// i goes from 0 to vertices.size()-1
}
define LOOP_N
Loop from 0 to x-1 with custom iterator name.
#define LOOP_N (
x,
n
) `for(int n = 0; n < int(x); n++)`
Shorthand for range-based integer loop with configurable iterator variable.
Parameters:
xUpper bound (exclusive)nIterator variable name
Example:
LOOP_N(10, j) {
// j goes from 0 to 9
}
define OPTIONS
Create std::vector<std::string> from variadic arguments.
#define OPTIONS (
...
) `std::vector<std::string>{__VA_ARGS__}`
Shorthand for initializing string vectors from comma-separated string literals. Commonly used for dropdown options or choice lists in UI.
Parameters:
...Comma-separated string literals
Example:
auto modes = OPTIONS("Perspective", "Orthographic", "Stereo");
// Equivalent to: std::vector<std::string>{"Perspective", "Orthographic", "Stereo"}
define SCREEN_H
Default screen height for initialization.
#define SCREEN_H `810`
Initial viewport height used for framebuffer and window creation. Can be overridden at runtime via viewport resize events.
Note:
This is a legacy constant - prefer reading viewport size from Context.
define SCREEN_W
Default screen width for initialization.
#define SCREEN_W `1740`
Initial viewport width used for framebuffer and window creation. Can be overridden at runtime via viewport resize events.
Note:
This is a legacy constant - prefer reading viewport size from Context.
define VA_NARGS_CALL_OVERLOAD
Call macro overload based on argument count.
#define VA_NARGS_CALL_OVERLOAD (
name,
...
) `_VA_NARGS_GLUE ( _VA_NARGS_OVERLOAD_MACRO (name, VA_NARGS_COUNT (__VA_ARGS__)), (__VA_ARGS__))`
Enables compile-time macro overloading by appending argument count to macro name. Used for implementing ISIN and other variadic macros with different behaviors.
Parameters:
nameBase macro name (overloads must be named name2, name3, etc.)...Variadic arguments to pass to overload
Example:
// Define overloads:
#define PRINT2(a, b) std::cout << a << b
#define PRINT3(a, b, c) std::cout << a << b << c
// Use dispatcher:
VA_NARGS_CALL_OVERLOAD(PRINT, x, y) // Calls PRINT2
VA_NARGS_CALL_OVERLOAD(PRINT, x, y, z) // Calls PRINT3
define VA_NARGS_COUNT
Count variadic macro arguments at compile-time.
#define VA_NARGS_COUNT (
...
) `/* multi line expression */`
Returns the number of arguments passed to the macro (up to 64). Used by VA_NARGS_CALL_OVERLOAD to dispatch to correct overload.
Parameters:
...Variadic arguments to count
Returns:
Integer literal representing argument count
Note:
Maximum 64 arguments supported.
Example:
VA_NARGS_COUNT(a, b, c) // Expands to 3
VA_NARGS_COUNT(x) // Expands to 1
define _VA_ISIN2
Check if v equals a (2-argument base case).
#define _VA_ISIN2 (
v,
a
) `((v) == (a))`
Note:
Internal use only - use ISIN macro instead.
define _VA_ISIN3
Check if v equals a or b (3-argument case).
#define _VA_ISIN3 (
v,
a,
b
) `( _VA_ISIN2 (v, a) || _VA_ISIN2 (v, b))`
Note:
Internal use only - use ISIN macro instead.
define _VA_ISIN4
Check if v equals a, b, or c (4-argument case).
#define _VA_ISIN4 (
v,
a,
b,
c
) `( _VA_ISIN3 (v, a, b) || _VA_ISIN2 (v, c))`
Note:
Internal use only - use ISIN macro instead.
define _VA_ISIN5
Check if v equals a, b, c, or d (5-argument case).
#define _VA_ISIN5 (
v,
a,
b,
c,
d
) `( _VA_ISIN4 (v, a, b, c) || _VA_ISIN2 (v, d))`
Note:
Internal use only - use ISIN macro instead.
define _VA_ISIN6
Check if v equals a, b, c, d, or e (6-argument case).
#define _VA_ISIN6 (
v,
a,
b,
c,
d,
e
) `( _VA_ISIN5 (v, a, b, c, d) || _VA_ISIN2 (v, e))`
Note:
Internal use only - use ISIN macro instead.
define _VA_ISIN7
Check if v equals a, b, c, d, e, or f (7-argument case).
#define _VA_ISIN7 (
v,
a,
b,
c,
d,
e,
f
) `( _VA_ISIN6 (v, a, b, c, d, e) || _VA_ISIN2 (v, f))`
Note:
Internal use only - use ISIN macro instead.
define _VA_ISIN8
Check if v equals a, b, c, d, e, f, or g (8-argument case).
#define _VA_ISIN8 (
v,
a,
b,
c,
d,
e,
f,
g
) `( _VA_ISIN7 (v, a, b, c, d, e, f) || _VA_ISIN2 (v, g))`
Note:
Internal use only - use ISIN macro instead.
define _VA_NARGS_EXPAND
Internal expansion helper for argument counting.
#define _VA_NARGS_EXPAND (
args
) `_VA_NARGS_RETURN_COUNT args`
Note:
Internal use only - not intended for direct invocation.
define _VA_NARGS_GLUE
Internal macro concatenation helper.
#define _VA_NARGS_GLUE (
x,
y
) `x y`
Used by variadic macro system to glue tokens together.
Note:
Internal use only - not intended for direct invocation.
define _VA_NARGS_OVERLOAD_MACRO
Internal macro overload dispatcher.
#define _VA_NARGS_OVERLOAD_MACRO (
name,
count
) `_VA_NARGS_OVERLOAD_MACRO1 (name, count)`
Note:
Internal use only - not intended for direct invocation.
define _VA_NARGS_OVERLOAD_MACRO1
Internal macro overload helper (level 1).
#define _VA_NARGS_OVERLOAD_MACRO1 (
name,
count
) `_VA_NARGS_OVERLOAD_MACRO2 (name, count)`
Note:
Internal use only - not intended for direct invocation.
define _VA_NARGS_OVERLOAD_MACRO2
Internal macro overload helper (level 2).
#define _VA_NARGS_OVERLOAD_MACRO2 (
name,
count
) `name##count`
Note:
Internal use only - not intended for direct invocation.
define _VA_NARGS_RETURN_COUNT
Internal argument counter helper.
#define _VA_NARGS_RETURN_COUNT (
_1_,
_2_,
_3_,
_4_,
_5_,
_6_,
_7_,
_8_,
_9_,
_10_,
_11_,
_12_,
_13_,
_14_,
_15_,
_16_,
_17_,
_18_,
_19_,
_20_,
_21_,
_22_,
_23_,
_24_,
_25_,
_26_,
_27_,
_28_,
_29_,
_30_,
_31_,
_32_,
_33_,
_34_,
_35_,
_36_,
_37_,
_38_,
_39_,
_40_,
_41_,
_42_,
_43_,
_44_,
_45_,
_46_,
_47_,
_48_,
_49_,
_50_,
_51_,
_52_,
_53_,
_54_,
_55_,
_56_,
_57_,
_58_,
_59_,
_60_,
_61_,
_62_,
_63_,
_64_,
count,
...
) `count`
Returns the count from the 64th position in the argument list. Used by VA_NARGS_COUNT to determine variadic argument count.
Note:
Internal use only - not intended for direct invocation.
The documentation for this class was generated from the following file src/extra/macros.h