288
|
1 module qt.qtd.MetaMarshall;
|
|
2
|
|
3 import std.traits;
|
|
4
|
302
|
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 }
|
|
32
|
288
|
33 template isQObjectType(T) // is a QObject type that belongs to the library
|
|
34 {
|
292
|
35 enum isQObjectType = is(T.__isQObjectType);
|
288
|
36 }
|
|
37
|
293
|
38 template isObjectType(T) // is a Qt Object type that belongs to the library
|
288
|
39 {
|
292
|
40 enum isObjectType = is(T.__isObjectType);
|
288
|
41 }
|
|
42
|
293
|
43 template isValueType(T) // is a Qt Value type that belongs to the library
|
288
|
44 {
|
293
|
45 enum isValueType = is(T.__isValueType);
|
288
|
46 }
|
|
47
|
|
48 template isNativeType(T) // type that doesn't require conversion i.e. is the same in C++ and D
|
|
49 {
|
302
|
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);
|
288
|
56 }
|
|
57
|
|
58 // converts an argumnent from C++ to D in qt_metacall
|
|
59 string metaCallArgument(T)(string ptr)
|
|
60 {
|
|
61 static if (isQObjectType!T)
|
|
62 return T.stringof ~ ".__getObject(*cast(void**)(" ~ ptr ~ "))";
|
|
63 else static if (isNativeType!T)
|
|
64 return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")";
|
302
|
65 else static if (isStringType!T)
|
|
66 return "QStringUtil.toNativeString(" ~ ptr ~ ")";
|
288
|
67 else
|
|
68 return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")";
|
|
69 //res = T.stringof;
|
|
70 }
|
|
71
|
|
72 // converts a D argument type to C++ for registering in Qt meta system
|
|
73 string qtDeclArg(T)()
|
|
74 {
|
|
75 static if (isQObjectType!T)
|
|
76 return T.stringof ~ "*";
|
302
|
77 else static if (isStringType!T)
|
|
78 return "QString";
|
288
|
79 else static if (isNativeType!T)
|
302
|
80 return Unqual!T.stringof;
|
288
|
81 else
|
|
82 return T.stringof;
|
|
83 }
|
|
84
|
|
85 // converts an argument from D to C++ in a signal emitter
|
|
86 string convertSignalArgument(T)(string arg)
|
|
87 {
|
|
88 static if (isQObjectType!T)
|
|
89 return arg ~ ".__nativeId";
|
302
|
90 else static if (isStringType!T)
|
|
91 return "_qt" ~ arg;
|
288
|
92 else static if (isNativeType!T)
|
|
93 return arg;
|
|
94 else
|
|
95 return arg;
|
|
96 }
|
302
|
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 }
|