Mercurial > projects > dstep
comparison dstep/foundation/NSProtocolChecker.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 | 89f3c3ef1fd2 |
children | b9de51448c6b |
comparison
equal
deleted
inserted
replaced
15:7ff919f595d5 | 16:19885b43130e |
---|---|
7 module dstep.foundation.NSProtocolChecker; | 7 module dstep.foundation.NSProtocolChecker; |
8 | 8 |
9 import dstep.foundation.NSObject; | 9 import dstep.foundation.NSObject; |
10 import dstep.foundation.NSProxy; | 10 import dstep.foundation.NSProxy; |
11 import dstep.objc.bridge.Bridge; | 11 import dstep.objc.bridge.Bridge; |
12 import dstep.objc.objc : id; | 12 import dstep.objc.objc; |
13 | |
14 | |
15 import dstep.objc.runtime; | |
16 | |
17 const TNSProtocolCheckerCreation = ` | |
18 | |
19 static Object protocolCheckerWithTarget (NSObject anObject, Protocol aProtocol) | |
20 { | |
21 return invokeObjcSuperClass!(Object, "protocolCheckerWithTarget:protocol:", NSObject, Protocol)(anObject, aProtocol); | |
22 } | |
23 | |
24 Object initWithTarget (NSObject anObject, Protocol aProtocol) | |
25 { | |
26 return invokeObjcSelf!(Object, "initWithTarget:protocol:", NSObject, Protocol)(anObject, aProtocol); | |
27 } | |
28 | |
29 this (NSObject anObject, Protocol aProtocol) | |
30 { | |
31 typeof(this).alloc.initWithTarget(anObject, aProtocol); | |
32 } | |
33 `; | |
13 | 34 |
14 class NSProtocolChecker : NSProxy | 35 class NSProtocolChecker : NSProxy |
15 { | 36 { |
16 mixin ObjcWrap; | 37 mixin (ObjcWrap); |
17 mixin TNSProtocolCheckerCreation; | 38 |
39 this () | |
40 { | |
41 super(typeof(this).alloc.init.objcObject); | |
42 } | |
43 | |
44 typeof(this) init () | |
45 { | |
46 return invokeObjcSelf!(typeof(this), "init"); | |
47 } | |
18 | 48 |
19 Protocol protocol () | 49 Protocol protocol () |
20 { | 50 { |
21 return invokeObjcSelf!(Protocol, "protocol"); | 51 return invokeObjcSelf!(Protocol, "protocol"); |
22 } | 52 } |
23 | 53 |
24 NSObject target () | 54 NSObject target () |
25 { | 55 { |
26 return invokeObjcSelf!(NSObject, "target"); | 56 return invokeObjcSelf!(NSObject, "target"); |
27 } | 57 } |
28 } | 58 |
29 | 59 // TNSProtocolCheckerCreation |
30 template TNSProtocolCheckerCreation () | |
31 { | |
32 static Object protocolCheckerWithTarget (NSObject anObject, Protocol aProtocol) | 60 static Object protocolCheckerWithTarget (NSObject anObject, Protocol aProtocol) |
33 { | 61 { |
34 return invokeObjcSelfClass!(Object, "protocolCheckerWithTarget:protocol:", NSObject, Protocol)(anObject, aProtocol); | 62 return invokeObjcSuperClass!(Object, "protocolCheckerWithTarget:protocol:", NSObject, Protocol)(anObject, aProtocol); |
35 } | 63 } |
36 | 64 |
37 Object initWithTarget (NSObject anObject, Protocol aProtocol) | 65 Object initWithTarget (NSObject anObject, Protocol aProtocol) |
38 { | 66 { |
39 return invokeObjcSelf!(Object, "initWithTarget:protocol:", NSObject, Protocol)(anObject, aProtocol); | 67 return invokeObjcSelf!(Object, "initWithTarget:protocol:", NSObject, Protocol)(anObject, aProtocol); |
40 } | 68 } |
41 | 69 |
42 this (NSObject anObject, Protocol aProtocol) | 70 this (NSObject anObject, Protocol aProtocol) |
43 { | 71 { |
44 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 72 typeof(this).alloc.initWithTarget(anObject, aProtocol); |
45 id result = Bridge.invokeObjcMethod!(id, "initWithTarget:protocol:", NSObject, Protocol)(objcObject, anObject, aProtocol); | |
46 | |
47 if (result) | |
48 objcObject = ret; | |
49 | |
50 dObject = this; | |
51 } | 73 } |
52 } | 74 } |
53 |