Mercurial > projects > dstep
comparison 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 |
comparison
equal
deleted
inserted
replaced
15:7ff919f595d5 | 16:19885b43130e |
---|---|
11 import dstep.objc.bridge.Capsule; | 11 import dstep.objc.bridge.Capsule; |
12 import dstep.objc.message; | 12 import dstep.objc.message; |
13 import dstep.objc.objc; | 13 import dstep.objc.objc; |
14 import dstep.objc.runtime; | 14 import dstep.objc.runtime; |
15 | 15 |
16 class ObjcWrapper | 16 /// Wrapper class for an Objective-C object. |
17 abstract class ObjcWrapper | |
17 { | 18 { |
18 static private Class objcClass_; | |
19 static private Class objcSuperClass_; | 19 static private Class objcSuperClass_; |
20 | 20 |
21 private id objcObject_; | 21 private id objcObject_; |
22 private objc_super* objcSuper_; | 22 private objc_super* objcSuper_; |
23 | |
24 this () | |
25 { | |
26 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
27 id ret = Bridge.invokeObjcMethod!(id, "init")(objcObject); | |
28 | 23 |
29 if (ret) | 24 /// Initializes object from an Objective-C object instance to wrap. |
30 objcObject = ret; | |
31 | |
32 dObject = this; | |
33 } | |
34 | |
35 /// Initialize object from an Objective-C object instance to wrap. | |
36 this (id object) | 25 this (id object) |
37 { | 26 { |
38 objcObject_ = object; | 27 objcObject = object; |
39 dObject = this; | 28 dObject = this; |
40 } | 29 } |
41 | 30 |
31 /// Initializes object from another wrapper. | |
32 this (ObjcWrapper wrapper) | |
33 { | |
34 if (wrapper) | |
35 this(wrapper.objcObject); | |
36 | |
37 else | |
38 this(cast(id) null); | |
39 } | |
40 | |
41 ~this () | |
42 { | |
43 Bridge.deregisterObjcInstance(objcObject_); | |
44 } | |
45 | |
46 /// Returns the Objective-C class for this wrapper | |
42 static Class objcClass () | 47 static Class objcClass () |
43 { | 48 { |
44 return capsuleClass; | 49 return capsuleClass; |
45 } | 50 } |
46 | 51 |
52 /// Returns the Objective-C superclass for this wrapper | |
47 static Class objcSuperClass () | 53 static Class objcSuperClass () |
48 { | 54 { |
49 if (!objcSuperClass_) | 55 if (!objcSuperClass_) |
50 return objcSuperClass_ = objcClass.getSuperclass; | 56 return objcSuperClass_ = objcClass.getSuperclass; |
51 | 57 |
52 return objcSuperClass_; | 58 return objcSuperClass_; |
53 } | 59 } |
54 | 60 |
55 id objcObject () | 61 /// Gets the Objective-C object instance pointer. |
62 final id objcObject () | |
56 { | 63 { |
57 return objcObject_; | 64 return objcObject_; |
58 } | 65 } |
59 | 66 |
60 protected id objcObject (id object) | 67 /// Sets the Objective-C object instance pointer. |
68 protected final id objcObject (id object) | |
61 { | 69 { |
62 return objcObject_ = object; | 70 return objcObject_ = object; |
63 } | 71 } |
64 | 72 |
65 protected void dObject (Object dObject) | 73 /// Sets the D object in the receiver's Objective-C instance |
74 protected final void dObject (Object dObject) | |
66 { | 75 { |
67 Bridge.setDObject(dObject, objcObject); | 76 Bridge.instance.setDObject(dObject, objcObject); |
68 } | 77 } |
69 | 78 |
70 objc_super* objcSuper () | 79 /// Gets the objc_super instance of the receiver |
80 protected final objc_super* objcSuper () | |
71 { | 81 { |
72 if (!objcSuper_) | 82 if (!objcSuper_) |
73 { | 83 { |
74 objcSuper_ = new objc_super; | 84 objcSuper_ = new objc_super; |
75 objcSuper_.receiver = objcObject; | 85 objcSuper_.receiver = objcObject; |