KConfig

conversioncheck.h
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2006 Thomas Braxton <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #ifndef CONVERSION_CHECK_H
9 #define CONVERSION_CHECK_H
10 
11 #include <QString>
12 #include <QDate>
13 #include <QPoint>
14 #include <QSize>
15 #include <QRect>
16 #include <QVariant>
17 
18 class QColor;
19 class QFont;
20 
21 namespace ConversionCheck
22 {
23 
24 // used to distinguish between supported/unsupported types
25 struct supported { };
26 struct unsupported { };
27 
28 // traits type class to define support for constraints
29 template <typename T>
30 struct QVconvertible {
31  typedef unsupported toQString;
32  typedef unsupported toQVariant;
33 };
34 
35 // constraint classes
36 template <typename T>
37 struct type_toQString {
38  void constraint()
39  {
40  supported x = y;
41  Q_UNUSED(x);
42  }
43  typename QVconvertible<T>::toQString y;
44 };
45 
46 template <typename T>
47 struct type_toQVariant {
48  void constraint()
49  {
50  supported x = y;
51  Q_UNUSED(x);
52  }
53  typename QVconvertible<T>::toQVariant y;
54 };
55 
56 // check if T is convertible to QString thru QVariant
57 // if not supported can't be used in QList<T> functions
58 template <typename T>
59 inline void to_QString()
60 {
61  void (type_toQString<T>::*x)() = &type_toQString<T>::constraint;
62  Q_UNUSED(x);
63 }
64 
65 // check if T is convertible to QVariant & supported in readEntry/writeEntry
66 template <typename T>
67 inline void to_QVariant()
68 {
69  void (type_toQVariant<T>::*x)() = &type_toQVariant<T>::constraint;
70  Q_UNUSED(x);
71 }
72 
73 // define for all types handled in readEntry/writeEntry
74 // string_support - is supported by QVariant(type).toString(),
75 // can be used in QList<T> functions
76 // variant_support - has a QVariant constructor
77 #define QVConversions(type, string_support, variant_support) \
78  template <> struct QVconvertible<type> {\
79  typedef string_support toQString;\
80  typedef variant_support toQVariant;\
81  }
82 
83 // The only types needed here are the types handled in readEntry/writeEntry
84 // the default QVconvertible will take care of the rest.
85 QVConversions(bool, supported, supported);
86 QVConversions(int, supported, supported);
87 QVConversions(unsigned int, supported, supported);
88 QVConversions(long long, supported, supported);
89 QVConversions(unsigned long long, supported, supported);
90 QVConversions(float, supported, supported);
91 QVConversions(double, supported, supported);
92 QVConversions(QString, supported, supported);
93 QVConversions(QColor, unsupported, supported);
94 QVConversions(QFont, supported, supported);
95 QVConversions(QDateTime, unsupported, supported);
96 QVConversions(QDate, unsupported, supported);
97 QVConversions(QSize, unsupported, supported);
98 QVConversions(QRect, unsupported, supported);
99 QVConversions(QPoint, unsupported, supported);
100 QVConversions(QSizeF, unsupported, supported);
101 QVConversions(QRectF, unsupported, supported);
102 QVConversions(QPointF, unsupported, supported);
103 QVConversions(QByteArray, supported, supported);
104 QVConversions(QStringList, unsupported, supported);
105 QVConversions(QVariantList, unsupported, supported);
106 QVConversions(QUrl, supported, supported);
107 QVConversions(QList<QUrl>, unsupported, supported);
108 }
109 
110 #endif
111 
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Aug 5 2020 22:46:14 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.