comparison include/QObjectEntity.h @ 248:7664de4a55e5

Fixed #23. QtD_QObjectEntity is not created dynamically for shell classes any more. Class initialization is now performed by static constructors. When wrapping QObjects returned from functions, their run-time types are now taken into account. QObjects are allocated on GC heap, a doubly-linked list is used to prevent them from been collected (arguably a better solution than allocating on C heap and adding GC ranges) Minor changes (including unnecessary).
author maxter
date Thu, 20 Aug 2009 14:47:17 +0000
parents e78566595089
children 37eed70de029
comparison
equal deleted inserted replaced
247:27497bbe62a1 248:7664de4a55e5
1 #ifndef QQOBJECTENTITY_H 1 #ifndef QQOBJECTENTITY_H
2 #define QQOBJECTENTITY_H 2 #define QQOBJECTENTITY_H
3 3
4 #include <cstdlib> 4 #include "qtd_core.h"
5 #include <qobject.h>
6 #include <iostream>
5 7
6 class Qtd_QObjectEntity 8 QTD_EXPORT(void, qtd_delete_d_qobject, (void* dPtr))
9
10 #ifdef CPP_SHARED
11 #define qtd_delete_d_qobject qtd_get_qtd_delete_d_qobject()
12 #endif
13
14 //TODO: user data ID must be registered with QObject::registerUserData;
15 #define userDataId 0
16
17 class QtD_QObjectEntity : public QtD_Entity, public QObjectUserData
7 { 18 {
8 public: 19 public:
9 Qtd_QObjectEntity(void *d_ptr) { _d_ptr = d_ptr; }
10 void *d_entity() const { return _d_ptr; }
11 20
12 private: 21 QtD_QObjectEntity(QObject *qObject, void *dId) : QtD_Entity(dId)
13 void *_d_ptr; 22 {
23 qObject->setUserData(userDataId, this);
24 }
25
26 virtual ~QtD_QObjectEntity()
27 {
28 qtd_delete_d_qobject(dId);
29 }
30
31 inline static QtD_QObjectEntity* getQObjectEntity(const QObject *qObject)
32 {
33 return static_cast<QtD_QObjectEntity*>(qObject->userData(userDataId));
34 }
14 }; 35 };
15 36
16 #endif // QQOBJECTENTITY_H 37 #endif // QQOBJECTENTITY_H