TTKMusicPlayer  4.2.0.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 // as_const defined
44 #if !TTK_HAS_CXX17
45 namespace std
46 {
47 // this adds const to non-const objects
48 template <typename T>
49 Q_DECL_CONSTEXPR typename std::add_const<T>::type &as_const(T &t) noexcept { return t; }
50 // prevent rvalue arguments:
51 template <typename T>
52 void as_const(const T &&) = delete;
53 }
54 #endif
55 
56 #if !TTK_QT_VERSION_CHECK(5,7,0) || TTK_QT_VERSION_CHECK(6,6,0)
57 # define qAsConst std::as_const
58 #endif
59 
60 
61 #ifdef Q_CC_MSVC
62 template <typename T>
63 inline T object_cast(QObject *object) noexcept
64 {
65  T v = qobject_cast<T>(object);
66  return v ? v : TTKStaticCast(T, object);
67 }
68 
69 template <typename T>
70 inline T object_cast(const QObject *object) noexcept
71 {
72  T v = qobject_cast<T>(object);
73  return v ? v : TTKStaticCast(T, object);
74 }
75 #else
76 # define object_cast qobject_cast
77 #endif
78 
79 #ifdef TTK_CAST
80 # define TTKObjectCast(x, y) (object_cast<x>(y))
81 #else
82 # define TTKObjectCast(x, y) ((x)(y))
83 #endif
84 
85 #if defined TTK_CAST && TTK_QT_VERSION_CHECK(5,15,0)
86 # define TTKVoidCast(x) (x)(void*)
87 #else
88 # define TTKVoidCast(x) (x)
89 #endif
90 
91 
92 #if !TTK_QT_VERSION_CHECK(5,0,0) && defined(Q_CC_GNU)
93 # if defined(__GXX_EXPERIMENTAL_CXX0X__) || TTK_HAS_CXX11
94 # define Q_COMPILER_DEFAULT_MEMBERS
95 # define Q_COMPILER_DELETE_MEMBERS
96 # define Q_COMPILER_NULLPTR
97 # define Q_COMPILER_EXPLICIT_OVERRIDES
98 # define Q_COMPILER_CONSTEXPR
99 # endif
100 #endif
101 
102 
103 // C++11 keywords and expressions
104 #ifdef Q_COMPILER_NULLPTR
105 # define TTK_NULLPTR nullptr
106 #else
107 # define TTK_NULLPTR NULL
108 #endif
109 
110 #ifdef Q_COMPILER_DEFAULT_MEMBERS
111 # define TTK_DEFAULT = default
112 #else
113 # define TTK_DEFAULT
114 #endif
115 
116 #ifdef Q_COMPILER_DELETE_MEMBERS
117 # define TTK_DELETE = delete
118 #else
119 # define TTK_DELETE
120 #endif
121 
122 #ifdef Q_COMPILER_EXPLICIT_OVERRIDES
123 # define TTK_OVERRIDE override
124 # define TTK_FINAL final
125 #else
126 # ifndef TTK_OVERRIDE
127 # define TTK_OVERRIDE
128 # endif
129 # ifndef TTK_FINAL
130 # define TTK_FINAL
131 # endif
132 #endif
133 
134 #if defined Q_CC_MSVC && _MSC_VER <= 1800
135 # define constexpr const
136 #endif
137 
138 #if defined Q_COMPILER_CONSTEXPR
139 # if defined(__cpp_constexpr) && __cpp_constexpr >= 201304L
140 # define TTK_CONSTEXPR constexpr
141 # define TTK_RCONSTEXPR constexpr
142 # else
143 # define TTK_CONSTEXPR constexpr
144 # define TTK_RCONSTEXPR const
145 # endif
146 #else
147 # define TTK_CONSTEXPR const
148 # define TTK_RCONSTEXPR const
149 #endif
150 
151 
152 // disable copy
153 #define TTK_DISABLE_COPY(Class) \
154 private: \
155  Class(const Class &) TTK_DELETE; \
156  Class &operator=(const Class &) TTK_DELETE;
157 
158 // disable init and copy
159 #define TTK_DISABLE_INIT_COPY(Class) \
160  TTK_DISABLE_COPY(Class) \
161  Class() TTK_DELETE;
162 
163 // make class name
164 #define TTK_DECLARE_MODULE(Class) \
165 public: \
166  inline static QString className() \
167  { \
168  return #Class; \
169  }
170 
171 
172 // declare list and enum flag
173 #define TTK_DECLARE_LIST(Class) using Class##List = QList<Class>
174 #define TTK_DECLARE_FLAG(Flags, Enum) using Flags = QFlags<Enum>
175 
176 #define TTK_SIGNAL SIGNAL
177 #define TTK_SLOT SLOT
178 
179 #if TTK_QT_VERSION_CHECK(6,0,0)
180 # define qint qintptr
181 #else
182 # define qint long
183 #endif
184 
185 #define TTK_FILE_SUFFIX(fin) fin.suffix().toLower()
186 
187 // marco timer single shot
188 #ifndef _MSC_VER
189 # define TTK_SIGNLE_SHOT(...) TTK_PP_OVERLOAD(__TTK_SIGNLE_SHOT__, __VA_ARGS__)(__VA_ARGS__)
190 #else
191 # define TTK_SIGNLE_SHOT(...) TTK_PP_CAT(TTK_PP_OVERLOAD(__TTK_SIGNLE_SHOT__, __VA_ARGS__)(__VA_ARGS__), TTK_PP_EMPTY())
192 #endif
193 #define __TTK_SIGNLE_SHOT__2(a, s) QTimer::singleShot(TTK_DN_ONCE, this, s(a()));
194 #define __TTK_SIGNLE_SHOT__3(a, b, s) QTimer::singleShot(TTK_DN_ONCE, a, s(b()));
195 #define __TTK_SIGNLE_SHOT__4(a, b, c, s) QTimer::singleShot(a, b, s(c()));
196 
197 
198 // Qt style format
199 using TTKIntSet = QSet<int>; /* int set */
200 using TTKIntList = QList<int>; /* int list */
201 using TTKVariantList = QList<QVariant>; /* variant list */
202 using TTKStringMap = QMap<QString, QString>; /* strings map */
203 using TTKVariantMap = QMap<QString, QVariant>; /* string variant map */
204 using TTKIntStringMap = QMap<qint64, QString>; /* int string map */
205 
206 #if !TTK_QT_VERSION_CHECK(5,10,0)
207 using qsizetype = QIntegerForSizeof<std::size_t>::Signed;
208 #endif
209 
210 #endif // TTKQTGLOBAL_H
Q_DECL_CONSTEXPR std::add_const< T >::type & as_const(T &t) noexcept
Definition: ttkqtglobal.h:49
#define TTKStaticCast(x, y)
Definition: ttkglobal.h:231
#define T(v)
Definition: http_parser.c:237
Definition: ttkcompat.h:39
QList< int > TTKIntList
Definition: ttkqtglobal.h:200
QMap< qint64, QString > TTKIntStringMap
Definition: ttkqtglobal.h:204
QMap< QString, QVariant > TTKVariantMap
Definition: ttkqtglobal.h:203
QSet< int > TTKIntSet
Definition: ttkqtglobal.h:199
QList< QVariant > TTKVariantList
Definition: ttkqtglobal.h:201
#define object_cast
Definition: ttkqtglobal.h:76
QMap< QString, QString > TTKStringMap
Definition: ttkqtglobal.h:202