Mercurial > projects > dstep
comparison dstep/objc/bridge/TypeEncoding.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 | 07194b026fa4 |
children |
comparison
equal
deleted
inserted
replaced
15:7ff919f595d5 | 16:19885b43130e |
---|---|
12 else | 12 else |
13 import std.traits; | 13 import std.traits; |
14 | 14 |
15 import dstep.internal.String; | 15 import dstep.internal.String; |
16 import dstep.internal.Traits; | 16 import dstep.internal.Traits; |
17 import dstep.objc.bridge.Type; | |
17 import dstep.objc.objc; | 18 import dstep.objc.objc; |
18 import dstep.objc.runtime; | 19 import dstep.objc.runtime; |
19 | 20 |
20 /** | 21 /** |
21 * Creates the encoded (mangled) form of a type for the | 22 * Creates the encoded (mangled) form of a type for the |
30 { | 31 { |
31 char[] s; | 32 char[] s; |
32 | 33 |
33 foreach (T ; TL) | 34 foreach (T ; TL) |
34 { | 35 { |
35 static if (is (T == id) || is (T == class)) | 36 static if (is (T == id) || needsEncapsulation!(T)) |
36 s ~= _C_ID; | 37 s ~= _C_ID; |
37 | 38 |
38 else static if (is (T == Class)) | 39 else static if (is (T == Class)) |
39 s ~= _C_CLASS; | 40 s ~= _C_CLASS; |
40 | 41 |
109 static assert(isCallableType!(typeof(Callable)), "dstep.objc.bridge.TypeCoding.encodeCallable: The given type is not a callable type"); | 110 static assert(isCallableType!(typeof(Callable)), "dstep.objc.bridge.TypeCoding.encodeCallable: The given type is not a callable type"); |
110 | 111 |
111 const encodeCallable = encode!(ReturnTypeOf!(typeof(Callable)), id, SEL, ParameterTupleOf!(typeof(Callable))); | 112 const encodeCallable = encode!(ReturnTypeOf!(typeof(Callable)), id, SEL, ParameterTupleOf!(typeof(Callable))); |
112 } | 113 } |
113 | 114 |
115 template checkSelector (string selector, ARGS...) | |
116 { | |
117 const checkSelector = checkSelectorImpl!(selector, ARGS); | |
118 } | |
119 | |
120 private bool checkSelectorImpl (string selector, ARGS...) () | |
121 { | |
122 size_t i = 0; | |
123 | |
124 foreach (c ; selector) | |
125 if (c == ':') | |
126 i++; | |
127 | |
128 return i == ARGS.length; | |
129 } | |
130 | |
114 /** | 131 /** |
115 * Builds a string representing a selector out of the given function | 132 * Builds a string representing a selector out of the given function |
116 * | 133 * |
117 * It will build the string like this: | 134 * It will build the string like this: |
118 * | 135 * |
152 result ~= str ~ ':'; | 169 result ~= str ~ ':'; |
153 | 170 |
154 return result; | 171 return result; |
155 } | 172 } |
156 | 173 |
157 /** | 174 template decimalDigit (int n) // [3] |
158 * Converts the given string representing of a OSType into an integer. | 175 { |
159 */ | 176 const string decimalDigit = "0123456789"[n .. n + 1]; |
177 } | |
178 | |
179 template itoa (long n) | |
180 { | |
181 static if (n < 0) | |
182 const string itoa = "-" ~ itoa!(-n); | |
183 | |
184 else static if (n < 10) | |
185 const string itoa = decimalDigit!(n); | |
186 | |
187 else | |
188 const string itoa = itoa!(n / 10L) ~ decimalDigit!(n % 10L); | |
189 } | |
190 | |
191 | |
192 /// Converts the given string representing an OSType into an integer. | |
160 template getOSType (string osType) | 193 template getOSType (string osType) |
161 { | 194 { |
195 static assert(osType.length == 4, `dstep.objc.bridge.TypeEncoding.getOSType: The length of the given string, "` ~ osType ~ `", is not four`); | |
162 const getOSType = (cast(int)osType[0]) << 24 | (cast(int)osType[1]) << 16 | (cast(int)osType[2]) << 8 | (cast(int)osType[3]); | 196 const getOSType = (cast(int)osType[0]) << 24 | (cast(int)osType[1]) << 16 | (cast(int)osType[2]) << 8 | (cast(int)osType[3]); |
163 } | 197 } |