Mercurial > projects > dstep
annotate 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 |
rev | line source |
---|---|
1 | 1 /** |
2 * Copyright: Copyright (c) 2009 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Feb 1, 2009 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module dstep.objc.bridge.Wrapper; | |
8 | |
9 import dstep.internal.String; | |
10 import dstep.objc.bridge.Bridge; | |
11 import dstep.objc.bridge.Capsule; | |
12 import dstep.objc.message; | |
13 import dstep.objc.objc; | |
14 import dstep.objc.runtime; | |
15 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
16 /// Wrapper class for an Objective-C object. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
17 abstract class ObjcWrapper |
1 | 18 { |
19 static private Class objcSuperClass_; | |
20 | |
21 private id objcObject_; | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
22 private objc_super* objcSuper_; |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
23 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
24 /// Initializes object from an Objective-C object instance to wrap. |
1 | 25 this (id object) |
26 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
27 objcObject = object; |
1 | 28 dObject = this; |
29 } | |
30 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
31 /// Initializes object from another wrapper. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
32 this (ObjcWrapper wrapper) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
33 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
34 if (wrapper) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
35 this(wrapper.objcObject); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
36 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
37 else |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
38 this(cast(id) null); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
39 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
40 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
41 ~this () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
42 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
43 Bridge.deregisterObjcInstance(objcObject_); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
44 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
45 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
46 /// Returns the Objective-C class for this wrapper |
1 | 47 static Class objcClass () |
48 { | |
49 return capsuleClass; | |
50 } | |
51 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
52 /// Returns the Objective-C superclass for this wrapper |
1 | 53 static Class objcSuperClass () |
54 { | |
55 if (!objcSuperClass_) | |
56 return objcSuperClass_ = objcClass.getSuperclass; | |
57 | |
58 return objcSuperClass_; | |
59 } | |
60 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
61 /// Gets the Objective-C object instance pointer. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
62 final id objcObject () |
1 | 63 { |
64 return objcObject_; | |
65 } | |
66 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
67 /// Sets the Objective-C object instance pointer. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
68 protected final id objcObject (id object) |
1 | 69 { |
70 return objcObject_ = object; | |
71 } | |
72 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
73 /// Sets the D object in the receiver's Objective-C instance |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
74 protected final void dObject (Object dObject) |
1 | 75 { |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
76 Bridge.instance.setDObject(dObject, objcObject); |
1 | 77 } |
78 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
79 /// Gets the objc_super instance of the receiver |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
80 protected final objc_super* objcSuper () |
1 | 81 { |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
82 if (!objcSuper_) |
1 | 83 { |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
84 objcSuper_ = new objc_super; |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
85 objcSuper_.receiver = objcObject; |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
86 objcSuper_.cls = objcSuperClass; |
1 | 87 } |
88 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
89 return objcSuper_; |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
90 } |
1 | 91 } |