File indexing completed on 2024-04-28 04:40:01

0001 #ifndef INTROSPECTION_H
0002 #define INTROSPECTION_H
0003 
0004 // define TREEINTROSPECTION to let objects have a pointer to their parents
0005 #define TREEINTROSPECTION
0006 
0007 #include <QtCore/QVariant>
0008 #include <QtCore/QVector>
0009 #include <stdint.h>
0010 
0011 class Introspectable;
0012 
0013 Q_DECLARE_METATYPE(QVector<quint16>);
0014 Q_DECLARE_METATYPE(QVector<quint32>);
0015 
0016 class Introspection {
0017 public:
0018     const QString name;
0019     const int numberOfMembers;
0020     const QString* const names;
0021     int (* const * const numberOfInstances)(const Introspectable*);
0022     QVariant (* const * const value)(const Introspectable*, int position);
0023     const Introspectable* (* const * const introspectable)(const Introspectable*, int position);
0024 
0025     Introspection(const QString& n,
0026             const int nOM,
0027             const QString* const ns,
0028             int (* const * const mC)(const Introspectable*),
0029             QVariant (* const * const vG)(const Introspectable*, int),
0030             const Introspectable* (* const * const i)(const Introspectable*, int))
0031         :name(n), numberOfMembers(nOM), names(ns),
0032          numberOfInstances(mC), value(vG), introspectable(i) {}
0033 
0034     // convenience
0035     static int zero(const Introspectable*) { return 0; }
0036     static int one(const Introspectable*) { return 1; }
0037     static const Introspectable* null(const Introspectable*, int) { return NULL; } 
0038     static QVariant nullValue(const Introspectable*, int) { return QVariant(); }
0039 };
0040 
0041 class Introspectable {
0042 public:
0043     uint32_t streamOffset;
0044 #ifdef TREEINTROSPECTION
0045     Introspectable const * parent; // one more 'const' would be nice ...
0046 
0047     Introspectable(const Introspectable* p)
0048             :streamOffset(999999), parent(p) {}
0049 #else
0050     Introspectable(const Introspectable* = 0)
0051             :streamOffset(999999) {
0052     }
0053 #endif
0054 
0055     virtual ~Introspectable() {}
0056     virtual const Introspection* getIntrospection() const = 0;
0057 };
0058 
0059 
0060 #endif