• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

Kross

  • kross
  • core
metatype.h
Go to the documentation of this file.
1/***************************************************************************
2 * metatype.h
3 * This file is part of the KDE project
4 * copyright (C)2004-2006 by Sebastian Sauer (mail@dipe.org)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this program; see the file COPYING. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 ***************************************************************************/
19
20#ifndef KROSS_METATYPE_H
21#define KROSS_METATYPE_H
22
23#include "krossconfig.h"
24//#include "object.h"
25
26
27#include <QtCore/QStringList>
28#include <QtCore/QVariant>
29#include <QtCore/QMetaType>
30
31#include <typeinfo>
32
33//#include <QDate>
34//#include <QTime>
35//#include <QDateTime>
36
37namespace Kross {
38
42 class MetaType
43 {
44 public:
45 virtual ~MetaType() {}
46
47 virtual int typeId() = 0;
48 //virtual QObject* toObject() = 0;
49 //virtual QVariant toVariant() = 0;
50 virtual void* toVoidStar() = 0;
51 };
52
56 template<typename METATYPE>
57 class MetaTypeImpl : public MetaType
58 {
59 public:
60 MetaTypeImpl(const METATYPE& v) : m_variant(v) {
61 #ifdef KROSS_METATYPE_DEBUG
62 krossdebug( QString("MetaTypeImpl<METATYPE> Ctor typeid=%1 typename=%2").arg(qMetaTypeId<METATYPE>()).arg(typeid(METATYPE).name()) );
63 #endif
64 }
65 virtual ~MetaTypeImpl() {
66 #ifdef KROSS_METATYPE_DEBUG
67 krossdebug( QString("MetaTypeImpl<METATYPE> Dtor typeid=%1 typename=%2").arg(qMetaTypeId<METATYPE>()).arg(typeid(METATYPE).name()) );
68 #endif
69 }
70
71 virtual int typeId() { return qMetaTypeId<METATYPE>(); }
72 //virtual QVariant toVariant() { return QVariant(typeId(), m_variant); }
73 virtual void* toVoidStar() { return static_cast<void *>(&m_variant); }
74
75 private:
76 METATYPE m_variant;
77 };
78
82 template<typename VARIANTTYPE>
83 class MetaTypeVariant : public MetaType
84 {
85 public:
86 MetaTypeVariant(const VARIANTTYPE& v) : m_value(v) {
87 #ifdef KROSS_METATYPE_DEBUG
88 krossdebug( QString("MetaTypeVariant<VARIANTTYPE> Ctor value=%1 typename=%2").arg(qVariantFromValue(m_value).toString()).arg(qVariantFromValue(m_value).typeName()) );
89 #endif
90 }
91 virtual ~MetaTypeVariant() {
92 #ifdef KROSS_METATYPE_DEBUG
93 krossdebug( QString("MetaTypeVariant<VARIANTTYPE> Dtor value=%1 typename=%2").arg(qVariantFromValue(m_value).toString()).arg(qVariantFromValue(m_value).typeName()) );
94 #endif
95 }
96
97 virtual int typeId() { return qVariantFromValue(m_value).type(); }
98 //virtual QVariant toVariant() { return qVariantFromValue(m_value); }
99 virtual void* toVoidStar() { return static_cast<void *>(&m_value); }
100
101 private:
102 VARIANTTYPE m_value;
103 };
104
108 class MetaTypeVoidStar : public MetaType
109 {
110 public:
111 MetaTypeVoidStar(int typeId, void* ptr, bool owner) : m_typeId(typeId), m_ptr(ptr), m_owner(owner) {
112 #ifdef KROSS_METATYPE_DEBUG
113 krossdebug( QString("MetaTypeVoidStar Ctor typeid=%1 typename=%2 owner=%3").arg(m_typeId).arg(typeid(m_ptr).name()).arg(m_owner) );
114 #endif
115 }
116 virtual ~MetaTypeVoidStar() {
117 #ifdef KROSS_METATYPE_DEBUG
118 krossdebug( QString("MetaTypeVoidStar Ctor typeid=%1 typename=%2 owner=%3").arg(m_typeId).arg(typeid(m_ptr).name()).arg(m_owner) );
119 #endif
120 if( m_owner )
121 QMetaType::destroy(m_typeId, m_ptr);
122 }
123 virtual int typeId() { return m_typeId; }
124 virtual void* toVoidStar() { return static_cast<void *>(&m_ptr); }
125
126 private:
127 int m_typeId;
128 void* m_ptr;
129 bool m_owner;
130 };
131
138 class KROSSCORE_EXPORT MetaTypeHandler
139 {
140 public:
141 typedef QVariant (FunctionPtr) (void*);
142 typedef QVariant (FunctionPtr2) (MetaTypeHandler* handler, void*);
143
144 explicit MetaTypeHandler() : m_func1(0), m_func2(0) {}
145 explicit MetaTypeHandler(FunctionPtr *func) : m_func1(func), m_func2(0) {}
146 explicit MetaTypeHandler(FunctionPtr2 *func) : m_func1(0), m_func2(func) {}
147 virtual ~MetaTypeHandler() {}
148
153 virtual QVariant callHandler(void* ptr) {
154 return m_func1 ? m_func1(ptr) : m_func2 ? m_func2(this, ptr) : QVariant();
155 }
156
157 private:
158 FunctionPtr *m_func1;
159 FunctionPtr2 *m_func2;
160 };
161}
162
163#endif
Kross::MetaTypeHandler
Base class for metatype-handlers as used returned by the Kross::Manager::metaTypeHandler() method.
Definition: metatype.h:139
Kross::MetaTypeHandler::MetaTypeHandler
MetaTypeHandler(FunctionPtr *func)
Definition: metatype.h:145
Kross::MetaTypeHandler::MetaTypeHandler
MetaTypeHandler()
Definition: metatype.h:144
Kross::MetaTypeHandler::MetaTypeHandler
MetaTypeHandler(FunctionPtr2 *func)
Definition: metatype.h:146
Kross::MetaTypeHandler::~MetaTypeHandler
virtual ~MetaTypeHandler()
Definition: metatype.h:147
Kross::MetaTypeHandler::callHandler
virtual QVariant callHandler(void *ptr)
This got called by the scripting-backend if the type-handler is called to translate a void-star point...
Definition: metatype.h:153
Kross::MetaTypeImpl
Metatypes which are registered in the QMetaType system.
Definition: metatype.h:58
Kross::MetaTypeImpl::MetaTypeImpl
MetaTypeImpl(const METATYPE &v)
Definition: metatype.h:60
Kross::MetaTypeImpl::~MetaTypeImpl
virtual ~MetaTypeImpl()
Definition: metatype.h:65
Kross::MetaTypeImpl::typeId
virtual int typeId()
Definition: metatype.h:71
Kross::MetaTypeImpl::toVoidStar
virtual void * toVoidStar()
Definition: metatype.h:73
Kross::MetaTypeVariant
Metatypes which are listened in QVariant::Type.
Definition: metatype.h:84
Kross::MetaTypeVariant::~MetaTypeVariant
virtual ~MetaTypeVariant()
Definition: metatype.h:91
Kross::MetaTypeVariant::typeId
virtual int typeId()
Definition: metatype.h:97
Kross::MetaTypeVariant::toVoidStar
virtual void * toVoidStar()
Definition: metatype.h:99
Kross::MetaTypeVariant::MetaTypeVariant
MetaTypeVariant(const VARIANTTYPE &v)
Definition: metatype.h:86
Kross::MetaTypeVoidStar
Metatype for generic VoidStar pointers.
Definition: metatype.h:109
Kross::MetaTypeVoidStar::MetaTypeVoidStar
MetaTypeVoidStar(int typeId, void *ptr, bool owner)
Definition: metatype.h:111
Kross::MetaTypeVoidStar::typeId
virtual int typeId()
Definition: metatype.h:123
Kross::MetaTypeVoidStar::~MetaTypeVoidStar
virtual ~MetaTypeVoidStar()
Definition: metatype.h:116
Kross::MetaTypeVoidStar::toVoidStar
virtual void * toVoidStar()
Definition: metatype.h:124
Kross::MetaType
Base class for metatype-implementations.
Definition: metatype.h:43
Kross::MetaType::typeId
virtual int typeId()=0
Kross::MetaType::toVoidStar
virtual void * toVoidStar()=0
Kross::MetaType::~MetaType
virtual ~MetaType()
Definition: metatype.h:45
krossconfig.h
name
const char * name(StandardAction id)
Kross
Definition: action.cpp:36
Kross::krossdebug
void krossdebug(const QString &s)
Debugging function.
Definition: krossconfig.cpp:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kross

Skip menu "Kross"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal