comparison qt/qtd/MetaMarshall.d @ 339:4e31cbd9e20c

fix enumeration problems. requires patched dmd
author Eldar Insafutdinov
date Sun, 09 May 2010 00:52:49 +0100
parents 7a3c43424dca
children
comparison
equal deleted inserted replaced
338:e65f08f6262b 339:4e31cbd9e20c
17 template isValueType(T) // is a Qt Value type that belongs to the library 17 template isValueType(T) // is a Qt Value type that belongs to the library
18 { 18 {
19 enum isValueType = is(T.__isValueType); 19 enum isValueType = is(T.__isValueType);
20 } 20 }
21 21
22 template isQtType(T)
23 {
24 mixin ("enum isQtType = is(T.__isQtType_" ~ T.stringof ~ ");");
25 }
26 /*
27 template isQtType(T)
28 {
29 enum isQtType = isQObjectType!(T) || isObjectType!(T) || isValueType!(T) || is(T.__isQtType);
30 }
31 */
22 template isNativeType(T) // type that doesn't require conversion i.e. is the same in C++ and D 32 template isNativeType(T) // type that doesn't require conversion i.e. is the same in C++ and D
23 { 33 {
24 enum isNativeType = isNumeric!T || is(T == bool) || is(T == struct); 34 enum isNativeType = isNumeric!T || is(T == bool) || is(T == struct);
25 } 35 }
26 36
32 template isQList(T) 42 template isQList(T)
33 { 43 {
34 enum isQList = ctfeStartsWith(Unqual!(T).stringof, "QList!"); 44 enum isQList = ctfeStartsWith(Unqual!(T).stringof, "QList!");
35 } 45 }
36 46
47 // returns full name of enum:
48 // for Qt enum it is in the form of QPaintDevice::PaintDeviceMetric
49 // for pure D enums it is Foo.Bar
50 template enumFullName(T)
51 {
52 static if(!isModule(__traits(parent, T).stringof))
53 {
54 static if(isQtType!(__traits(parent, T)))
55 enum enumFullName = qualifiedCppName!T;
56 else
57 enum enumFullName = qualifiedDName!T;
58 }
59 else
60 enum enumFullName = qualifiedDName!T;
61
62 }
63
37 // converts an argumnent from C++ to D in qt_metacall 64 // converts an argumnent from C++ to D in qt_metacall
38 string metaCallArgument(T)(string ptr) 65 string metaCallArgument(T)(string ptr)
39 { 66 {
40 static if (isQObjectType!T || isObjectType!T) 67 static if (isQObjectType!T || isObjectType!T)
41 return T.stringof ~ ".__getObject(*cast(void**)(" ~ ptr ~ "))"; 68 return T.stringof ~ ".__getObject(*cast(void**)(" ~ ptr ~ "))";
43 return "new " ~ T.stringof ~ "(" ~ T.stringof ~ ".__constructNativeCopy(" ~ ptr ~ "))"; 70 return "new " ~ T.stringof ~ "(" ~ T.stringof ~ ".__constructNativeCopy(" ~ ptr ~ "))";
44 else static if (isNativeType!T) 71 else static if (isNativeType!T)
45 return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")"; 72 return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")";
46 else static if (isStringType!T) 73 else static if (isStringType!T)
47 return "QStringUtil.toNativeString(" ~ ptr ~ ")"; 74 return "QStringUtil.toNativeString(" ~ ptr ~ ")";
75 else static if (is(T == enum))
76 return "*(cast(" ~ qualifiedDName!T ~ "*)" ~ ptr ~ ")";
48 else 77 else
49 return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")"; 78 return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")";
50 //res = T.stringof; 79 //res = T.stringof;
51 } 80 }
52 81
65 static if (is(ElementType == string)) 94 static if (is(ElementType == string))
66 return "QStringList"; 95 return "QStringList";
67 else 96 else
68 return "QList<" ~ qtDeclArg!(templateParam!T)() ~ ">"; 97 return "QList<" ~ qtDeclArg!(templateParam!T)() ~ ">";
69 } 98 }
99 else static if (is(T == enum))
100 return enumFullName!T;
70 else static if (isNativeType!T) 101 else static if (isNativeType!T)
71 return Unqual!T.stringof; 102 return Unqual!T.stringof;
72 else 103 else
73 return T.stringof; 104 return T.stringof;
74 } 105 }