Changeset View
Changeset View
Standalone View
Standalone View
core/qtcompat_p.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (c) 2017 Kevin Funk <kfunk@.kde.org | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or modify it | ||||
5 | under the terms of the GNU Library General Public License as published by | ||||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||||
7 | option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||||
12 | License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Library General Public License | ||||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||||
17 | 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #ifndef KDEVELOP_QTCOMPAT_P_H | ||||
21 | #define KDEVELOP_QTCOMPAT_P_H | ||||
22 | | ||||
23 | #include <qglobal.h> | ||||
24 | | ||||
25 | #include <QDir> | ||||
26 | | ||||
27 | #if QT_VERSION < QT_VERSION_CHECK(5,7,0) | ||||
28 | namespace QtPrivate | ||||
29 | { | ||||
30 | template <typename T> struct QAddConst { | ||||
31 | typedef const T Type; | ||||
32 | }; | ||||
33 | } | ||||
34 | | ||||
35 | // this adds const to non-const objects (like std::as_const) | ||||
36 | template <typename T> | ||||
37 | Q_DECL_CONSTEXPR typename QtPrivate::QAddConst<T>::Type &qAsConst(T &t) Q_DECL_NOTHROW { return t; } | ||||
38 | // prevent rvalue arguments: | ||||
39 | template <typename T> | ||||
40 | void qAsConst(const T &&) Q_DECL_EQ_DELETE; | ||||
41 | #endif | ||||
42 | | ||||
43 | // compat for Q_FALLTHROUGH | ||||
44 | #if QT_VERSION < QT_VERSION_CHECK(5,8,0) | ||||
45 | | ||||
46 | #if defined(__has_cpp_attribute) | ||||
47 | # if __has_cpp_attribute(fallthrough) | ||||
48 | # define Q_FALLTHROUGH() [[fallthrough]] | ||||
49 | # elif __has_cpp_attribute(clang::fallthrough) | ||||
50 | # define Q_FALLTHROUGH() [[clang::fallthrough]] | ||||
51 | # elif __has_cpp_attribute(gnu::fallthrough) | ||||
52 | # define Q_FALLTHROUGH() [[gnu::fallthrough]] | ||||
53 | # endif | ||||
54 | #endif | ||||
55 | | ||||
56 | #ifndef Q_FALLTHROUGH | ||||
57 | # if defined(__GNUC__) && !defined(__INTEL_COMPILER) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 700) | ||||
58 | # define Q_FALLTHROUGH() __attribute__((fallthrough)) | ||||
59 | # else | ||||
60 | # define Q_FALLTHROUGH() (void)0 | ||||
61 | # endif | ||||
62 | #endif | ||||
63 | | ||||
64 | #endif | ||||
65 | | ||||
66 | namespace QtCompat { | ||||
67 | // TODO: Just use QDir::listSeparator once we depend on Qt 5.6 | ||||
68 | Q_DECL_CONSTEXPR inline QChar listSeparator() Q_DECL_NOTHROW | ||||
69 | { | ||||
70 | #if QT_VERSION < QT_VERSION_CHECK(5,6,0) | ||||
71 | #ifdef Q_OS_WIN | ||||
72 | return QLatin1Char(';'); | ||||
73 | #else | ||||
74 | return QLatin1Char(':'); | ||||
75 | #endif | ||||
76 | #else | ||||
77 | return QDir::listSeparator(); | ||||
78 | #endif | ||||
79 | } | ||||
80 | } | ||||
81 | | ||||
82 | #endif |