diff 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 diff
--- a/dstep/objc/bridge/Wrapper.d	Mon Aug 03 15:31:48 2009 +0200
+++ b/dstep/objc/bridge/Wrapper.d	Sun Jan 03 22:06:11 2010 +0100
@@ -13,37 +13,43 @@
 import dstep.objc.objc;
 import dstep.objc.runtime;
 
-class ObjcWrapper
+/// Wrapper class for an Objective-C object. 
+abstract class ObjcWrapper
 {	
-	static private Class objcClass_;
 	static private Class objcSuperClass_;
 	
 	private id objcObject_;
 	private objc_super* objcSuper_;
-	
-	this ()
-	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id ret = Bridge.invokeObjcMethod!(id, "init")(objcObject);
 		
-		if (ret)
-			objcObject = ret;
-		
-		dObject = this;
-	}
-		
-	/// Initialize object from an Objective-C object instance to wrap.
+	/// Initializes object from an Objective-C object instance to wrap.
 	this (id object)
 	{
-		objcObject_ = 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_)
@@ -52,22 +58,26 @@
 		return objcSuperClass_;
 	}
 	
-	id objcObject ()
+	/// Gets the Objective-C object instance pointer. 
+	final id objcObject ()
 	{
 		return objcObject_;
 	}
 	
-	protected id objcObject (id object)
+	/// Sets the Objective-C object instance pointer. 
+	protected final id objcObject (id object)
 	{
 		return objcObject_ = object;
 	}
 	
-	protected void dObject (Object dObject)
+	/// Sets the D object in the receiver's Objective-C instance
+	protected final void dObject (Object dObject)
 	{
-		Bridge.setDObject(dObject, objcObject);
+		Bridge.instance.setDObject(dObject, objcObject);
 	}
 	
-	objc_super* objcSuper ()
+	/// Gets the objc_super instance of the receiver
+	protected final objc_super* objcSuper ()
 	{
 		if (!objcSuper_)
 		{