1 /* |
1 /* |
2 * ZCinema: Zandronum demo launcher |
2 * ZCinema: Zandronum demo launcher |
3 * Copyright (C) 2013 Santeri Piippo |
3 * Copyright (C) 2013-2015 Teemu Piippo |
4 * |
4 * |
5 * This program is free software: you can redistribute it and/or modify |
5 * This program is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License as published by |
6 * it under the terms of the GNU General Public License as published by |
7 * the Free Software Foundation, either version 3 of the License, or |
7 * the Free Software Foundation, either version 3 of the License, or |
8 * (at your option) any later version. |
8 * (at your option) any later version. |
14 * |
14 * |
15 * You should have received a copy of the GNU General Public License |
15 * You should have received a copy of the GNU General Public License |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 */ |
17 */ |
18 |
18 |
19 #ifndef ZCINEMA_TYPES_H |
19 #pragma once |
20 #define ZCINEMA_TYPES_H |
|
21 |
|
22 #include "main.h" |
20 #include "main.h" |
23 #include <QString> |
21 #include <QString> |
24 #include <QList> |
22 #include <QList> |
25 #include <QVariant> |
23 #include <QVariant> |
26 |
24 |
27 typedef QString str; |
|
28 template<class T> using list = QList<T>; |
25 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>; |
26 template<class T> using initlist = std::initializer_list<T>; |
33 using std::size_t; |
27 using std::size_t; |
34 |
28 |
35 typedef qint8 int8; |
29 typedef qint8 int8; |
36 typedef qint16 int16; |
30 typedef qint16 int16; |
43 |
37 |
44 #ifdef IN_IDE_PARSER // :| |
38 #ifdef IN_IDE_PARSER // :| |
45 typedef void FILE; |
39 typedef void FILE; |
46 #endif |
40 #endif |
47 |
41 |
48 // ============================================================================= |
42 struct ZandronumVersion |
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
43 { |
50 // ============================================================================= |
44 ZandronumVersion (QString name, bool isRelease, QString binaryPath) : |
51 // StringFormatArg |
45 name (name), |
52 // |
46 binaryPath (binaryPath), |
53 // Converts a given value into a string that can be retrieved with ::value (). |
47 isRelease (isRelease) {} |
54 // Used as the argument type to the formatting functions, hence its name. |
48 |
55 // ============================================================================= |
49 ZandronumVersion() : |
56 class StringFormatArg { |
50 isRelease (false) {} |
57 public: |
51 |
58 StringFormatArg (const str& v); |
52 QString name; |
59 StringFormatArg (const char& v); |
53 QString binaryPath; |
60 StringFormatArg (const uchar& v); |
54 bool isRelease; |
61 StringFormatArg (const QChar& v); |
|
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 |
|
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) |
|
76 |
|
77 StringFormatArg (const float& v); |
|
78 StringFormatArg (const double& v); |
|
79 StringFormatArg (const char* v); |
|
80 StringFormatArg (const void* v); |
|
81 |
|
82 template<class T> StringFormatArg (const list<T>& v) { |
|
83 m_val = "{ "; |
|
84 uint i = 0; |
|
85 const bool isString = typeid (T) == typeid (str); |
|
86 |
|
87 for (const T& it : v) { |
|
88 if (i++) |
|
89 m_val += ", "; |
|
90 |
|
91 StringFormatArg arg (it); |
|
92 |
|
93 if (isString) |
|
94 m_val += "\"" + arg.value() + "\""; |
|
95 else |
|
96 m_val += arg.value(); |
|
97 } |
|
98 |
|
99 if (i) |
|
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 }; |
55 }; |
111 |
56 |
112 // Formatter function |
57 Q_DECLARE_METATYPE (ZandronumVersion) |
113 str doFormat (initlist<StringFormatArg> args); |
58 typedef QList<ZandronumVersion> VersionList; |
114 |
59 |
115 // printf replacement |
|
116 void doPrint (FILE* fp, initlist<StringFormatArg> args); |
|
117 |
|
118 // Macros to access these functions |
|
119 #ifndef IN_IDE_PARSER |
|
120 # define fmt(...) doFormat({ __VA_ARGS__ }) |
|
121 # define print(...) doPrint (stdout, { __VA_ARGS__ }) |
|
122 # define fprint(FP, ...) doPrint (FP, { __VA_ARGS__ }) |
|
123 #else |
|
124 str fmt (const char* fmtstr, ...); |
|
125 void print (const char* fmtstr, ...); |
|
126 void fprint (FILE* fp, const char* fmtstr, ...); |
|
127 #endif |
|
128 |
|
129 #endif // ZCINEMA_TYPES_H |
|