1
#ifndef INTROSPECTION_H
2
#define INTROSPECTION_H
3
4
// define TREEINTROSPECTION to let objects have a pointer to their parents
5
#define TREEINTROSPECTION
6
7
#include <QtCore/QVariant>
8
#include <QtCore/QVector>
9
#include <stdint.h>
10
11
class Introspectable;
12
13
Q_DECLARE_METATYPE(QVector<quint16>);
14
Q_DECLARE_METATYPE(QVector<quint32>);
15
16
class Introspection {
17
public:
18
    const QString name;
19
    const int numberOfMembers;
20
    const QString* const names;
21
    int (* const * const numberOfInstances)(const Introspectable*);
22
    QVariant (* const * const value)(const Introspectable*, int position);
23
    const Introspectable* (* const * const introspectable)(const Introspectable*, int position);
24
25
    Introspection(const QString& n,
26
            const int nOM,
27
            const QString* const ns,
28
            int (* const * const mC)(const Introspectable*),
29
            QVariant (* const * const vG)(const Introspectable*, int),
30
            const Introspectable* (* const * const i)(const Introspectable*, int))
31
        :name(n), numberOfMembers(nOM), names(ns),
32
         numberOfInstances(mC), value(vG), introspectable(i) {}
33
34
    // convenience
35
    static int zero(const Introspectable*) { return 0; }
36
    static int one(const Introspectable*) { return 1; }
37
    static const Introspectable* null(const Introspectable*, int) { return NULL; } 
38
    static QVariant nullValue(const Introspectable*, int) { return QVariant(); }
39
};
40
41
class Introspectable {
42
public:
43
    uint32_t streamOffset;
44
#ifdef TREEINTROSPECTION
45
    Introspectable const * parent; // one more 'const' would be nice ...
46
47
    Introspectable(const Introspectable* p)
48
            :streamOffset(999999), parent(p) {}
49
#else
50
    Introspectable(const Introspectable* = 0)
51
            :streamOffset(999999) {
52
    }
53
#endif
54
55
    virtual ~Introspectable() {}
56
    virtual const Introspection* getIntrospection() const = 0;
57
};
58
59
60
#endif