Mercurial > projects > qtd
diff d1/qt/core/QMetaObject.d @ 311:8674fd5f34f4 lifetime
Added d1/d2 top directories
author | maxter <spambox@d-coding.com> |
---|---|
date | Wed, 23 Dec 2009 16:17:22 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d1/qt/core/QMetaObject.d Wed Dec 23 16:17:22 2009 +0200 @@ -0,0 +1,85 @@ +module qt.core.QMetaObject; + +import + qt.Core, + qt.core.QObject, + qt.QtdObject; + +/++ + Meta-object for QObject classes. ++/ +final class QMetaObject : QtdMetaObjectBase +{ + alias typeof(this) This; + + this(void* nativeId, QtdMetaObjectBase base, CreateWrapper createWrapper) + { + super(nativeId, base, createWrapper); + } + + private QMetaObject lookupDerived(void*[] moIds) + { + assert (moIds.length >= 1); + + for (auto mo = static_cast!(This)(firstDerived); mo !is null; mo = static_cast!(This)(mo.next)) + { + if (mo.nativeId == moIds[0]) + { + if (moIds.length == 1) // exact match found + return mo; + else // look deeper + return mo.lookupDerived(moIds[1..$]); + } + } + + // no initialized wrapper that matches the native object. + // use the base class wrapper + return this; + } + + QObject wrap(void* nativeObjId, QtdObjectFlags flags = QtdObjectFlags.none) + { + QObject result; + + if (nativeObjId) + { + result = cast(QObject)qtd_get_d_qobject(nativeObjId); + if (!result) + { + auto moId = qtd_QObject_typeId(nativeObjId); + if (nativeId == moId) + result = static_cast!(QObject)(_createWrapper(nativeObjId, flags)); + else + { + // get native metaobjects for the entire derivation lattice + // up to, but not including, the current metaobject. + size_t moCount = 1; + + for (void* tmp = moId;;) + { + tmp = qtd_QMetaObject_superClass(tmp); + if (!tmp) + return null; + + if (tmp == nativeId) + break; + moCount++; + } + + void*[] moIds = (cast(void**)alloca(moCount * (void*).sizeof))[0..moCount]; + + moIds[--moCount] = moId; + while (moCount > 0) + moIds[--moCount] = moId = qtd_QMetaObject_superClass(moId); + + auto mo = lookupDerived(moIds); + result = static_cast!(QObject)(mo._createWrapper(nativeObjId, flags)); + } + } + } + + return result; + } +} + +extern(C) void* qtd_QMetaObject_superClass(void* nativeId); \ No newline at end of file