1 /****************************************************************************
3 ** Copyright (C) Qxt Foundation. Some rights reserved.
5 ** This file is part of the QxtCore module of the Qt eXTension library
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
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.
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.
21 ** <http://libqxt.sourceforge.net> <foundation@libqxt.org>
23 ****************************************************************************/
29 #include <QDataStream>
30 #include <QGenericArgument>
36 static inline T* construct(const T* copy = 0) {
37 return QMetaType::construct(qMetaTypeId<T>(), reinterpret_cast<const void*>(copy));
40 static inline void destroy(T* data) {
41 QMetaType::destroy(qMetaTypeId<T>(), data);
44 // no need to reimplement isRegistered since this class will fail at compile time if it isn't
46 static inline bool load(QDataStream& stream, T* data) {
47 return QMetaType::load(stream, qMetaTypeId<T>(), reinterpret_cast<void*>(data));
50 static inline bool save(QDataStream& stream, const T* data) {
51 return QMetaType::save(stream, qMetaTypeId<T>(), reinterpret_cast<const void*>(data));
54 static inline int type() {
55 return qMetaTypeId<T>();
58 static inline const char* name() {
59 return QMetaType::typeName(qMetaTypeId<T>());
64 class QxtMetaType<void> {
66 static inline void* construct(const void* copy = 0) {
71 static inline void destroy(void* data) {
75 static inline bool load(QDataStream& stream, void* data) {
81 static inline bool save(QDataStream& stream, const void* data) {
87 static inline int type() {
91 static inline const char* name() {
96 inline void* qxtConstructByName(const char* typeName, const void* copy = 0) {
97 return QMetaType::construct(QMetaType::type(typeName), copy);
100 inline void qxtDestroyByName(const char* typeName, void* data) {
101 QMetaType::destroy(QMetaType::type(typeName), data);
104 inline void* qxtConstructFromGenericArgument(QGenericArgument arg) {
105 return qxtConstructByName(arg.name(), arg.data());
108 inline void qxtDestroyFromGenericArgument(QGenericArgument arg) {
109 qxtDestroyByName(arg.name(), arg.data());