Sun, 11 Aug 2013 14:04:03 +0300
Replaced the Bytestream class with QDataStream
13
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
1 | /* |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
2 | * ZanDemo: Zandronum demo launcher |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
3 | * Copyright (C) 2013 Santeri Piippo |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
4 | * |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
8 | * (at your option) any later version. |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
9 | * |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
13 | * GNU General Public License for more details. |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
14 | * |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
17 | */ |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
18 | |
0 | 19 | #ifndef TYPES_H |
20 | #define TYPES_H | |
21 | ||
22 | #include "main.h" | |
23 | #include <QString> | |
24 | #include <QList> | |
3
d0b278fd29d5
Implemented wad path list
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
25 | #include <QVariant> |
0 | 26 | |
27 | typedef QString str; | |
28 | typedef QChar qchar; | |
3
d0b278fd29d5
Implemented wad path list
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
29 | typedef QVariant var; |
0 | 30 | template<class T> using list = QList<T>; |
31 | typedef unsigned int uint; | |
32 | typedef unsigned short ushort; | |
33 | typedef unsigned long ulong; | |
34 | template<class T> using initlist = std::initializer_list<T>; | |
35 | using std::size_t; | |
36 | ||
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
37 | typedef qint8 int8; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
38 | typedef qint16 int16; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
39 | typedef qint32 int32; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
40 | typedef qint64 int64; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
41 | typedef quint8 uint8; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
42 | typedef quint16 uint16; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
43 | typedef quint32 uint32; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
44 | typedef quint64 uint64; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
45 | |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
46 | #ifdef IN_IDE_PARSER // :| |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
47 | typedef void FILE; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
48 | #endif |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
49 | |
0 | 50 | // ============================================================================= |
51 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
52 | // ============================================================================= | |
53 | // StringFormatArg | |
54 | // | |
55 | // Converts a given value into a string that can be retrieved with ::value (). | |
56 | // Used as the argument type to the formatting functions, hence its name. | |
57 | // ============================================================================= | |
58 | class StringFormatArg { | |
59 | public: | |
14 | 60 | StringFormatArg (const str& v); |
61 | StringFormatArg (const char& v); | |
62 | StringFormatArg (const uchar& v); | |
63 | StringFormatArg (const qchar& v); | |
0 | 64 | |
65 | #define NUMERIC_FORMAT_ARG(T,C) \ | |
66 | StringFormatArg (const T& v) { \ | |
67 | char valstr[32]; \ | |
68 | sprintf (valstr, "%" #C, v); \ | |
69 | m_val = valstr; \ | |
70 | } | |
71 | ||
14 | 72 | NUMERIC_FORMAT_ARG (int, d) |
73 | NUMERIC_FORMAT_ARG (short, d) | |
74 | NUMERIC_FORMAT_ARG (long, ld) | |
75 | NUMERIC_FORMAT_ARG (uint, u) | |
76 | NUMERIC_FORMAT_ARG (ushort, u) | |
77 | NUMERIC_FORMAT_ARG (ulong, lu) | |
0 | 78 | |
14 | 79 | StringFormatArg (const float& v); |
80 | StringFormatArg (const double& v); | |
81 | StringFormatArg (const char* v); | |
82 | StringFormatArg (const void* v); | |
0 | 83 | |
14 | 84 | template<class T> StringFormatArg (const list<T>& v) { |
0 | 85 | m_val = "{ "; |
86 | uint i = 0; | |
14 | 87 | const bool isString = typeid (T) == typeid (str); |
0 | 88 | |
14 | 89 | for (const T& it : v) { |
90 | if (i++) | |
0 | 91 | m_val += ", "; |
92 | ||
14 | 93 | StringFormatArg arg (it); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
94 | |
14 | 95 | if (isString) |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
96 | m_val += "\"" + arg.value() + "\""; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
97 | else |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
98 | m_val += arg.value(); |
0 | 99 | } |
100 | ||
14 | 101 | if (i) |
0 | 102 | m_val += " "; |
103 | ||
104 | m_val += "}"; | |
105 | } | |
106 | ||
107 | str value() const { | |
108 | return m_val; | |
109 | } | |
110 | private: | |
111 | str m_val; | |
112 | }; | |
113 | ||
114 | // Formatter function | |
14 | 115 | str doFormat (initlist<StringFormatArg> args); |
0 | 116 | |
117 | // printf replacement | |
14 | 118 | void doPrint (FILE* fp, initlist<StringFormatArg> args); |
0 | 119 | |
120 | // Macros to access these functions | |
121 | #ifndef IN_IDE_PARSER | |
122 | # define fmt(...) doFormat({ __VA_ARGS__ }) | |
14 | 123 | # define print(...) doPrint (stdout, { __VA_ARGS__ }) |
124 | # define fprint(FP, ...) doPrint (FP, { __VA_ARGS__ }) | |
0 | 125 | #else |
14 | 126 | str fmt (const char* fmtstr, ...); |
127 | void print (const char* fmtstr, ...); | |
128 | void fprint (FILE* fp, const char* fmtstr, ...); | |
0 | 129 | #endif |
130 | ||
131 | #endif // TYPES_H |