Mercurial > projects > dstep
annotate dstep/objc/bridge/Wrapper.d @ 27:57371c29ef73 default tip
ObjcWrap is now automatically mixed in. Added support for building as a dylib with DMD.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Fri, 09 Apr 2010 23:00:22 +0200 |
parents | b9de51448c6b |
children |
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_; |
27
57371c29ef73
ObjcWrap is now automatically mixed in. Added support for building as a dylib with DMD.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
23 |
57371c29ef73
ObjcWrap is now automatically mixed in. Added support for building as a dylib with DMD.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
24 this () {} |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
25 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
26 /// Initializes object from an Objective-C object instance to wrap. |
1 | 27 this (id object) |
28 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
29 objcObject = object; |
1 | 30 dObject = this; |
31 } | |
32 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
33 /// Initializes object from another wrapper. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
34 this (ObjcWrapper wrapper) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
35 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
36 if (wrapper) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
37 this(wrapper.objcObject); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
38 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
39 else |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
40 this(cast(id) null); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
41 } |
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 ~this () |
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 Bridge.deregisterObjcInstance(objcObject_); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
46 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
47 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
48 /// Returns the Objective-C class for this wrapper |
1 | 49 static Class objcClass () |
50 { | |
51 return capsuleClass; | |
52 } | |
53 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
54 /// Returns the Objective-C superclass for this wrapper |
1 | 55 static Class objcSuperClass () |
56 { | |
57 if (!objcSuperClass_) | |
58 return objcSuperClass_ = objcClass.getSuperclass; | |
59 | |
60 return objcSuperClass_; | |
61 } | |
62 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
63 /// Gets the Objective-C object instance pointer. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
64 final id objcObject () |
1 | 65 { |
66 return objcObject_; | |
67 } | |
68 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
69 /// Sets the Objective-C object instance pointer. |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
70 protected final id objcObject (id object) |
1 | 71 { |
72 return objcObject_ = object; | |
73 } | |
74 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
75 /// 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
|
76 protected final void dObject (Object dObject) |
1 | 77 { |
25
b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
Jacob Carlborg <doob@me.com>
parents:
16
diff
changeset
|
78 Bridge.setDObject(dObject, objcObject); |
1 | 79 } |
80 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
2
diff
changeset
|
81 /// 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
|
82 protected final objc_super* 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 if (!objcSuper_) |
1 | 85 { |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
86 objcSuper_ = new objc_super; |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
87 objcSuper_.receiver = objcObject; |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
88 objcSuper_.cls = objcSuperClass; |
1 | 89 } |
90 | |
2
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
91 return objcSuper_; |
9fd439a28ce3
Adapted the scripts for the new bridge + a lot more
Jacob Carlborg <doob@me.com>
parents:
1
diff
changeset
|
92 } |
1 | 93 } |