Mercurial > projects > qtd
annotate qt/qtd/MetaMarshall.d @ 319:894d40eb89b6 signals
new signals and slots syntax. have to use prefixes now: signal_fooed and slot_onFooed
author | eldar_ins@eldar-laptop |
---|---|
date | Fri, 25 Dec 2009 21:48:32 +0500 |
parents | ce07227f00c1 |
children | 7a3c43424dca |
rev | line source |
---|---|
288 | 1 module qt.qtd.MetaMarshall; |
2 | |
3 import std.traits; | |
4 | |
319
894d40eb89b6
new signals and slots syntax. have to use prefixes now: signal_fooed and slot_onFooed
eldar_ins@eldar-laptop
parents:
318
diff
changeset
|
5 import qt.qtd.Meta; |
309 | 6 |
288 | 7 template isQObjectType(T) // is a QObject type that belongs to the library |
8 { | |
292 | 9 enum isQObjectType = is(T.__isQObjectType); |
288 | 10 } |
11 | |
293 | 12 template isObjectType(T) // is a Qt Object type that belongs to the library |
288 | 13 { |
292 | 14 enum isObjectType = is(T.__isObjectType); |
288 | 15 } |
16 | |
293 | 17 template isValueType(T) // is a Qt Value type that belongs to the library |
288 | 18 { |
293 | 19 enum isValueType = is(T.__isValueType); |
288 | 20 } |
21 | |
22 template isNativeType(T) // type that doesn't require conversion i.e. is the same in C++ and D | |
23 { | |
302 | 24 enum isNativeType = isNumeric!T || is(T == bool) || is(T == struct); |
25 } | |
26 | |
27 template isStringType(T) // string type | |
28 { | |
29 enum isStringType = is(T == string); | |
288 | 30 } |
31 | |
309 | 32 template isQList(T) |
33 { | |
319
894d40eb89b6
new signals and slots syntax. have to use prefixes now: signal_fooed and slot_onFooed
eldar_ins@eldar-laptop
parents:
318
diff
changeset
|
34 enum isQList = ctfeStartsWith(Unqual!(T).stringof, "QList!"); |
309 | 35 } |
36 | |
288 | 37 // converts an argumnent from C++ to D in qt_metacall |
38 string metaCallArgument(T)(string ptr) | |
39 { | |
303 | 40 static if (isQObjectType!T || isObjectType!T) |
288 | 41 return T.stringof ~ ".__getObject(*cast(void**)(" ~ ptr ~ "))"; |
318 | 42 else static if (isValueType!T) |
43 return "new " ~ T.stringof ~ "(" ~ T.stringof ~ ".__constructNativeCopy(" ~ ptr ~ "))"; | |
288 | 44 else static if (isNativeType!T) |
45 return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")"; | |
302 | 46 else static if (isStringType!T) |
47 return "QStringUtil.toNativeString(" ~ ptr ~ ")"; | |
288 | 48 else |
49 return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")"; | |
50 //res = T.stringof; | |
51 } | |
52 | |
53 // converts a D argument type to C++ for registering in Qt meta system | |
54 string qtDeclArg(T)() | |
55 { | |
303 | 56 static if (isQObjectType!T || isObjectType!T) |
288 | 57 return T.stringof ~ "*"; |
318 | 58 else static if (isValueType!T) |
59 return T.stringof; | |
302 | 60 else static if (isStringType!T) |
61 return "QString"; | |
309 | 62 else static if (isQList!T) |
318 | 63 { |
64 alias templateParam!T ElementType; | |
65 static if (is(ElementType == string)) | |
66 return "QStringList"; | |
67 else | |
68 return "QList<" ~ qtDeclArg!(templateParam!T)() ~ ">"; | |
69 } | |
288 | 70 else static if (isNativeType!T) |
302 | 71 return Unqual!T.stringof; |
288 | 72 else |
73 return T.stringof; | |
74 } | |
75 | |
76 // converts an argument from D to C++ in a signal emitter | |
77 string convertSignalArgument(T)(string arg) | |
78 { | |
303 | 79 static if (isQObjectType!T || isObjectType!T) |
318 | 80 return "&" ~ arg ~ ".__nativeId"; |
81 else static if (isValueType!T) | |
288 | 82 return arg ~ ".__nativeId"; |
302 | 83 else static if (isStringType!T) |
318 | 84 return "&_qt" ~ arg; |
288 | 85 else static if (isNativeType!T) |
318 | 86 return "&" ~ arg; |
288 | 87 else |
318 | 88 return "&" ~ arg; |
288 | 89 } |
302 | 90 |
91 string prepareSignalArguments(Args...)() | |
92 { | |
93 string res; | |
94 foreach(i, _; Args) | |
95 static if (isStringType!(Args[i])) | |
96 res ~= "auto _qt_t" ~ __toString(i) ~ " = QString(_t" ~ __toString(i) ~ ");\n"; | |
97 return res; | |
98 } |