Wed, 17 Jul 2013 19:45:19 +0300
shrink a little
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 | ||
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
19 | typedef qint8 int8; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
20 | typedef qint16 int16; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
21 | typedef qint32 int32; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
22 | typedef qint64 int64; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
23 | typedef quint8 uint8; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
24 | typedef quint16 uint16; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
25 | typedef quint32 uint32; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
26 | typedef quint64 uint64; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
27 | |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
28 | #ifdef IN_IDE_PARSER // :| |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
29 | typedef void FILE; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
30 | #endif |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
31 | |
0 | 32 | // ============================================================================= |
33 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
34 | // ============================================================================= | |
35 | // StringFormatArg | |
36 | // | |
37 | // Converts a given value into a string that can be retrieved with ::value (). | |
38 | // Used as the argument type to the formatting functions, hence its name. | |
39 | // ============================================================================= | |
40 | class StringFormatArg { | |
41 | public: | |
42 | StringFormatArg( const str& v ); | |
43 | StringFormatArg( const char& v ); | |
44 | StringFormatArg( const uchar& v ); | |
45 | StringFormatArg( const qchar& v ); | |
46 | ||
47 | #define NUMERIC_FORMAT_ARG(T,C) \ | |
48 | StringFormatArg (const T& v) { \ | |
49 | char valstr[32]; \ | |
50 | sprintf (valstr, "%" #C, v); \ | |
51 | m_val = valstr; \ | |
52 | } | |
53 | ||
54 | NUMERIC_FORMAT_ARG( int, d ) | |
55 | NUMERIC_FORMAT_ARG( short, d ) | |
56 | NUMERIC_FORMAT_ARG( long, ld ) | |
57 | NUMERIC_FORMAT_ARG( uint, u ) | |
58 | NUMERIC_FORMAT_ARG( ushort, u ) | |
59 | NUMERIC_FORMAT_ARG( ulong, lu ) | |
60 | ||
61 | StringFormatArg( const float& v ); | |
62 | StringFormatArg( const double& v ); | |
63 | StringFormatArg( const char* v ); | |
64 | StringFormatArg( const void* v ); | |
65 | ||
66 | template<class T> StringFormatArg( const list<T>& v ) { | |
67 | m_val = "{ "; | |
68 | uint i = 0; | |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
69 | const bool isString = typeid( T ) == typeid( str ); |
0 | 70 | |
71 | for( const T& it : v ) { | |
72 | if( i++ ) | |
73 | m_val += ", "; | |
74 | ||
75 | StringFormatArg arg( it ); | |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
76 | |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
77 | if( isString ) |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
78 | m_val += "\"" + arg.value() + "\""; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
79 | else |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
80 | m_val += arg.value(); |
0 | 81 | } |
82 | ||
83 | if( i ) | |
84 | m_val += " "; | |
85 | ||
86 | m_val += "}"; | |
87 | } | |
88 | ||
89 | str value() const { | |
90 | return m_val; | |
91 | } | |
92 | private: | |
93 | str m_val; | |
94 | }; | |
95 | ||
96 | // Formatter function | |
1 | 97 | str doFormat( initlist<StringFormatArg> args ); |
0 | 98 | |
99 | // printf replacement | |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
100 | void doPrint( FILE* fp, initlist<StringFormatArg> args ); |
0 | 101 | |
102 | // Macros to access these functions | |
103 | #ifndef IN_IDE_PARSER | |
104 | # define fmt(...) doFormat({ __VA_ARGS__ }) | |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
105 | # define print(...) doPrint( stdout, { __VA_ARGS__ }) |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
106 | # define fprint(FP, ...) doPrint( FP, { __VA_ARGS__ }) |
0 | 107 | #else |
108 | str fmt( const char* fmtstr, ... ); | |
109 | void print( const char* fmtstr, ... ); | |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
110 | void fprint( FILE* fp, const char* fmtstr, ... ); |
0 | 111 | #endif |
112 | ||
113 | #endif // TYPES_H |