Ok, the long awaited config wizard is here (at least in a very basic state). There...
[quassel.git] / src / contrib / libqxt-2007-10-24 / src / core / qxtmetatype.h
1 /****************************************************************************
2 **
3 ** Copyright (C) Qxt Foundation. Some rights reserved.
4 **
5 ** This file is part of the QxtCore module of the Qt eXTension library
6 **
7 ** This library is free software; you can redistribute it and/or modify it
8 ** under the terms of th Common Public License, version 1.0, as published by
9 ** IBM.
10 **
11 ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
12 ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
13 ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
14 ** FITNESS FOR A PARTICULAR PURPOSE.
15 **
16 ** You should have received a copy of the CPL along with this file.
17 ** See the LICENSE file and the cpl1.0.txt file included with the source
18 ** distribution for more information. If you did not receive a copy of the
19 ** license, contact the Qxt Foundation.
20 **
21 ** <http://libqxt.sourceforge.net>  <foundation@libqxt.org>
22 **
23 ****************************************************************************/
24
25 #ifndef QXTMETATYPE_H
26 #define QXTMETATYPE_H
27
28 #include <QMetaType>
29 #include <QDataStream>
30 #include <QGenericArgument>
31 #include <QtDebug>
32
33 template <typename T>
34 class QxtMetaType {
35 public:
36     static inline T* construct(const T* copy = 0) {
37         return QMetaType::construct(qMetaTypeId<T>(), reinterpret_cast<const void*>(copy));
38     }
39
40     static inline void destroy(T* data) {
41         QMetaType::destroy(qMetaTypeId<T>(), data);
42     }
43
44     // no need to reimplement isRegistered since this class will fail at compile time if it isn't
45     
46     static inline bool load(QDataStream& stream, T* data) {
47         return QMetaType::load(stream, qMetaTypeId<T>(), reinterpret_cast<void*>(data));
48     }
49
50     static inline bool save(QDataStream& stream, const T* data) {
51         return QMetaType::save(stream, qMetaTypeId<T>(), reinterpret_cast<const void*>(data));
52     }
53
54     static inline int type() {
55         return qMetaTypeId<T>();
56     }
57
58     static inline const char* name() {
59         return QMetaType::typeName(qMetaTypeId<T>());
60     }
61 };
62
63 template <>
64 class QxtMetaType<void> {
65 public:
66     static inline void* construct(const void* copy = 0) {
67         Q_UNUSED(copy);
68         return 0;
69     }
70
71     static inline void destroy(void* data) {
72         Q_UNUSED(data);
73     }
74
75     static inline bool load(QDataStream& stream, void* data) {
76         Q_UNUSED(stream);
77         Q_UNUSED(data);
78         return false;
79     }
80
81     static inline bool save(QDataStream& stream, const void* data) {
82         Q_UNUSED(stream);
83         Q_UNUSED(data);
84         return false;
85     }
86
87     static inline int type() {
88         return 0;
89     }
90
91     static inline const char* name() {
92         return 0;
93     }
94 };
95
96 inline void* qxtConstructByName(const char* typeName, const void* copy = 0) {
97     return QMetaType::construct(QMetaType::type(typeName), copy);
98 }
99
100 inline void qxtDestroyByName(const char* typeName, void* data) {
101     QMetaType::destroy(QMetaType::type(typeName), data);
102 }
103
104 inline void* qxtConstructFromGenericArgument(QGenericArgument arg) {
105     return qxtConstructByName(arg.name(), arg.data());
106 }
107
108 inline void qxtDestroyFromGenericArgument(QGenericArgument arg) {
109     qxtDestroyByName(arg.name(), arg.data());
110 }
111
112 #endif