GammaRay  2.4.0
metaobjectrepository.h
Go to the documentation of this file.
1 /*
2  metaobjectrepository.h
3 
4  This file is part of GammaRay, the Qt application inspection and
5  manipulation tool.
6 
7  Copyright (C) 2011-2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
8  Author: Volker Krause <volker.krause@kdab.com>
9 
10  Licensees holding valid commercial KDAB GammaRay licenses may use this file in
11  accordance with GammaRay Commercial License Agreement provided with the Software.
12 
13  Contact info@kdab.com if any conditions of this licensing are not clear to you.
14 
15  This program is free software; you can redistribute it and/or modify
16  it under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 2 of the License, or
18  (at your option) any later version.
19 
20  This program is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  GNU General Public License for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with this program. If not, see <http://www.gnu.org/licenses/>.
27 */
28 
33 #ifndef GAMMARAY_METAOBJECTREPOSITORY_H
34 #define GAMMARAY_METAOBJECTREPOSITORY_H
35 
36 #include "gammaray_core_export.h"
37 #include <QHash>
38 
39 class QString;
40 
41 namespace GammaRay {
42 
43 class MetaObject;
44 
51 class GAMMARAY_CORE_EXPORT MetaObjectRepository
52 {
53  public:
55 
57  static MetaObjectRepository *instance();
58 
62  void addMetaObject(MetaObject *mo);
63 
67  MetaObject *metaObject(const QString& typeName) const;
68 
72  bool hasMetaObject(const QString &typeName) const;
73 
74  protected:
76 
77  private:
78  Q_DISABLE_COPY(MetaObjectRepository)
79  void initBuiltInTypes();
80  void initQObjectTypes();
81  void initIOTypes();
82  void initNetworkTypes();
83  void initGuiTypes();
84  void initOpenGLTypes();
85 
86  private:
87  QHash<QString, MetaObject*> m_metaObjects;
88  bool m_initialized;
89 };
90 
91 }
93 #define MO_ADD_BASECLASS(Base) \
94  Q_ASSERT(GammaRay::MetaObjectRepository::instance()->hasMetaObject(QStringLiteral(#Base))); \
95  mo->addBaseClass(GammaRay::MetaObjectRepository::instance()->metaObject(QStringLiteral(#Base)));
96 
101 #define MO_ADD_METAOBJECT0(Class) \
102  mo = new GammaRay::MetaObjectImpl<Class>; \
103  mo->setClassName(QStringLiteral(#Class)); \
104  GammaRay::MetaObjectRepository::instance()->addMetaObject(mo);
105 
109 #define MO_ADD_METAOBJECT1(Class, Base1) \
110  mo = new GammaRay::MetaObjectImpl<Class, Base1>; \
111  mo->setClassName(QStringLiteral(#Class)); \
112  MO_ADD_BASECLASS(Base1) \
113  GammaRay::MetaObjectRepository::instance()->addMetaObject(mo);
114 
118 #define MO_ADD_METAOBJECT2(Class, Base1, Base2) \
119  mo = new GammaRay::MetaObjectImpl<Class, Base1, Base2>; \
120  mo->setClassName(QStringLiteral(#Class)); \
121  MO_ADD_BASECLASS(Base1) \
122  MO_ADD_BASECLASS(Base2) \
123  GammaRay::MetaObjectRepository::instance()->addMetaObject(mo);
124 
126 #define MO_ADD_PROPERTY(Class, Type, Getter, Setter) \
127  mo->addProperty(new GammaRay::MetaPropertyImpl<Class, Type>( \
128  #Getter, \
129  &Class::Getter, \
130  static_cast<void (Class::*)(Type)>(&Class::Setter)) \
131  );
132 
134 #define MO_ADD_PROPERTY_CR(Class, Type, Getter, Setter) \
135  mo->addProperty(new GammaRay::MetaPropertyImpl<Class, Type, const Type&>( \
136  #Getter, \
137  &Class::Getter, \
138  static_cast<void (Class::*)(const Type&)>(&Class::Setter)) \
139  );
140 
142 #define MO_ADD_PROPERTY_RO(Class, Type, Getter) \
143  mo->addProperty(new GammaRay::MetaPropertyImpl<Class, Type>( \
144  #Getter, \
145  &Class::Getter));
146 
148 #define MO_ADD_PROPERTY_ST(Class, Type, Getter) \
149  mo->addProperty(new GammaRay::MetaStaticPropertyImpl<Class, Type>( \
150  #Getter, \
151  &Class::Getter));
152 
153 #endif // GAMMARAY_METAOBJECTREPOSITORY_H
Compile-time introspection adaptor for non-QObject classes.
Definition: metaobject.h:41
Definition: endpoint.h:42
QMetaObject instance only.
Definition: enums.h:41
MetaObject repository.
Definition: metaobjectrepository.h:51

Klarälvdalens Datakonsult AB (KDAB)
"The Qt Experts"
http://www.kdab.com/
GammaRay
Qt-application inspection and manipulation tool
http://www.kdab.com/kdab-products/gammaray/