GammaRay  2.4.0
metaobject.h
1 /*
2  metaobject.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 
29 #ifndef GAMMARAY_METAOBJECT_H
30 #define GAMMARAY_METAOBJECT_H
31 
32 #include "gammaray_core_export.h"
33 
34 #include "metaproperty.h"
35 
36 #include <QVector>
37 
38 namespace GammaRay {
39 
41 class GAMMARAY_CORE_EXPORT MetaObject
42 {
43  public:
44  MetaObject();
45  virtual ~MetaObject();
46 
50  int propertyCount() const;
51 
55  MetaProperty *propertyAt(int index) const;
56 
58  void addBaseClass(MetaObject *baseClass);
59 
61  void addProperty(MetaProperty *property);
62 
64  QString className() const;
65 
70  void *castForPropertyAt(void *object, int index) const;
71 
72  void setClassName(const QString &className);
73 
74  MetaObject *superClass(int index = 0) const;
75  bool inherits(const QString &className) const;
76 
77  protected:
81  virtual void *castToBaseClass(void *object, int baseClassIndex) const = 0;
82 
83  protected:
84  QVector<MetaObject*> m_baseClasses;
85 
86  private:
87  QVector<MetaProperty*> m_properties;
88  QString m_className;
89 };
90 
92 template <typename T, typename Base1 = void, typename Base2 = void, typename Base3 = void>
93 class MetaObjectImpl : public MetaObject
94 {
95  public:
96  void *castToBaseClass(void *object, int baseClassIndex) const Q_DECL_OVERRIDE
97  {
98  Q_ASSERT(baseClassIndex >= 0 && baseClassIndex < m_baseClasses.size());
99  switch (baseClassIndex) {
100  case 0:
101  return static_cast<Base1*>(static_cast<T*>(object));
102  case 1:
103  return static_cast<Base2*>(static_cast<T*>(object));
104  case 2:
105  return static_cast<Base3*>(static_cast<T*>(object));
106  }
107  Q_ASSERT(!"WTF!?");
108  return 0;
109  }
110 };
111 
112 }
113 
114 #endif // GAMMARAY_METAOBJECT_H
Compile-time introspection adaptor for non-QObject classes.
Definition: metaobject.h:41
Introspectable adaptor to non-QObject properties.
Definition: metaproperty.h:41
Definition: endpoint.h:42
Template implementation of MetaObject.
Definition: metaobject.h:93
void * castToBaseClass(void *object, int baseClassIndex) const Q_DECL_OVERRIDE
Definition: metaobject.h:96

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/