TTKMusicPlayer  4.1.3.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
ttkqtglobal.h
Go to the documentation of this file.
1 #ifndef TTKQTGLOBAL_H
2 #define TTKQTGLOBAL_H
3 
4 /***************************************************************************
5  * This file is part of the TTK Library Module project
6  * Copyright (C) 2015 - 2025 Greedysky Studio
7 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17 
18  * You should have received a copy of the GNU Lesser General Public License along
19  * with this program; If not, see <http://www.gnu.org/licenses/>.
20  ***************************************************************************/
21 
22 #include <QMap>
23 #include <QSet>
24 #include <QVariant>
25 #include "ttklogger.h"
26 
27 #ifdef QT_DEBUG
28 # define TTK_DEBUG
29 #endif
30 
31 #define TTK_QT_VERSION_CHECK(major, minor, patch) (QT_VERSION >= QT_VERSION_CHECK(major, minor, patch))
32 
33 
34 #ifndef qPrintable
35 # define qPrintable(s) QString(s).toLocal8Bit().constData()
36 #endif
37 
38 #ifndef qUtf8Printable
39 # define qUtf8Printable(s) QString(s).toUtf8().constData()
40 #endif
41 
42 
43 #if !TTK_QT_VERSION_CHECK(5,7,0)
44 // this adds const to non-const objects (like std::as_const)
45 template <typename T>
46 Q_DECL_CONSTEXPR typename std::add_const<T>::type &qAsConst(T &t) noexcept { return t; }
47 // prevent rvalue arguments:
48 template <typename T>
49 void qAsConst(const T &&) = delete;
50 #elif TTK_QT_VERSION_CHECK(6,6,0)
51 # define qAsConst std::as_const
52 #endif
53 
54 
55 #ifdef Q_CC_MSVC
56 template <typename T>
57 inline T object_cast(QObject *object)
58 {
59  T v = qobject_cast<T>(object);
60  return v ? v : TTKStaticCast(T, object);
61 }
62 
63 template <typename T>
64 inline T object_cast(const QObject *object)
65 {
66  T v = qobject_cast<T>(object);
67  return v ? v : TTKStaticCast(T, object);
68 }
69 #else
70 # define object_cast qobject_cast
71 #endif
72 
73 #ifdef TTK_CAST
74 # define TTKObjectCast(x, y) (object_cast<x>(y))
75 #else
76 # define TTKObjectCast(x, y) ((x)(y))
77 #endif
78 
79 #if defined TTK_CAST && TTK_QT_VERSION_CHECK(5,15,0)
80 # define TTKVoidCast(x) (x)(void*)
81 #else
82 # define TTKVoidCast(x) (x)
83 #endif
84 
85 
86 // deprecated function
87 #ifdef Q_CC_MSVC
88 # define TTK_DEPRECATED __declspec(deprecated)
89 # define TTK_DEPRECATED_X(text) __declspec(deprecated(text))
90 #else
91 # define TTK_DEPRECATED __attribute__((__deprecated__))
92 # define TTK_DEPRECATED_X(text) __attribute__((__deprecated__(text)))
93 #endif
94 
95 
96 #if !TTK_QT_VERSION_CHECK(5,0,0) && defined(Q_CC_GNU)
97 # if defined(__GXX_EXPERIMENTAL_CXX0X__) || TTK_HAS_CXX11
98 # define Q_COMPILER_DEFAULT_MEMBERS
99 # define Q_COMPILER_DELETE_MEMBERS
100 # define Q_COMPILER_NULLPTR
101 # define Q_COMPILER_EXPLICIT_OVERRIDES
102 # define Q_COMPILER_CONSTEXPR
103 # endif
104 #endif
105 
106 
107 // C++11 keywords and expressions
108 #ifdef Q_COMPILER_NULLPTR
109 # define TTK_NULLPTR nullptr
110 #else
111 # define TTK_NULLPTR NULL
112 #endif
113 
114 #ifdef Q_COMPILER_DEFAULT_MEMBERS
115 # define TTK_DEFAULT = default
116 #else
117 # define TTK_DEFAULT
118 #endif
119 
120 #ifdef Q_COMPILER_DELETE_MEMBERS
121 # define TTK_DELETE = delete
122 #else
123 # define TTK_DELETE
124 #endif
125 
126 #ifdef Q_COMPILER_EXPLICIT_OVERRIDES
127 # define TTK_OVERRIDE override
128 # define TTK_FINAL final
129 #else
130 # ifndef TTK_OVERRIDE
131 # define TTK_OVERRIDE
132 # endif
133 # ifndef TTK_FINAL
134 # define TTK_FINAL
135 # endif
136 #endif
137 
138 #if defined Q_CC_MSVC && _MSC_VER <= 1800
139 # define constexpr const
140 #endif
141 
142 #if defined Q_COMPILER_CONSTEXPR
143 # if defined(__cpp_constexpr) && __cpp_constexpr >= 201304L
144 # define TTK_CONSTEXPR constexpr
145 # define TTK_RCONSTEXPR constexpr
146 # else
147 # define TTK_CONSTEXPR constexpr
148 # define TTK_RCONSTEXPR const
149 # endif
150 #else
151 # define TTK_CONSTEXPR const
152 # define TTK_RCONSTEXPR const
153 #endif
154 
155 
156 // disable copy
157 #define TTK_DISABLE_COPY(Class) \
158 private: \
159  Class(const Class &) TTK_DELETE; \
160  Class &operator=(const Class &) TTK_DELETE;
161 
162 // disable init and copy
163 #define TTK_DISABLE_INIT_COPY(Class) \
164  TTK_DISABLE_COPY(Class) \
165  Class() TTK_DELETE;
166 
167 // make class name
168 #define TTK_DECLARE_MODULE(Class) \
169 public: \
170  inline static QString className() \
171  { \
172  return #Class; \
173  }
174 
175 
176 // declare list and enum flag
177 #define TTK_DECLARE_LIST(Class) using Class##List = QList<Class>
178 #define TTK_DECLARE_FLAG(Flags, Enum) using Flags = QFlags<Enum>
179 
180 #define TTK_SIGNAL SIGNAL
181 #define TTK_SLOT SLOT
182 
183 #if TTK_QT_VERSION_CHECK(6,0,0)
184 # define qint qintptr
185 #else
186 # define qint long
187 #endif
188 
189 #define TTK_FILE_SUFFIX(fin) fin.suffix().toLower()
190 
191 // marco timer single shot
192 #ifndef _MSC_VER
193 # define TTK_SIGNLE_SHOT(...) TTK_PP_OVERLOAD(__TTK_SIGNLE_SHOT__, __VA_ARGS__)(__VA_ARGS__)
194 #else
195 # define TTK_SIGNLE_SHOT(...) TTK_PP_CAT(TTK_PP_OVERLOAD(__TTK_SIGNLE_SHOT__, __VA_ARGS__)(__VA_ARGS__), TTK_PP_EMPTY())
196 #endif
197 #define __TTK_SIGNLE_SHOT__2(a, s) QTimer::singleShot(TTK_DN_ONCE, this, s(a()));
198 #define __TTK_SIGNLE_SHOT__3(a, b, s) QTimer::singleShot(TTK_DN_ONCE, a, s(b()));
199 #define __TTK_SIGNLE_SHOT__4(a, b, c, s) QTimer::singleShot(a, b, s(c()));
200 
201 
202 // Qt style format
203 using TTKIntSet = QSet<int>; /* int set */
204 using TTKIntList = QList<int>; /* int list */
205 using TTKVariantList = QList<QVariant>; /* variant list */
206 using TTKStringMap = QMap<QString, QString>; /* strings map */
207 using TTKVariantMap = QMap<QString, QVariant>; /* string variant map */
208 using TTKIntStringMap = QMap<qint64, QString>; /* int string map */
209 
210 #if !TTK_QT_VERSION_CHECK(5,10,0)
211 using qsizetype = QIntegerForSizeof<std::size_t>::Signed;
212 #endif
213 
214 #endif // TTKQTGLOBAL_H
#define TTKStaticCast(x, y)
Definition: ttkglobal.h:159
#define T(v)
Definition: http_parser.c:237
QList< int > TTKIntList
Definition: ttkqtglobal.h:204
#define qAsConst
Definition: ttkqtglobal.h:51
QMap< qint64, QString > TTKIntStringMap
Definition: ttkqtglobal.h:208
QMap< QString, QVariant > TTKVariantMap
Definition: ttkqtglobal.h:207
QSet< int > TTKIntSet
Definition: ttkqtglobal.h:203
QList< QVariant > TTKVariantList
Definition: ttkqtglobal.h:205
#define object_cast
Definition: ttkqtglobal.h:70
QMap< QString, QString > TTKStringMap
Definition: ttkqtglobal.h:206