ARB
stringize.h
Go to the documentation of this file.
1 // ========================================================= //
2 // //
3 // File : stringize.h //
4 // Purpose : stringize et.al. //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in Jan 22 //
7 // http://www.arb-home.de/ //
8 // //
9 // ========================================================= //
10 
11 #ifndef STRINGIZE_H
12 #define STRINGIZE_H
13 
14 // see also: https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html
15 // https://gcc.gnu.org/onlinedocs/cpp/Argument-Prescan.html
16 //
17 // unittests are available in ../SL/HEADERTESTS/tiny.cxx@TEST_stringize
18 
19 // --------------------------------------------------------------------------------
20 // convert an ID or its prescanned value into a string
21 //
22 // #define VALUE 7
23 // stringize(VALUE) -> "VALUE"
24 // stringize_pscan(VALUE) -> "7"
25 //
26 // Note: if VALUE is not defined -> stringize_pscan() results in "VALUE"!
27 
28 // unittests are available in ../SL/HEADERTESTS/tiny.cxx@TEST_stringize
29 
30 #define stringize(s) #s
31 #define stringize_pscan(s) stringize(s)
32 
33 
34 // --------------------------------------------------------------------------------
35 // concatenate IDs
36 //
37 // #define PREFIX pre_
38 // #define SUFFIX suf
39 // concatenate(PREFIX,SUFFIX) -> PREFIXSUFFIX
40 // stringize_pscan(concatenate(PREFIX,SUFFIX)) -> "PREFIXSUFFIX"
41 // concatenate_pscans(PREFIX,SUFFIX) -> pre_suf
42 
43 #define concatenate(a,b) a##b
44 #define concatenate_pscans(a,b) concatenate(a,b)
45 
46 
47 #else
48 #error stringize.h included twice
49 #endif // STRINGIZE_H
50