src/types.h

Sun, 11 Aug 2013 13:33:57 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 11 Aug 2013 13:33:57 +0300
changeset 16
a8c78391e414
parent 14
825d9ed1ee01
child 20
a5457405cc9b
permissions
-rw-r--r--

Only add 'widgets' to QT in the project file in Qt5 - Qt4 doesn't have it and using it results in a warning.

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
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #ifndef TYPES_H
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #define TYPES_H
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "main.h"
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include <QString>
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include <QList>
3
d0b278fd29d5 Implemented wad path list
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
25 #include <QVariant>
0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 typedef QString str;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 typedef QChar qchar;
3
d0b278fd29d5 Implemented wad path list
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
29 typedef QVariant var;
0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 template<class T> using list = QList<T>;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 typedef unsigned int uint;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 typedef unsigned short ushort;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 typedef unsigned long ulong;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 template<class T> using initlist = std::initializer_list<T>;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 using std::size_t;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
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
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 // =============================================================================
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 // =============================================================================
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 // StringFormatArg
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 //
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 // Converts a given value into a string that can be retrieved with ::value ().
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 // Used as the argument type to the formatting functions, hence its name.
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 // =============================================================================
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 class StringFormatArg {
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 public:
14
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
60 StringFormatArg (const str& v);
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
61 StringFormatArg (const char& v);
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
62 StringFormatArg (const uchar& v);
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
63 StringFormatArg (const qchar& v);
0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 #define NUMERIC_FORMAT_ARG(T,C) \
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 StringFormatArg (const T& v) { \
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 char valstr[32]; \
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 sprintf (valstr, "%" #C, v); \
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 m_val = valstr; \
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 }
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71
14
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
72 NUMERIC_FORMAT_ARG (int, d)
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
73 NUMERIC_FORMAT_ARG (short, d)
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
74 NUMERIC_FORMAT_ARG (long, ld)
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
75 NUMERIC_FORMAT_ARG (uint, u)
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
76 NUMERIC_FORMAT_ARG (ushort, u)
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
77 NUMERIC_FORMAT_ARG (ulong, lu)
0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78
14
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
79 StringFormatArg (const float& v);
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
80 StringFormatArg (const double& v);
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
81 StringFormatArg (const char* v);
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
82 StringFormatArg (const void* v);
0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83
14
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
84 template<class T> StringFormatArg (const list<T>& v) {
0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 m_val = "{ ";
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 uint i = 0;
14
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
87 const bool isString = typeid (T) == typeid (str);
0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88
14
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
89 for (const T& it : v) {
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
90 if (i++)
0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 m_val += ", ";
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92
14
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
93 StringFormatArg arg (it);
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents: 3
diff changeset
94
14
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
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
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 }
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100
14
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
101 if (i)
0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 m_val += " ";
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 m_val += "}";
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 }
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 str value() const {
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 return m_val;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 }
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 private:
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 str m_val;
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 };
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 // Formatter function
14
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
115 str doFormat (initlist<StringFormatArg> args);
0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 // printf replacement
14
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
118 void doPrint (FILE* fp, initlist<StringFormatArg> args);
0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 // Macros to access these functions
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 #ifndef IN_IDE_PARSER
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 # define fmt(...) doFormat({ __VA_ARGS__ })
14
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
123 # define print(...) doPrint (stdout, { __VA_ARGS__ })
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
124 # define fprint(FP, ...) doPrint (FP, { __VA_ARGS__ })
0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 #else
14
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
126 str fmt (const char* fmtstr, ...);
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
127 void print (const char* fmtstr, ...);
825d9ed1ee01 more consistency
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
128 void fprint (FILE* fp, const char* fmtstr, ...);
0
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 #endif
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130
bb264814dd81 Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 #endif // TYPES_H

mercurial