288
|
1 module qt.qtd.MetaMarshall;
|
|
2
|
|
3 import std.traits;
|
|
4
|
|
5 template isQObjectType(T) // is a QObject type that belongs to the library
|
|
6 {
|
|
7 enum isQObjectType = is(typeof(mixin("T." ~ "__isQObjectType")));
|
|
8 }
|
|
9
|
|
10 template isObjectType(T) // is a QObject type that belongs to the library
|
|
11 {
|
|
12 enum isQObjectType = is(typeof(mixin("T." ~ "__isObjectType")));
|
|
13 }
|
|
14
|
|
15 template isValueType(T) // is a QObject type that belongs to the library
|
|
16 {
|
|
17 enum isQObjectType = is(typeof(mixin("T." ~ "__isValueType")));
|
|
18 }
|
|
19
|
|
20 template isNativeType(T) // type that doesn't require conversion i.e. is the same in C++ and D
|
|
21 {
|
|
22 enum isNativeType = isNumeric!T || is(T == bool);
|
|
23 }
|
|
24
|
|
25 // converts an argumnent from C++ to D in qt_metacall
|
|
26 string metaCallArgument(T)(string ptr)
|
|
27 {
|
|
28 static if (isQObjectType!T)
|
|
29 return T.stringof ~ ".__getObject(*cast(void**)(" ~ ptr ~ "))";
|
|
30 else static if (isNativeType!T)
|
|
31 return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")";
|
|
32 else
|
|
33 return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")";
|
|
34 //res = T.stringof;
|
|
35 }
|
|
36
|
|
37 // converts a D argument type to C++ for registering in Qt meta system
|
|
38 string qtDeclArg(T)()
|
|
39 {
|
|
40 static if (isQObjectType!T)
|
|
41 return T.stringof ~ "*";
|
|
42 else static if (isNativeType!T)
|
|
43 return T.stringof;
|
|
44 else
|
|
45 return T.stringof;
|
|
46 }
|
|
47
|
|
48 // converts an argument from D to C++ in a signal emitter
|
|
49 string convertSignalArgument(T)(string arg)
|
|
50 {
|
|
51 static if (isQObjectType!T)
|
|
52 return arg ~ ".__nativeId";
|
|
53 else static if (isNativeType!T)
|
|
54 return arg;
|
|
55 else
|
|
56 return arg;
|
|
57 }
|