src/types.h

Sun, 08 Sep 2013 22:37:59 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 08 Sep 2013 22:37:59 +0300
changeset 32
91e9c2b710dd
parent 30
6b82f6a3ad53
child 37
c82a86ea87be
permissions
-rw-r--r--

removed unused 'item' variable

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

mercurial