Mercurial > projects > dstep
comparison dstep/objc/bridge/Capsule.d @ 25:b9de51448c6b
Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Tue, 06 Apr 2010 11:37:27 +0200 |
parents | ab33fc0c3fc1 |
children |
comparison
equal
deleted
inserted
replaced
24:ab33fc0c3fc1 | 25:b9de51448c6b |
---|---|
18 { | 18 { |
19 import GC = std.gc : addRoot; | 19 import GC = std.gc : addRoot; |
20 import std.math : log2; | 20 import std.math : log2; |
21 } | 21 } |
22 | 22 |
23 import dstep.internal.Reflection; | |
23 import dstep.internal.String; | 24 import dstep.internal.String; |
24 import dstep.objc.bridge.Bridge; | 25 import dstep.objc.bridge.Bridge; |
25 import dstep.objc.bridge.Type; | 26 import dstep.objc.bridge.Type; |
26 import dstep.objc.bridge.TypeEncoding; | 27 import dstep.objc.bridge.TypeEncoding; |
27 import dstep.objc.bridge.Wrapper; | 28 import dstep.objc.bridge.Wrapper; |
202 */ | 203 */ |
203 T decapsule (T) (ObjcType!(T) value) | 204 T decapsule (T) (ObjcType!(T) value) |
204 { | 205 { |
205 static if (needsEncapsulation!(T)) | 206 static if (needsEncapsulation!(T)) |
206 { | 207 { |
207 static if (hasIdConstructor!(T)) | 208 static if (is(T : ObjcWrapper)) |
208 { | 209 { |
209 T instance = cast(T) Bridge.getDObject(value); | 210 T instance = cast(T) Bridge.getDObject(value); |
210 | 211 |
211 return instance ? instance : new T(value); | 212 return instance ? instance : newWrapper!(T)(value); |
212 } | 213 } |
213 | 214 |
214 else | 215 else |
215 return cast(T) Bridge.getDObject(value); | 216 return cast(T) Bridge.getDObject(value); |
216 } | 217 } |
217 | 218 |
218 else | 219 else |
219 return value; | 220 return value; |
220 } | 221 } |
221 | 222 |
223 private T newWrapper (T) (ObjcType!(T) value) | |
224 { | |
225 auto wrapper = cast(ObjcWrapper) newInstance(T.classinfo); | |
226 setValueOfField!("objcObject_")(wrapper, value); | |
227 Bridge.setDObject(wrapper, value); | |
228 | |
229 return cast(T) wrapper; | |
230 } | |
231 | |
222 private id encapsuleString (string str) | 232 private id encapsuleString (string str) |
223 { | 233 { |
224 enum { NSUTF8StringEncoding = 4 } | 234 enum { NSUTF8StringEncoding = 4 } |
225 | 235 |
226 return objc.getClass!("NSString").msgSend(sel.registerName!("alloc")).msgSend(sel.registerName!("initWithBytes:length:encoding:"), str.ptr, str.length, NSUTF8StringEncoding); | 236 return objc.getClass!("NSString").msgSend(sel.registerName!("alloc")).msgSend(sel.registerName!("initWithBytes:length:encoding:"), str.ptr, str.length, NSUTF8StringEncoding); |