Mercurial > projects > qtd
comparison qt/qtd/MetaMarshall.d @ 302:55ee4603365d signals
string arguments for signals
author | eldar_ins@eldar-laptop |
---|---|
date | Sat, 12 Dec 2009 03:22:54 +0500 |
parents | 8627891e4556 |
children | 98b211f3ee34 |
comparison
equal
deleted
inserted
replaced
301:4d8481385c71 | 302:55ee4603365d |
---|---|
1 module qt.qtd.MetaMarshall; | 1 module qt.qtd.MetaMarshall; |
2 | 2 |
3 import std.traits; | 3 import std.traits; |
4 | |
5 // shouldn't be here | |
6 | |
7 string __toString(long v) | |
8 { | |
9 if (v == 0) | |
10 return "0"; | |
11 | |
12 string ret; | |
13 | |
14 bool neg; | |
15 if (v < 0) | |
16 { | |
17 neg = true; | |
18 v = -v; | |
19 } | |
20 | |
21 while (v != 0) | |
22 { | |
23 ret = cast(char)(v % 10 + '0') ~ ret; | |
24 v = cast(long)(v / 10); | |
25 } | |
26 | |
27 if (neg) | |
28 ret = "-" ~ ret; | |
29 | |
30 return ret; | |
31 } | |
4 | 32 |
5 template isQObjectType(T) // is a QObject type that belongs to the library | 33 template isQObjectType(T) // is a QObject type that belongs to the library |
6 { | 34 { |
7 enum isQObjectType = is(T.__isQObjectType); | 35 enum isQObjectType = is(T.__isQObjectType); |
8 } | 36 } |
17 enum isValueType = is(T.__isValueType); | 45 enum isValueType = is(T.__isValueType); |
18 } | 46 } |
19 | 47 |
20 template isNativeType(T) // type that doesn't require conversion i.e. is the same in C++ and D | 48 template isNativeType(T) // type that doesn't require conversion i.e. is the same in C++ and D |
21 { | 49 { |
22 enum isNativeType = isNumeric!T || is(T == bool); | 50 enum isNativeType = isNumeric!T || is(T == bool) || is(T == struct); |
51 } | |
52 | |
53 template isStringType(T) // string type | |
54 { | |
55 enum isStringType = is(T == string); | |
23 } | 56 } |
24 | 57 |
25 // converts an argumnent from C++ to D in qt_metacall | 58 // converts an argumnent from C++ to D in qt_metacall |
26 string metaCallArgument(T)(string ptr) | 59 string metaCallArgument(T)(string ptr) |
27 { | 60 { |
28 static if (isQObjectType!T) | 61 static if (isQObjectType!T) |
29 return T.stringof ~ ".__getObject(*cast(void**)(" ~ ptr ~ "))"; | 62 return T.stringof ~ ".__getObject(*cast(void**)(" ~ ptr ~ "))"; |
30 else static if (isNativeType!T) | 63 else static if (isNativeType!T) |
31 return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")"; | 64 return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")"; |
65 else static if (isStringType!T) | |
66 return "QStringUtil.toNativeString(" ~ ptr ~ ")"; | |
32 else | 67 else |
33 return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")"; | 68 return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")"; |
34 //res = T.stringof; | 69 //res = T.stringof; |
35 } | 70 } |
36 | 71 |
37 // converts a D argument type to C++ for registering in Qt meta system | 72 // converts a D argument type to C++ for registering in Qt meta system |
38 string qtDeclArg(T)() | 73 string qtDeclArg(T)() |
39 { | 74 { |
40 static if (isQObjectType!T) | 75 static if (isQObjectType!T) |
41 return T.stringof ~ "*"; | 76 return T.stringof ~ "*"; |
77 else static if (isStringType!T) | |
78 return "QString"; | |
42 else static if (isNativeType!T) | 79 else static if (isNativeType!T) |
43 return T.stringof; | 80 return Unqual!T.stringof; |
44 else | 81 else |
45 return T.stringof; | 82 return T.stringof; |
46 } | 83 } |
47 | 84 |
48 // converts an argument from D to C++ in a signal emitter | 85 // converts an argument from D to C++ in a signal emitter |
49 string convertSignalArgument(T)(string arg) | 86 string convertSignalArgument(T)(string arg) |
50 { | 87 { |
51 static if (isQObjectType!T) | 88 static if (isQObjectType!T) |
52 return arg ~ ".__nativeId"; | 89 return arg ~ ".__nativeId"; |
90 else static if (isStringType!T) | |
91 return "_qt" ~ arg; | |
53 else static if (isNativeType!T) | 92 else static if (isNativeType!T) |
54 return arg; | 93 return arg; |
55 else | 94 else |
56 return arg; | 95 return arg; |
57 } | 96 } |
97 | |
98 string prepareSignalArguments(Args...)() | |
99 { | |
100 string res; | |
101 foreach(i, _; Args) | |
102 static if (isStringType!(Args[i])) | |
103 res ~= "auto _qt_t" ~ __toString(i) ~ " = QString(_t" ~ __toString(i) ~ ");\n"; | |
104 return res; | |
105 } |