Despite programming in C/C++ for quite a while this technique never occurred to me. It's still quite clunky, but I have found it useful in my latest work when loading/saving values from a file.
In one .h file, lets call it sizes.h:
| #ifdef GUI_SIZE
GUI_SIZE(Background)
GUI_SIZE(Button)
GUI_SIZE(Slider)
#undef GUI_SIZE
#endif
|
Then in another file:
1
2
3
4
5
6
7
8
9
10
11
12
13 | #define QUOTED_EXPAND(str) #str
#define QUOTED(str) QUOTED_EXPAND(str)
enum GuiSizes {
#define GUI_SIZE(name) GuiSizes_##name,
#include "sizes.h"
GuiSizes_Count,
};
const char *guiSizeNames[GuiSizes_Count] = {
#define GUI_SIZE(name) QUOTED(name),
#include "sizes.h"
};
|