PageRenderTime 25ms CodeModel.GetById 14ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/thirdparty/qxt/qxtweb-standalone/qxtweb/qxtmetatype.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 132 lines | 87 code | 20 blank | 25 comment | 0 complexity | 8eb145bb50412611f6bee070ebe5222f MD5 | raw file
  1/****************************************************************************
  2 **
  3 ** Copyright (C) Qxt Foundation. Some rights reserved.
  4 **
  5 ** This file is part of the QxtCore module of the Qxt library.
  6 **
  7 ** This library is free software; you can redistribute it and/or modify it
  8 ** under the terms of the Common Public License, version 1.0, as published
  9 ** by IBM, and/or under the terms of the GNU Lesser General Public License,
 10 ** version 2.1, as published by the Free Software Foundation.
 11 **
 12 ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
 13 ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
 14 ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
 15 ** FITNESS FOR A PARTICULAR PURPOSE.
 16 **
 17 ** You should have received a copy of the CPL and the LGPL along with this
 18 ** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
 19 ** included with the source distribution for more information.
 20 ** If you did not receive a copy of the licenses, contact the Qxt Foundation.
 21 **
 22 ** <http://libqxt.org>  <foundation@libqxt.org>
 23 **
 24 ****************************************************************************/
 25
 26#ifndef QXTMETATYPE_H
 27#define QXTMETATYPE_H
 28
 29#include <QMetaType>
 30#include <QDataStream>
 31#include <QGenericArgument>
 32#include <QtDebug>
 33#include <qxtglobal.h>
 34
 35template <typename T>
 36class /*QXT_CORE_EXPORT*/ QxtMetaType
 37{
 38public:
 39    static inline T* construct(const T* copy = 0)
 40    {
 41        return QMetaType::construct(qMetaTypeId<T>(), reinterpret_cast<const void*>(copy));
 42    }
 43
 44    static inline void destroy(T* data)
 45    {
 46        QMetaType::destroy(qMetaTypeId<T>(), data);
 47    }
 48
 49    // no need to reimplement isRegistered since this class will fail at compile time if it isn't
 50
 51    static inline bool load(QDataStream& stream, T* data)
 52    {
 53        return QMetaType::load(stream, qMetaTypeId<T>(), reinterpret_cast<void*>(data));
 54    }
 55
 56    static inline bool save(QDataStream& stream, const T* data)
 57    {
 58        return QMetaType::save(stream, qMetaTypeId<T>(), reinterpret_cast<const void*>(data));
 59    }
 60
 61    static inline int type()
 62    {
 63        return qMetaTypeId<T>();
 64    }
 65
 66    static inline const char* name()
 67    {
 68        return QMetaType::typeName(qMetaTypeId<T>());
 69    }
 70};
 71
 72template <>
 73class /*QXT_CORE_EXPORT*/ QxtMetaType<void>
 74{
 75public:
 76    static inline void* construct(const void* copy = 0)
 77    {
 78        Q_UNUSED(copy);
 79        return 0;
 80    }
 81
 82    static inline void destroy(void* data)
 83    {
 84        Q_UNUSED(data);
 85    }
 86
 87    static inline bool load(QDataStream& stream, void* data)
 88    {
 89        Q_UNUSED(stream);
 90        Q_UNUSED(data);
 91        return false;
 92    }
 93
 94    static inline bool save(QDataStream& stream, const void* data)
 95    {
 96        Q_UNUSED(stream);
 97        Q_UNUSED(data);
 98        return false;
 99    }
100
101    static inline int type()
102    {
103        return 0;
104    }
105
106    static inline const char* name()
107    {
108        return 0;
109    }
110};
111
112inline void* qxtConstructByName(const char* typeName, const void* copy = 0)
113{
114    return QMetaType::construct(QMetaType::type(typeName), copy);
115}
116
117inline void qxtDestroyByName(const char* typeName, void* data)
118{
119    QMetaType::destroy(QMetaType::type(typeName), data);
120}
121
122inline void* qxtConstructFromGenericArgument(QGenericArgument arg)
123{
124    return qxtConstructByName(arg.name(), arg.data());
125}
126
127inline void qxtDestroyFromGenericArgument(QGenericArgument arg)
128{
129    qxtDestroyByName(arg.name(), arg.data());
130}
131
132#endif