Sun, 08 Sep 2013 17:44:58 +0300
the demo auth checksums need to be read in with readString and not operator>>
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 | |
20
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
19 | #ifndef ZANDEMO_TYPES_H |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
20 | #define ZANDEMO_TYPES_H |
0 | 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 | template<class T> using list = QList<T>; | |
29 | typedef unsigned int uint; | |
30 | typedef unsigned short ushort; | |
31 | typedef unsigned long ulong; | |
32 | template<class T> using initlist = std::initializer_list<T>; | |
33 | using std::size_t; | |
34 | ||
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
35 | typedef qint8 int8; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
36 | typedef qint16 int16; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
37 | typedef qint32 int32; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
38 | typedef qint64 int64; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
39 | typedef quint8 uint8; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
40 | typedef quint16 uint16; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
41 | typedef quint32 uint32; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
42 | typedef quint64 uint64; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
43 | |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
44 | #ifdef IN_IDE_PARSER // :| |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
45 | typedef void FILE; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
46 | #endif |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
47 | |
0 | 48 | // ============================================================================= |
49 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
50 | // ============================================================================= | |
51 | // StringFormatArg | |
52 | // | |
53 | // Converts a given value into a string that can be retrieved with ::value (). | |
54 | // Used as the argument type to the formatting functions, hence its name. | |
55 | // ============================================================================= | |
56 | class StringFormatArg { | |
57 | public: | |
14 | 58 | StringFormatArg (const str& v); |
59 | StringFormatArg (const char& v); | |
60 | StringFormatArg (const uchar& v); | |
21
99225eac33ba
use proper names QVariant and QChar instead of ambigous/dumb "var" and "qchar"
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
61 | StringFormatArg (const QChar& v); |
0 | 62 | |
63 | #define NUMERIC_FORMAT_ARG(T,C) \ | |
64 | StringFormatArg (const T& v) { \ | |
65 | char valstr[32]; \ | |
66 | sprintf (valstr, "%" #C, v); \ | |
67 | m_val = valstr; \ | |
68 | } | |
69 | ||
14 | 70 | NUMERIC_FORMAT_ARG (int, d) |
71 | NUMERIC_FORMAT_ARG (short, d) | |
72 | NUMERIC_FORMAT_ARG (long, ld) | |
73 | NUMERIC_FORMAT_ARG (uint, u) | |
74 | NUMERIC_FORMAT_ARG (ushort, u) | |
75 | NUMERIC_FORMAT_ARG (ulong, lu) | |
0 | 76 | |
14 | 77 | StringFormatArg (const float& v); |
78 | StringFormatArg (const double& v); | |
79 | StringFormatArg (const char* v); | |
80 | StringFormatArg (const void* v); | |
0 | 81 | |
14 | 82 | template<class T> StringFormatArg (const list<T>& v) { |
0 | 83 | m_val = "{ "; |
84 | uint i = 0; | |
14 | 85 | const bool isString = typeid (T) == typeid (str); |
0 | 86 | |
14 | 87 | for (const T& it : v) { |
88 | if (i++) | |
0 | 89 | m_val += ", "; |
90 | ||
14 | 91 | StringFormatArg arg (it); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
92 | |
14 | 93 | if (isString) |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
94 | m_val += "\"" + arg.value() + "\""; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
95 | else |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
96 | m_val += arg.value(); |
0 | 97 | } |
98 | ||
14 | 99 | if (i) |
0 | 100 | m_val += " "; |
101 | ||
102 | m_val += "}"; | |
103 | } | |
104 | ||
105 | str value() const { | |
106 | return m_val; | |
107 | } | |
108 | private: | |
109 | str m_val; | |
110 | }; | |
111 | ||
112 | // Formatter function | |
14 | 113 | str doFormat (initlist<StringFormatArg> args); |
0 | 114 | |
115 | // printf replacement | |
14 | 116 | void doPrint (FILE* fp, initlist<StringFormatArg> args); |
0 | 117 | |
118 | // Macros to access these functions | |
119 | #ifndef IN_IDE_PARSER | |
120 | # define fmt(...) doFormat({ __VA_ARGS__ }) | |
14 | 121 | # define print(...) doPrint (stdout, { __VA_ARGS__ }) |
122 | # define fprint(FP, ...) doPrint (FP, { __VA_ARGS__ }) | |
0 | 123 | #else |
14 | 124 | str fmt (const char* fmtstr, ...); |
125 | void print (const char* fmtstr, ...); | |
126 | void fprint (FILE* fp, const char* fmtstr, ...); | |
0 | 127 | #endif |
128 | ||
20
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
129 | #endif // ZANDEMO_TYPES_H |