Mercurial > projects > dstep
view dstep/objc/bridge/Wrapper.d @ 16:19885b43130e
Huge update, the bridge actually works now
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 03 Jan 2010 22:06:11 +0100 |
parents | 9fd439a28ce3 |
children | b9de51448c6b |
line wrap: on
line source
/** * Copyright: Copyright (c) 2009 Jacob Carlborg. * Authors: Jacob Carlborg * Version: Initial created: Feb 1, 2009 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) */ module dstep.objc.bridge.Wrapper; import dstep.internal.String; import dstep.objc.bridge.Bridge; import dstep.objc.bridge.Capsule; import dstep.objc.message; import dstep.objc.objc; import dstep.objc.runtime; /// Wrapper class for an Objective-C object. abstract class ObjcWrapper { static private Class objcSuperClass_; private id objcObject_; private objc_super* objcSuper_; /// Initializes object from an Objective-C object instance to wrap. this (id object) { objcObject = object; dObject = this; } /// Initializes object from another wrapper. this (ObjcWrapper wrapper) { if (wrapper) this(wrapper.objcObject); else this(cast(id) null); } ~this () { Bridge.deregisterObjcInstance(objcObject_); } /// Returns the Objective-C class for this wrapper static Class objcClass () { return capsuleClass; } /// Returns the Objective-C superclass for this wrapper static Class objcSuperClass () { if (!objcSuperClass_) return objcSuperClass_ = objcClass.getSuperclass; return objcSuperClass_; } /// Gets the Objective-C object instance pointer. final id objcObject () { return objcObject_; } /// Sets the Objective-C object instance pointer. protected final id objcObject (id object) { return objcObject_ = object; } /// Sets the D object in the receiver's Objective-C instance protected final void dObject (Object dObject) { Bridge.instance.setDObject(dObject, objcObject); } /// Gets the objc_super instance of the receiver protected final objc_super* objcSuper () { if (!objcSuper_) { objcSuper_ = new objc_super; objcSuper_.receiver = objcObject; objcSuper_.cls = objcSuperClass; } return objcSuper_; } }