Wed, 17 Jul 2013 03:06:21 +0300
Added configs for Zandronum binary paths
0 | 1 | #ifndef TYPES_H |
2 | #define TYPES_H | |
3 | ||
4 | #include "main.h" | |
5 | #include <QString> | |
6 | #include <QList> | |
3
d0b278fd29d5
Implemented wad path list
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
7 | #include <QVariant> |
0 | 8 | |
9 | typedef QString str; | |
10 | typedef QChar qchar; | |
3
d0b278fd29d5
Implemented wad path list
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
11 | typedef QVariant var; |
0 | 12 | template<class T> using list = QList<T>; |
13 | typedef unsigned int uint; | |
14 | typedef unsigned short ushort; | |
15 | typedef unsigned long ulong; | |
16 | template<class T> using initlist = std::initializer_list<T>; | |
17 | using std::size_t; | |
18 | ||
19 | // ============================================================================= | |
20 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
21 | // ============================================================================= | |
22 | // StringFormatArg | |
23 | // | |
24 | // Converts a given value into a string that can be retrieved with ::value (). | |
25 | // Used as the argument type to the formatting functions, hence its name. | |
26 | // ============================================================================= | |
27 | class StringFormatArg { | |
28 | public: | |
29 | StringFormatArg( const str& v ); | |
30 | StringFormatArg( const char& v ); | |
31 | StringFormatArg( const uchar& v ); | |
32 | StringFormatArg( const qchar& v ); | |
33 | ||
34 | #define NUMERIC_FORMAT_ARG(T,C) \ | |
35 | StringFormatArg (const T& v) { \ | |
36 | char valstr[32]; \ | |
37 | sprintf (valstr, "%" #C, v); \ | |
38 | m_val = valstr; \ | |
39 | } | |
40 | ||
41 | NUMERIC_FORMAT_ARG( int, d ) | |
42 | NUMERIC_FORMAT_ARG( short, d ) | |
43 | NUMERIC_FORMAT_ARG( long, ld ) | |
44 | NUMERIC_FORMAT_ARG( uint, u ) | |
45 | NUMERIC_FORMAT_ARG( ushort, u ) | |
46 | NUMERIC_FORMAT_ARG( ulong, lu ) | |
47 | ||
48 | StringFormatArg( const float& v ); | |
49 | StringFormatArg( const double& v ); | |
50 | StringFormatArg( const char* v ); | |
51 | StringFormatArg( const void* v ); | |
52 | ||
53 | template<class T> StringFormatArg( const list<T>& v ) { | |
54 | m_val = "{ "; | |
55 | uint i = 0; | |
56 | ||
57 | for( const T& it : v ) { | |
58 | if( i++ ) | |
59 | m_val += ", "; | |
60 | ||
61 | StringFormatArg arg( it ); | |
62 | m_val += arg.value(); | |
63 | } | |
64 | ||
65 | if( i ) | |
66 | m_val += " "; | |
67 | ||
68 | m_val += "}"; | |
69 | } | |
70 | ||
71 | str value() const { | |
72 | return m_val; | |
73 | } | |
74 | private: | |
75 | str m_val; | |
76 | }; | |
77 | ||
78 | // Formatter function | |
1 | 79 | str doFormat( initlist<StringFormatArg> args ); |
0 | 80 | |
81 | // printf replacement | |
1 | 82 | void doPrint( initlist<StringFormatArg> args ); |
0 | 83 | |
84 | // Macros to access these functions | |
85 | #ifndef IN_IDE_PARSER | |
86 | # define fmt(...) doFormat({ __VA_ARGS__ }) | |
87 | # define print(...) doPrint({ __VA_ARGS__ }) | |
88 | #else | |
89 | str fmt( const char* fmtstr, ... ); | |
90 | void print( const char* fmtstr, ... ); | |
91 | #endif | |
92 | ||
93 | #endif // TYPES_H |