Mercurial > projects > dstep
diff 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 |
line wrap: on
line diff
--- a/dstep/objc/bridge/TypeEncoding.d Mon Aug 03 15:31:48 2009 +0200 +++ b/dstep/objc/bridge/TypeEncoding.d Sun Jan 03 22:06:11 2010 +0100 @@ -14,6 +14,7 @@ import dstep.internal.String; import dstep.internal.Traits; +import dstep.objc.bridge.Type; import dstep.objc.objc; import dstep.objc.runtime; @@ -32,7 +33,7 @@ foreach (T ; TL) { - static if (is (T == id) || is (T == class)) + static if (is (T == id) || needsEncapsulation!(T)) s ~= _C_ID; else static if (is (T == Class)) @@ -111,6 +112,22 @@ const encodeCallable = encode!(ReturnTypeOf!(typeof(Callable)), id, SEL, ParameterTupleOf!(typeof(Callable))); } +template checkSelector (string selector, ARGS...) +{ + const checkSelector = checkSelectorImpl!(selector, ARGS); +} + +private bool checkSelectorImpl (string selector, ARGS...) () +{ + size_t i = 0; + + foreach (c ; selector) + if (c == ':') + i++; + + return i == ARGS.length; +} + /** * Builds a string representing a selector out of the given function * @@ -154,10 +171,27 @@ return result; } -/** - * Converts the given string representing of a OSType into an integer. - */ +template decimalDigit (int n) // [3] +{ + const string decimalDigit = "0123456789"[n .. n + 1]; +} + +template itoa (long n) +{ + static if (n < 0) + const string itoa = "-" ~ itoa!(-n); + + else static if (n < 10) + const string itoa = decimalDigit!(n); + + else + const string itoa = itoa!(n / 10L) ~ decimalDigit!(n % 10L); +} + + +/// Converts the given string representing an OSType into an integer. template getOSType (string osType) { + static assert(osType.length == 4, `dstep.objc.bridge.TypeEncoding.getOSType: The length of the given string, "` ~ osType ~ `", is not four`); const getOSType = (cast(int)osType[0]) << 24 | (cast(int)osType[1]) << 16 | (cast(int)osType[2]) << 8 | (cast(int)osType[3]); } \ No newline at end of file