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
35namespace ConversionCheck {
36
37// used to distinguish between supported/unsupported types
38struct supported { };
39struct unsupported { };
40
41// traits type class to define support for constraints
42template <typename T>
43struct QVconvertible
44{
45 typedef unsupported toQString;
46 typedef unsupported toQVariant;
47};
48
49// constraint classes
50template <typename T>
51struct type_toQString
52{
53 void constraint() { supported x = y; Q_UNUSED(x); }
54 typename QVconvertible<T>::toQString y;
55};
56
57template <typename T>
58struct 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
67template <typename T>
68inline 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
75template <typename T>
76inline 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) \
87template <> 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.
94QVConversions(bool, supported, supported);
95QVConversions(int, supported, supported);
96QVConversions(unsigned int, supported, supported);
97QVConversions(long long, supported, supported);
98QVConversions(unsigned long long, supported, supported);
99QVConversions(float, supported, supported);
100QVConversions(double, supported, supported);
101QVConversions(QString, supported, supported);
102QVConversions(QColor, unsupported, supported);
103QVConversions(QFont, supported, supported);
104QVConversions(QDateTime, unsupported, supported);
105QVConversions(QDate, unsupported, supported);
106QVConversions(QSize, unsupported, supported);
107QVConversions(QRect, unsupported, supported);
108QVConversions(QPoint, unsupported, supported);
109QVConversions(QSizeF, unsupported, supported);
110QVConversions(QRectF, unsupported, supported);
111QVConversions(QPointF, unsupported, supported);
112QVConversions(QByteArray, supported, supported);
113QVConversions(QStringList, unsupported, supported);
114QVConversions(QVariantList, unsupported, supported);
115QVConversions(KUrl, supported, supported);
116QVConversions(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.