author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 10:37:55 +0300 | |
changeset 33 | 3e2da88830cd |
parent 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtCore module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#ifndef QVARIANT_H |
|
43 |
#define QVARIANT_H |
|
44 |
||
45 |
#include <QtCore/qatomic.h> |
|
46 |
#include <QtCore/qbytearray.h> |
|
47 |
#include <QtCore/qlist.h> |
|
48 |
#include <QtCore/qmetatype.h> |
|
49 |
#include <QtCore/qmap.h> |
|
50 |
#include <QtCore/qhash.h> |
|
51 |
#include <QtCore/qstring.h> |
|
52 |
||
53 |
QT_BEGIN_HEADER |
|
54 |
||
55 |
QT_BEGIN_NAMESPACE |
|
56 |
||
57 |
QT_MODULE(Core) |
|
58 |
||
59 |
class QBitArray; |
|
60 |
class QDataStream; |
|
61 |
class QDate; |
|
62 |
class QDateTime; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
63 |
class QEasingCurve; |
0 | 64 |
class QLine; |
65 |
class QLineF; |
|
66 |
class QLocale; |
|
67 |
class QMatrix; |
|
68 |
class QTransform; |
|
69 |
class QStringList; |
|
70 |
class QTime; |
|
71 |
class QPoint; |
|
72 |
class QPointF; |
|
73 |
class QSize; |
|
74 |
class QSizeF; |
|
75 |
class QRect; |
|
76 |
class QRectF; |
|
77 |
#ifndef QT_NO_REGEXP |
|
78 |
class QRegExp; |
|
79 |
#endif |
|
80 |
class QTextFormat; |
|
81 |
class QTextLength; |
|
82 |
class QUrl; |
|
83 |
class QVariant; |
|
84 |
class QVariantComparisonHelper; |
|
85 |
||
86 |
#ifndef QT_NO_MEMBER_TEMPLATES |
|
87 |
template <typename T> |
|
88 |
inline QVariant qVariantFromValue(const T &); |
|
89 |
||
90 |
template <typename T> |
|
91 |
inline void qVariantSetValue(QVariant &, const T &); |
|
92 |
||
93 |
template<typename T> |
|
94 |
inline T qVariantValue(const QVariant &); |
|
95 |
||
96 |
template<typename T> |
|
97 |
inline bool qVariantCanConvert(const QVariant &); |
|
98 |
#endif |
|
99 |
||
100 |
class Q_CORE_EXPORT QVariant |
|
101 |
{ |
|
102 |
public: |
|
103 |
enum Type { |
|
104 |
Invalid = 0, |
|
105 |
||
106 |
Bool = 1, |
|
107 |
Int = 2, |
|
108 |
UInt = 3, |
|
109 |
LongLong = 4, |
|
110 |
ULongLong = 5, |
|
111 |
Double = 6, |
|
112 |
Char = 7, |
|
113 |
Map = 8, |
|
114 |
List = 9, |
|
115 |
String = 10, |
|
116 |
StringList = 11, |
|
117 |
ByteArray = 12, |
|
118 |
BitArray = 13, |
|
119 |
Date = 14, |
|
120 |
Time = 15, |
|
121 |
DateTime = 16, |
|
122 |
Url = 17, |
|
123 |
Locale = 18, |
|
124 |
Rect = 19, |
|
125 |
RectF = 20, |
|
126 |
Size = 21, |
|
127 |
SizeF = 22, |
|
128 |
Line = 23, |
|
129 |
LineF = 24, |
|
130 |
Point = 25, |
|
131 |
PointF = 26, |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
132 |
RegExp = 27, |
0 | 133 |
Hash = 28, |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
134 |
EasingCurve = 29, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
135 |
LastCoreType = EasingCurve, |
0 | 136 |
|
137 |
// value 62 is internally reserved |
|
138 |
#ifdef QT3_SUPPORT |
|
139 |
ColorGroup = 63, |
|
140 |
#endif |
|
141 |
Font = 64, |
|
142 |
Pixmap = 65, |
|
143 |
Brush = 66, |
|
144 |
Color = 67, |
|
145 |
Palette = 68, |
|
146 |
Icon = 69, |
|
147 |
Image = 70, |
|
148 |
Polygon = 71, |
|
149 |
Region = 72, |
|
150 |
Bitmap = 73, |
|
151 |
Cursor = 74, |
|
152 |
SizePolicy = 75, |
|
153 |
KeySequence = 76, |
|
154 |
Pen = 77, |
|
155 |
TextLength = 78, |
|
156 |
TextFormat = 79, |
|
157 |
Matrix = 80, |
|
158 |
Transform = 81, |
|
159 |
Matrix4x4 = 82, |
|
160 |
Vector2D = 83, |
|
161 |
Vector3D = 84, |
|
162 |
Vector4D = 85, |
|
163 |
Quaternion = 86, |
|
164 |
LastGuiType = Quaternion, |
|
165 |
||
166 |
UserType = 127, |
|
167 |
#ifdef QT3_SUPPORT |
|
168 |
IconSet = Icon, |
|
169 |
CString = ByteArray, |
|
170 |
PointArray = Polygon, |
|
171 |
#endif |
|
172 |
LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type |
|
173 |
}; |
|
174 |
||
175 |
inline QVariant(); |
|
176 |
~QVariant(); |
|
177 |
QVariant(Type type); |
|
178 |
QVariant(int typeOrUserType, const void *copy); |
|
179 |
QVariant(int typeOrUserType, const void *copy, uint flags); |
|
180 |
QVariant(const QVariant &other); |
|
181 |
||
182 |
#ifndef QT_NO_DATASTREAM |
|
183 |
QVariant(QDataStream &s); |
|
184 |
#endif |
|
185 |
||
186 |
QVariant(int i); |
|
187 |
QVariant(uint ui); |
|
188 |
QVariant(qlonglong ll); |
|
189 |
QVariant(qulonglong ull); |
|
190 |
QVariant(bool b); |
|
191 |
QVariant(double d); |
|
192 |
QVariant(float f) { d.is_null = false; d.type = QMetaType::Float; d.data.f = f; } |
|
193 |
#ifndef QT_NO_CAST_FROM_ASCII |
|
194 |
QT_ASCII_CAST_WARN_CONSTRUCTOR QVariant(const char *str); |
|
195 |
#endif |
|
196 |
||
197 |
QVariant(const QByteArray &bytearray); |
|
198 |
QVariant(const QBitArray &bitarray); |
|
199 |
QVariant(const QString &string); |
|
200 |
QVariant(const QLatin1String &string); |
|
201 |
QVariant(const QStringList &stringlist); |
|
202 |
QVariant(const QChar &qchar); |
|
203 |
QVariant(const QDate &date); |
|
204 |
QVariant(const QTime &time); |
|
205 |
QVariant(const QDateTime &datetime); |
|
206 |
QVariant(const QList<QVariant> &list); |
|
207 |
QVariant(const QMap<QString,QVariant> &map); |
|
208 |
QVariant(const QHash<QString,QVariant> &hash); |
|
209 |
#ifndef QT_NO_GEOM_VARIANT |
|
210 |
QVariant(const QSize &size); |
|
211 |
QVariant(const QSizeF &size); |
|
212 |
QVariant(const QPoint &pt); |
|
213 |
QVariant(const QPointF &pt); |
|
214 |
QVariant(const QLine &line); |
|
215 |
QVariant(const QLineF &line); |
|
216 |
QVariant(const QRect &rect); |
|
217 |
QVariant(const QRectF &rect); |
|
218 |
#endif |
|
219 |
QVariant(const QUrl &url); |
|
220 |
QVariant(const QLocale &locale); |
|
221 |
#ifndef QT_NO_REGEXP |
|
222 |
QVariant(const QRegExp ®Exp); |
|
223 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
224 |
#ifndef QT_BOOTSTRAPPED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
225 |
QVariant(const QEasingCurve &easing); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
226 |
#endif |
0 | 227 |
QVariant(Qt::GlobalColor color); |
228 |
||
229 |
QVariant& operator=(const QVariant &other); |
|
230 |
||
231 |
Type type() const; |
|
232 |
int userType() const; |
|
233 |
const char *typeName() const; |
|
234 |
||
235 |
bool canConvert(Type t) const; |
|
236 |
bool convert(Type t); |
|
237 |
||
238 |
#ifdef QT3_SUPPORT |
|
239 |
inline QT3_SUPPORT bool canCast(Type t) const |
|
240 |
{ return canConvert(t); } |
|
241 |
inline QT3_SUPPORT bool cast(Type t) |
|
242 |
{ return convert(t); } |
|
243 |
#endif |
|
244 |
||
245 |
inline bool isValid() const; |
|
246 |
bool isNull() const; |
|
247 |
||
248 |
void clear(); |
|
249 |
||
250 |
void detach(); |
|
251 |
inline bool isDetached() const; |
|
252 |
||
253 |
int toInt(bool *ok = 0) const; |
|
254 |
uint toUInt(bool *ok = 0) const; |
|
255 |
qlonglong toLongLong(bool *ok = 0) const; |
|
256 |
qulonglong toULongLong(bool *ok = 0) const; |
|
257 |
bool toBool() const; |
|
258 |
double toDouble(bool *ok = 0) const; |
|
259 |
float toFloat(bool *ok = 0) const; |
|
260 |
qreal toReal(bool *ok = 0) const; |
|
261 |
QByteArray toByteArray() const; |
|
262 |
QBitArray toBitArray() const; |
|
263 |
QString toString() const; |
|
264 |
QStringList toStringList() const; |
|
265 |
QChar toChar() const; |
|
266 |
QDate toDate() const; |
|
267 |
QTime toTime() const; |
|
268 |
QDateTime toDateTime() const; |
|
269 |
QList<QVariant> toList() const; |
|
270 |
QMap<QString, QVariant> toMap() const; |
|
271 |
QHash<QString, QVariant> toHash() const; |
|
272 |
||
273 |
#ifndef QT_NO_GEOM_VARIANT |
|
274 |
QPoint toPoint() const; |
|
275 |
QPointF toPointF() const; |
|
276 |
QRect toRect() const; |
|
277 |
QSize toSize() const; |
|
278 |
QSizeF toSizeF() const; |
|
279 |
QLine toLine() const; |
|
280 |
QLineF toLineF() const; |
|
281 |
QRectF toRectF() const; |
|
282 |
#endif |
|
283 |
QUrl toUrl() const; |
|
284 |
QLocale toLocale() const; |
|
285 |
#ifndef QT_NO_REGEXP |
|
286 |
QRegExp toRegExp() const; |
|
287 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
288 |
#ifndef QT_BOOTSTRAPPED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
289 |
QEasingCurve toEasingCurve() const; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
290 |
#endif |
0 | 291 |
|
292 |
#ifdef QT3_SUPPORT |
|
293 |
inline QT3_SUPPORT int &asInt(); |
|
294 |
inline QT3_SUPPORT uint &asUInt(); |
|
295 |
inline QT3_SUPPORT qlonglong &asLongLong(); |
|
296 |
inline QT3_SUPPORT qulonglong &asULongLong(); |
|
297 |
inline QT3_SUPPORT bool &asBool(); |
|
298 |
inline QT3_SUPPORT double &asDouble(); |
|
299 |
inline QT3_SUPPORT QByteArray &asByteArray(); |
|
300 |
inline QT3_SUPPORT QBitArray &asBitArray(); |
|
301 |
inline QT3_SUPPORT QString &asString(); |
|
302 |
inline QT3_SUPPORT QStringList &asStringList(); |
|
303 |
inline QT3_SUPPORT QDate &asDate(); |
|
304 |
inline QT3_SUPPORT QTime &asTime(); |
|
305 |
inline QT3_SUPPORT QDateTime &asDateTime(); |
|
306 |
inline QT3_SUPPORT QList<QVariant> &asList(); |
|
307 |
inline QT3_SUPPORT QMap<QString,QVariant> &asMap(); |
|
308 |
inline QT3_SUPPORT QPoint &asPoint(); |
|
309 |
inline QT3_SUPPORT QRect &asRect(); |
|
310 |
inline QT3_SUPPORT QSize &asSize(); |
|
311 |
#endif //QT3_SUPPORT |
|
312 |
||
313 |
#ifndef QT_NO_DATASTREAM |
|
314 |
void load(QDataStream &ds); |
|
315 |
void save(QDataStream &ds) const; |
|
316 |
#endif |
|
317 |
static const char *typeToName(Type type); |
|
318 |
static Type nameToType(const char *name); |
|
319 |
||
320 |
#ifdef QT3_SUPPORT |
|
321 |
inline QT3_SUPPORT_CONSTRUCTOR QVariant(bool val, int) { create(Bool, &val); } |
|
322 |
inline QT3_SUPPORT const QByteArray toCString() const { return toByteArray(); } |
|
323 |
inline QT3_SUPPORT QByteArray &asCString() { return *reinterpret_cast<QByteArray *>(castOrDetach(ByteArray)); } |
|
324 |
#endif |
|
325 |
||
326 |
void *data(); |
|
327 |
const void *constData() const; |
|
328 |
inline const void *data() const { return constData(); } |
|
329 |
||
330 |
#ifndef QT_NO_MEMBER_TEMPLATES |
|
331 |
template<typename T> |
|
332 |
inline void setValue(const T &value); |
|
333 |
||
334 |
template<typename T> |
|
335 |
inline T value() const |
|
336 |
{ return qVariantValue<T>(*this); } |
|
337 |
||
338 |
template<typename T> |
|
339 |
static inline QVariant fromValue(const T &value) |
|
340 |
{ return qVariantFromValue(value); } |
|
341 |
||
342 |
template<typename T> |
|
343 |
bool canConvert() const |
|
344 |
{ return qVariantCanConvert<T>(*this); } |
|
345 |
#endif |
|
346 |
||
347 |
public: |
|
348 |
#ifndef qdoc |
|
349 |
struct PrivateShared |
|
350 |
{ |
|
351 |
inline PrivateShared(void *v) : ptr(v), ref(1) { } |
|
352 |
void *ptr; |
|
353 |
QAtomicInt ref; |
|
354 |
}; |
|
355 |
struct Private |
|
356 |
{ |
|
357 |
inline Private(): type(Invalid), is_shared(false), is_null(true) { data.ptr = 0; } |
|
358 |
inline Private(const Private &other) |
|
359 |
: data(other.data), type(other.type), |
|
360 |
is_shared(other.is_shared), is_null(other.is_null) |
|
361 |
{} |
|
362 |
union Data |
|
363 |
{ |
|
364 |
char c; |
|
365 |
int i; |
|
366 |
uint u; |
|
367 |
bool b; |
|
368 |
double d; |
|
369 |
float f; |
|
370 |
qreal real; |
|
371 |
qlonglong ll; |
|
372 |
qulonglong ull; |
|
373 |
QObject *o; |
|
374 |
void *ptr; |
|
375 |
PrivateShared *shared; |
|
376 |
} data; |
|
377 |
uint type : 30; |
|
378 |
uint is_shared : 1; |
|
379 |
uint is_null : 1; |
|
380 |
}; |
|
381 |
public: |
|
382 |
typedef void (*f_construct)(Private *, const void *); |
|
383 |
typedef void (*f_clear)(Private *); |
|
384 |
typedef bool (*f_null)(const Private *); |
|
385 |
#ifndef QT_NO_DATASTREAM |
|
386 |
typedef void (*f_load)(Private *, QDataStream &); |
|
387 |
typedef void (*f_save)(const Private *, QDataStream &); |
|
388 |
#endif |
|
389 |
typedef bool (*f_compare)(const Private *, const Private *); |
|
390 |
typedef bool (*f_convert)(const QVariant::Private *d, Type t, void *, bool *); |
|
391 |
typedef bool (*f_canConvert)(const QVariant::Private *d, Type t); |
|
392 |
typedef void (*f_debugStream)(QDebug, const QVariant &); |
|
393 |
struct Handler { |
|
394 |
f_construct construct; |
|
395 |
f_clear clear; |
|
396 |
f_null isNull; |
|
397 |
#ifndef QT_NO_DATASTREAM |
|
398 |
f_load load; |
|
399 |
f_save save; |
|
400 |
#endif |
|
401 |
f_compare compare; |
|
402 |
f_convert convert; |
|
403 |
f_canConvert canConvert; |
|
404 |
f_debugStream debugStream; |
|
405 |
}; |
|
406 |
#endif |
|
407 |
||
408 |
inline bool operator==(const QVariant &v) const |
|
409 |
{ return cmp(v); } |
|
410 |
inline bool operator!=(const QVariant &v) const |
|
411 |
{ return !cmp(v); } |
|
412 |
||
413 |
protected: |
|
414 |
friend inline bool qvariant_cast_helper(const QVariant &, QVariant::Type, void *); |
|
415 |
friend int qRegisterGuiVariant(); |
|
416 |
friend int qUnregisterGuiVariant(); |
|
417 |
friend inline bool operator==(const QVariant &, const QVariantComparisonHelper &); |
|
418 |
#ifndef QT_NO_DEBUG_STREAM |
|
419 |
friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QVariant &); |
|
420 |
#endif |
|
421 |
Private d; |
|
422 |
||
423 |
static const Handler *handler; |
|
424 |
||
425 |
void create(int type, const void *copy); |
|
426 |
#ifdef QT3_SUPPORT |
|
427 |
void *castOrDetach(Type t); |
|
428 |
#endif |
|
429 |
bool cmp(const QVariant &other) const; |
|
430 |
||
431 |
private: |
|
432 |
// force compile error, prevent QVariant(bool) to be called |
|
433 |
inline QVariant(void *) { Q_ASSERT(false); } |
|
434 |
#ifdef QT_NO_CAST_FROM_ASCII |
|
435 |
// force compile error when implicit conversion is not wanted |
|
436 |
inline QVariant(const char *) { Q_ASSERT(false); } |
|
437 |
#endif |
|
438 |
#ifndef QT3_SUPPORT |
|
439 |
// force compile error, prevent QVariant(QVariant::Type, int) to be called |
|
440 |
inline QVariant(bool, int) { Q_ASSERT(false); } |
|
441 |
#endif |
|
442 |
public: |
|
443 |
typedef Private DataPtr; |
|
444 |
inline DataPtr &data_ptr() { return d; } |
|
445 |
}; |
|
446 |
||
447 |
typedef QList<QVariant> QVariantList; |
|
448 |
typedef QMap<QString, QVariant> QVariantMap; |
|
449 |
typedef QHash<QString, QVariant> QVariantHash; |
|
450 |
||
451 |
inline bool qvariant_cast_helper(const QVariant &v, QVariant::Type tp, void *ptr) |
|
452 |
{ return QVariant::handler->convert(&v.d, tp, ptr, 0); } |
|
453 |
||
454 |
template <typename T> |
|
455 |
inline QVariant qVariantFromValue(const T &t) |
|
456 |
{ |
|
457 |
return QVariant(qMetaTypeId<T>(reinterpret_cast<T *>(0)), &t, QTypeInfo<T>::isPointer); |
|
458 |
} |
|
459 |
||
460 |
template <> |
|
461 |
inline QVariant qVariantFromValue(const QVariant &t) { return t; } |
|
462 |
||
463 |
template <typename T> |
|
464 |
inline void qVariantSetValue(QVariant &v, const T &t) |
|
465 |
{ |
|
466 |
//if possible we reuse the current QVariant private |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
467 |
const uint type = qMetaTypeId<T>(reinterpret_cast<T *>(0)); |
0 | 468 |
QVariant::Private &d = v.data_ptr(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
469 |
if (v.isDetached() && (type == d.type || (type <= uint(QVariant::Char) && d.type <= uint(QVariant::Char)))) { |
0 | 470 |
d.type = type; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
471 |
d.is_null = false; |
0 | 472 |
T *old = reinterpret_cast<T*>(d.is_shared ? d.data.shared->ptr : &d.data.ptr); |
473 |
if (QTypeInfo<T>::isComplex) |
|
474 |
old->~T(); |
|
475 |
new (old) T(t); //call the copy constructor |
|
476 |
} else { |
|
477 |
v = QVariant(type, &t, QTypeInfo<T>::isPointer); |
|
478 |
} |
|
479 |
} |
|
480 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
481 |
template <> |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
482 |
inline void qVariantSetValue<QVariant>(QVariant &v, const QVariant &t) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
483 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
484 |
v = t; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
485 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
486 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
487 |
|
0 | 488 |
inline QVariant::QVariant() {} |
489 |
inline bool QVariant::isValid() const { return d.type != Invalid; } |
|
490 |
||
491 |
#ifdef QT3_SUPPORT |
|
492 |
inline int &QVariant::asInt() |
|
493 |
{ return *reinterpret_cast<int *>(castOrDetach(Int)); } |
|
494 |
inline uint &QVariant::asUInt() |
|
495 |
{ return *reinterpret_cast<uint *>(castOrDetach(UInt)); } |
|
496 |
inline qlonglong &QVariant::asLongLong() |
|
497 |
{ return *reinterpret_cast<qlonglong *>(castOrDetach(LongLong)); } |
|
498 |
inline qulonglong &QVariant::asULongLong() |
|
499 |
{ return *reinterpret_cast<qulonglong *>(castOrDetach(ULongLong)); } |
|
500 |
inline bool &QVariant::asBool() |
|
501 |
{ return *reinterpret_cast<bool *>(castOrDetach(Bool)); } |
|
502 |
inline double &QVariant::asDouble() |
|
503 |
{ return *reinterpret_cast<double *>(castOrDetach(Double)); } |
|
504 |
inline QByteArray& QVariant::asByteArray() |
|
505 |
{ return *reinterpret_cast<QByteArray *>(castOrDetach(ByteArray)); } |
|
506 |
inline QBitArray& QVariant::asBitArray() |
|
507 |
{ return *reinterpret_cast<QBitArray *>(castOrDetach(BitArray)); } |
|
508 |
inline QString& QVariant::asString() |
|
509 |
{ return *reinterpret_cast<QString *>(castOrDetach(String)); } |
|
510 |
inline QStringList& QVariant::asStringList() |
|
511 |
{ return *reinterpret_cast<QStringList *>(castOrDetach(StringList)); } |
|
512 |
inline QDate& QVariant::asDate() |
|
513 |
{ return *reinterpret_cast<QDate *>(castOrDetach(Date)); } |
|
514 |
inline QTime& QVariant::asTime() |
|
515 |
{ return *reinterpret_cast<QTime *>(castOrDetach(Time)); } |
|
516 |
inline QDateTime& QVariant::asDateTime() |
|
517 |
{ return *reinterpret_cast<QDateTime *>(castOrDetach(DateTime)); } |
|
518 |
inline QList<QVariant>& QVariant::asList() |
|
519 |
{ return *reinterpret_cast<QList<QVariant> *>(castOrDetach(List)); } |
|
520 |
inline QMap<QString, QVariant>& QVariant::asMap() |
|
521 |
{ return *reinterpret_cast<QMap<QString, QVariant> *>(castOrDetach(Map)); } |
|
522 |
inline QPoint &QVariant::asPoint() |
|
523 |
{ return *reinterpret_cast<QPoint *>(castOrDetach(Point)); } |
|
524 |
inline QRect &QVariant::asRect() |
|
525 |
{ return *reinterpret_cast<QRect *>(castOrDetach(Rect)); } |
|
526 |
inline QSize &QVariant::asSize() |
|
527 |
{ return *reinterpret_cast<QSize *>(castOrDetach(Size)); } |
|
528 |
#endif //QT3_SUPPORT |
|
529 |
||
530 |
#ifndef QT_NO_MEMBER_TEMPLATES |
|
531 |
template<typename T> |
|
532 |
inline void QVariant::setValue(const T &avalue) |
|
533 |
{ qVariantSetValue(*this, avalue); } |
|
534 |
#endif |
|
535 |
||
536 |
#ifndef QT_NO_DATASTREAM |
|
537 |
Q_CORE_EXPORT QDataStream& operator>> (QDataStream& s, QVariant& p); |
|
538 |
Q_CORE_EXPORT QDataStream& operator<< (QDataStream& s, const QVariant& p); |
|
539 |
Q_CORE_EXPORT QDataStream& operator>> (QDataStream& s, QVariant::Type& p); |
|
540 |
Q_CORE_EXPORT QDataStream& operator<< (QDataStream& s, const QVariant::Type p); |
|
541 |
#endif |
|
542 |
||
543 |
inline bool QVariant::isDetached() const |
|
544 |
{ return !d.is_shared || d.data.shared->ref == 1; } |
|
545 |
||
546 |
||
547 |
#ifdef qdoc |
|
548 |
inline bool operator==(const QVariant &v1, const QVariant &v2); |
|
549 |
inline bool operator!=(const QVariant &v1, const QVariant &v2); |
|
550 |
#else |
|
551 |
||
552 |
/* Helper class to add one more level of indirection to prevent |
|
553 |
implicit casts. |
|
554 |
*/ |
|
555 |
class QVariantComparisonHelper |
|
556 |
{ |
|
557 |
public: |
|
558 |
inline QVariantComparisonHelper(const QVariant &var) |
|
559 |
: v(&var) {} |
|
560 |
private: |
|
561 |
friend inline bool operator==(const QVariant &, const QVariantComparisonHelper &); |
|
562 |
const QVariant *v; |
|
563 |
}; |
|
564 |
||
565 |
inline bool operator==(const QVariant &v1, const QVariantComparisonHelper &v2) |
|
566 |
{ |
|
567 |
return v1.cmp(*v2.v); |
|
568 |
} |
|
569 |
||
570 |
inline bool operator!=(const QVariant &v1, const QVariantComparisonHelper &v2) |
|
571 |
{ |
|
572 |
return !operator==(v1, v2); |
|
573 |
} |
|
574 |
#endif |
|
575 |
||
576 |
#ifndef QT_MOC |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
577 |
template<typename T> inline T qvariant_cast(const QVariant &v) |
0 | 578 |
{ |
579 |
const int vid = qMetaTypeId<T>(static_cast<T *>(0)); |
|
580 |
if (vid == v.userType()) |
|
581 |
return *reinterpret_cast<const T *>(v.constData()); |
|
582 |
if (vid < int(QMetaType::User)) { |
|
583 |
T t; |
|
584 |
if (qvariant_cast_helper(v, QVariant::Type(vid), &t)) |
|
585 |
return t; |
|
586 |
} |
|
587 |
return T(); |
|
588 |
} |
|
589 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
590 |
template<> inline QVariant qvariant_cast<QVariant>(const QVariant &v) |
0 | 591 |
{ |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
592 |
if (v.userType() == QMetaType::QVariant) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
593 |
return *reinterpret_cast<const QVariant *>(v.constData()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
594 |
return v; |
0 | 595 |
} |
596 |
||
597 |
template<typename T> |
|
598 |
inline T qVariantValue(const QVariant &variant) |
|
599 |
{ return qvariant_cast<T>(variant); } |
|
600 |
||
601 |
template<typename T> |
|
602 |
inline bool qVariantCanConvert(const QVariant &variant) |
|
603 |
{ |
|
604 |
return variant.canConvert(static_cast<QVariant::Type>( |
|
605 |
qMetaTypeId<T>(static_cast<T *>(0)))); |
|
606 |
} |
|
607 |
#endif |
|
608 |
Q_DECLARE_SHARED(QVariant) |
|
609 |
Q_DECLARE_TYPEINFO(QVariant, Q_MOVABLE_TYPE); |
|
610 |
||
611 |
#ifndef QT_NO_DEBUG_STREAM |
|
612 |
Q_CORE_EXPORT QDebug operator<<(QDebug, const QVariant &); |
|
613 |
Q_CORE_EXPORT QDebug operator<<(QDebug, const QVariant::Type); |
|
614 |
#endif |
|
615 |
||
616 |
QT_END_NAMESPACE |
|
617 |
||
618 |
Q_DECLARE_BUILTIN_METATYPE(QVariantList, QVariantList) |
|
619 |
Q_DECLARE_BUILTIN_METATYPE(QVariantMap, QVariantMap) |
|
620 |
Q_DECLARE_BUILTIN_METATYPE(QVariantHash, QVariantHash) |
|
621 |
||
622 |
QT_END_HEADER |
|
623 |
||
624 |
#endif // QVARIANT_H |