Mercurial > projects > qtd
annotate d1/qtd/MetaMarshall.d @ 371:12f60887ed15
add elasticnodes example and necessary changes to the library.
author | Eldar Insafutdinov |
---|---|
date | Wed, 07 Jul 2010 22:54:12 +0100 |
parents | 96a75b1e5b26 |
children |
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 | |
339
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
22 template isQtType(T) |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
23 { |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
24 mixin ("enum isQtType = is(T.__isQtType_" ~ T.stringof ~ ");"); |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
25 } |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
26 /* |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
27 template isQtType(T) |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
28 { |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
29 enum isQtType = isQObjectType!(T) || isObjectType!(T) || isValueType!(T) || is(T.__isQtType); |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
30 } |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
31 */ |
288 | 32 template isNativeType(T) // type that doesn't require conversion i.e. is the same in C++ and D |
33 { | |
302 | 34 enum isNativeType = isNumeric!T || is(T == bool) || is(T == struct); |
35 } | |
36 | |
37 template isStringType(T) // string type | |
38 { | |
39 enum isStringType = is(T == string); | |
288 | 40 } |
41 | |
309 | 42 template isQList(T) |
43 { | |
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
|
44 enum isQList = ctfeStartsWith(Unqual!(T).stringof, "QList!"); |
309 | 45 } |
46 | |
339
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
47 // returns full name of enum: |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
48 // for Qt enum it is in the form of QPaintDevice::PaintDeviceMetric |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
49 // for pure D enums it is Foo.Bar |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
50 template enumFullName(T) |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
51 { |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
52 static if(!isModule(__traits(parent, T).stringof)) |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
53 { |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
54 static if(isQtType!(__traits(parent, T))) |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
55 enum enumFullName = qualifiedCppName!T; |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
56 else |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
57 enum enumFullName = qualifiedDName!T; |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
58 } |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
59 else |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
60 enum enumFullName = qualifiedDName!T; |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
61 |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
62 } |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
63 |
288 | 64 // converts an argumnent from C++ to D in qt_metacall |
65 string metaCallArgument(T)(string ptr) | |
66 { | |
303 | 67 static if (isQObjectType!T || isObjectType!T) |
288 | 68 return T.stringof ~ ".__getObject(*cast(void**)(" ~ ptr ~ "))"; |
318 | 69 else static if (isValueType!T) |
70 return "new " ~ T.stringof ~ "(" ~ T.stringof ~ ".__constructNativeCopy(" ~ ptr ~ "))"; | |
288 | 71 else static if (isNativeType!T) |
72 return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")"; | |
302 | 73 else static if (isStringType!T) |
74 return "QStringUtil.toNativeString(" ~ ptr ~ ")"; | |
339
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
75 else static if (is(T == enum)) |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
76 return "*(cast(" ~ qualifiedDName!T ~ "*)" ~ ptr ~ ")"; |
288 | 77 else |
78 return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")"; | |
79 //res = T.stringof; | |
80 } | |
81 | |
82 // converts a D argument type to C++ for registering in Qt meta system | |
83 string qtDeclArg(T)() | |
84 { | |
303 | 85 static if (isQObjectType!T || isObjectType!T) |
288 | 86 return T.stringof ~ "*"; |
318 | 87 else static if (isValueType!T) |
88 return T.stringof; | |
302 | 89 else static if (isStringType!T) |
90 return "QString"; | |
309 | 91 else static if (isQList!T) |
318 | 92 { |
93 alias templateParam!T ElementType; | |
94 static if (is(ElementType == string)) | |
95 return "QStringList"; | |
96 else | |
97 return "QList<" ~ qtDeclArg!(templateParam!T)() ~ ">"; | |
98 } | |
339
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
99 else static if (is(T == enum)) |
4e31cbd9e20c
fix enumeration problems. requires patched dmd
Eldar Insafutdinov
parents:
323
diff
changeset
|
100 return enumFullName!T; |
288 | 101 else static if (isNativeType!T) |
302 | 102 return Unqual!T.stringof; |
288 | 103 else |
104 return T.stringof; | |
105 } | |
106 | |
107 // converts an argument from D to C++ in a signal emitter | |
108 string convertSignalArgument(T)(string arg) | |
109 { | |
303 | 110 static if (isQObjectType!T || isObjectType!T) |
323
7a3c43424dca
make all examples compile with new signals/slots
eldar_ins@eldar-laptop
parents:
319
diff
changeset
|
111 return arg ~ " ? " "&" ~ arg ~ ".__nativeId : cast(void**) &" ~ arg; // since it is a pointer type check arg for null |
318 | 112 else static if (isValueType!T) |
288 | 113 return arg ~ ".__nativeId"; |
302 | 114 else static if (isStringType!T) |
318 | 115 return "&_qt" ~ arg; |
288 | 116 else static if (isNativeType!T) |
318 | 117 return "&" ~ arg; |
288 | 118 else |
318 | 119 return "&" ~ arg; |
288 | 120 } |
302 | 121 |
122 string prepareSignalArguments(Args...)() | |
123 { | |
124 string res; | |
125 foreach(i, _; Args) | |
126 static if (isStringType!(Args[i])) | |
127 res ~= "auto _qt_t" ~ __toString(i) ~ " = QString(_t" ~ __toString(i) ~ ");\n"; | |
128 return res; | |
129 } |