Warning: That file was not part of the compilation database. It may have many parsing errors.
1 | /* |
---|---|
2 | This file is part of the KDE libraries |
3 | Copyright (c) 2006 Thomas Braxton <brax108@cox.net> |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. |
9 | |
10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. |
19 | */ |
20 | |
21 | |
22 | #ifndef CONVERSION_CHECK_H |
23 | #define CONVERSION_CHECK_H |
24 | |
25 | #include <QtCore/QString> |
26 | #include <QtGui/QColor> |
27 | #include <QtGui/QFont> |
28 | #include <QtCore/QDate> |
29 | #include <QtCore/QPoint> |
30 | #include <QtCore/QSize> |
31 | #include <QtCore/QRect> |
32 | #include <kurl.h> |
33 | #include <QtCore/QVariant> |
34 | |
35 | namespace ConversionCheck { |
36 | |
37 | // used to distinguish between supported/unsupported types |
38 | struct supported { }; |
39 | struct unsupported { }; |
40 | |
41 | // traits type class to define support for constraints |
42 | template <typename T> |
43 | struct QVconvertible |
44 | { |
45 | typedef unsupported toQString; |
46 | typedef unsupported toQVariant; |
47 | }; |
48 | |
49 | // constraint classes |
50 | template <typename T> |
51 | struct type_toQString |
52 | { |
53 | void constraint() { supported x = y; Q_UNUSED(x); } |
54 | typename QVconvertible<T>::toQString y; |
55 | }; |
56 | |
57 | template <typename T> |
58 | struct type_toQVariant |
59 | { |
60 | void constraint() { supported x = y; Q_UNUSED(x); } |
61 | typename QVconvertible<T>::toQVariant y; |
62 | }; |
63 | |
64 | |
65 | // check if T is convertible to QString thru QVariant |
66 | // if not supported can't be used in QList<T> functions |
67 | template <typename T> |
68 | inline void to_QString() |
69 | { |
70 | void (type_toQString<T>::*x)() = &type_toQString<T>::constraint; |
71 | Q_UNUSED(x); |
72 | } |
73 | |
74 | // check if T is convertible to QVariant & supported in readEntry/writeEntry |
75 | template <typename T> |
76 | inline void to_QVariant() |
77 | { |
78 | void (type_toQVariant<T>::*x)() = &type_toQVariant<T>::constraint; |
79 | Q_UNUSED(x); |
80 | } |
81 | |
82 | // define for all types handled in readEntry/writeEntry |
83 | // string_support - is supported by QVariant(type).toString(), |
84 | // can be used in QList<T> functions |
85 | // variant_support - has a QVariant constructor |
86 | #define QVConversions(type, string_support, variant_support) \ |
87 | template <> struct QVconvertible<type> {\ |
88 | typedef string_support toQString;\ |
89 | typedef variant_support toQVariant;\ |
90 | } |
91 | |
92 | // The only types needed here are the types handled in readEntry/writeEntry |
93 | // the default QVconvertible will take care of the rest. |
94 | QVConversions(bool, supported, supported); |
95 | QVConversions(int, supported, supported); |
96 | QVConversions(unsigned int, supported, supported); |
97 | QVConversions(long long, supported, supported); |
98 | QVConversions(unsigned long long, supported, supported); |
99 | QVConversions(float, supported, supported); |
100 | QVConversions(double, supported, supported); |
101 | QVConversions(QString, supported, supported); |
102 | QVConversions(QColor, unsupported, supported); |
103 | QVConversions(QFont, supported, supported); |
104 | QVConversions(QDateTime, unsupported, supported); |
105 | QVConversions(QDate, unsupported, supported); |
106 | QVConversions(QSize, unsupported, supported); |
107 | QVConversions(QRect, unsupported, supported); |
108 | QVConversions(QPoint, unsupported, supported); |
109 | QVConversions(QSizeF, unsupported, supported); |
110 | QVConversions(QRectF, unsupported, supported); |
111 | QVConversions(QPointF, unsupported, supported); |
112 | QVConversions(QByteArray, supported, supported); |
113 | QVConversions(QStringList, unsupported, supported); |
114 | QVConversions(QVariantList, unsupported, supported); |
115 | QVConversions(KUrl, supported, supported); |
116 | QVConversions(KUrl::List, unsupported, supported); |
117 | } |
118 | |
119 | #endif |
120 | |
121 |
Warning: That file was not part of the compilation database. It may have many parsing errors.