diff qt/core/QMetaObject.d @ 259:515d6e1c7b10 lifetime

another iteration
author maxter
date Thu, 17 Sep 2009 16:28:41 +0000
parents 073b9153ed8a
children b5773ccab07d
line wrap: on
line diff
--- a/qt/core/QMetaObject.d	Wed Sep 16 14:16:33 2009 +0000
+++ b/qt/core/QMetaObject.d	Thu Sep 17 16:28:41 2009 +0000
@@ -4,56 +4,20 @@
 import qt.core.QObject;
 import qt.QtdObject;
 
-final class QMetaObject
+/++
+    Meta-object for QObject classes.
++/
+final class QMetaObject : MetaObject
 {
-    private
-    {
-        void* _nativeId;
-        QMetaObject _base; // super class
-        QMetaObject _firstDerived; // head of the linked list of derived classes
-        QMetaObject _next; // next sibling on this derivation level
-        ClassInfo _classInfo;
-
-        QObject function(void* nativeId) _createWrapper;
-    }
+    alias typeof(this) This;
     
-    private void addDerived(QMetaObject mo)
-    {
-        mo._next = _firstDerived;
-        _firstDerived = mo;
-    }
+    private void* _nativeId;
     
-    // NOTE: construction is split between this non-templated constructor and 'construct' function below.
     this(void* nativeId, QMetaObject base)
     {
         _nativeId = nativeId;
-        if (base)
-        {
-            base.addDerived(this);
-            _base = base;
-        }
-    }
-    
-    // TODO: remove when D acquires templated constructors       
-    void construct(T : QObject, Concrete = T)()
-    {
-        _classInfo = T.classinfo;        
-
-        _createWrapper = function QObject(void* nativeId) {
-                // COMPILER BUG: cast is should not be needed
-                auto obj = new Concrete(nativeId, cast(QtdObjectFlags)(QtdObjectFlags.nativeOwnership | QtdObjectFlags.dynamicEntity));
-                // TODO: Probably this should be a virtual call from T's constructor
-                T.__createEntity(nativeId, cast(void*)obj);
-                return obj;
-            };
-    }
-    
-    /++
-    +/
-    QMetaObject base()
-    {
-        return _base;
-    }
+        super(base);
+    }    
     
     /++
     +/
@@ -61,19 +25,12 @@
     {
         return _nativeId;
     }
-
-    /++
-    +/
-    ClassInfo classInfo()
-    {
-        return _classInfo;
-    }
     
     private QMetaObject lookupDerived(void*[] moIds)
     {
         assert (moIds.length >= 1);
                 
-        for (auto mo = _firstDerived; mo !is null; mo = mo._next)
+        for (auto mo = static_cast!(This)(firstDerived); mo !is null; mo = static_cast!(This)(mo.next))
         {
             if (mo._nativeId == moIds[0])
             {
@@ -89,7 +46,7 @@
         return this;
     }
     
-    QObject getObject(void* nativeObjId)
+    QObject wrap(void* nativeObjId, QtdObjectFlags flags = QtdObjectFlags.none)
     {
         QObject result;
         
@@ -100,7 +57,7 @@
             {
                 auto moId = qtd_QObject_metaObject(nativeObjId);
                 if (_nativeId == moId)
-                     result = _createWrapper(nativeObjId);
+                     result = _createWrapper(nativeObjId, flags);
                 else
                 {
                     // get native metaobjects for the entire derivation lattice
@@ -110,7 +67,9 @@
                     for (void* tmp = moId;;)
                     {
                         tmp = qtd_QMetaObject_superClass(tmp);                        
-                        assert(tmp);
+                        if (!tmp)
+                            return null;
+                        
                         if (tmp == _nativeId)                        
                             break;
                         moCount++;
@@ -122,7 +81,7 @@
                     while (moCount > 0)
                         moIds[--moCount] = moId = qtd_QMetaObject_superClass(moId);
                                     
-                    result = lookupDerived(moIds)._createWrapper(nativeObjId);
+                    result = lookupDerived(moIds)._createWrapper(nativeObjId, flags);
                 }                
             }
         }