4 This file is part of GammaRay, the Qt application inspection and
7 Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
8 Author: Volker Krause <volker.krause@kdab.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #ifndef GAMMARAY_METAOBJECT_H
25 #define GAMMARAY_METAOBJECT_H
27 #include "metaproperty.h"
33 /** Compile-time introspection adaptor for non-QObject classes. */
38 virtual ~MetaObject();
41 * Returns the amount of properties available in this class (including base classes).
43 int propertyCount() const;
46 * Returns the property adaptor for index @p index.
48 MetaProperty
*propertyAt(int index
) const;
50 /** Add a base class meta object. */
51 void addBaseClass(MetaObject
*baseClass
);
53 /** Add a property for this class. This transfers ownership. */
54 void addProperty(MetaProperty
*property
);
56 /// Returns the name of the class represented by this object.
57 QString
className() const;
59 /** Casts a void pointer for an instance of this type to one appropriate
60 * for use with the property at index @p index.
61 * Make sure to use this when dealing with multi-inheritance.
63 void *castForPropertyAt(void *object
, int index
) const;
66 /** Casts down to base class @p baseClassIndex.
67 * This is important when traversing multi-inheritance trees.
69 virtual void *castToBaseClass(void *object
, int baseClassIndex
) const = 0;
72 QVector
<MetaObject
*> m_baseClasses
;
75 friend class MetaObjectRepository
;
76 void setClassName(const QString
&className
);
79 QVector
<MetaProperty
*> m_properties
;
83 /** Template implementation of MetaObject. */
84 template <typename T
, typename Base1
= void, typename Base2
= void, typename Base3
= void>
85 class MetaObjectImpl
: public MetaObject
88 void *castToBaseClass(void *object
, int baseClassIndex
) const
90 Q_ASSERT(baseClassIndex
>= 0 && baseClassIndex
< m_baseClasses
.size());
91 switch (baseClassIndex
) {
93 return static_cast<Base1
*>(static_cast<T
*>(object
));
95 return static_cast<Base2
*>(static_cast<T
*>(object
));
97 return static_cast<Base3
*>(static_cast<T
*>(object
));
106 #endif // GAMMARAY_METAOBJECT_H