comparison qt/qtd/MetaMarshall.d @ 308:2485419c5c63 signals

merge with 299
author eldar_ins@eldar-laptop
date Wed, 23 Dec 2009 04:45:55 +0500
parents 91ed8edd442e
children 8a0cf14e3419
comparison
equal deleted inserted replaced
307:91ed8edd442e 308:2485419c5c63
1 module qt.qtd.MetaMarshall; 1 module qt.qtd.MetaMarshall;
2 2
3 import std.traits; 3 import std.traits;
4 4
5 // utilities
6 // shouldn't be here 5 // shouldn't be here
7
8 public bool startsWith(T)(T[] source, T[] pattern)
9 {
10 return source.length >= pattern.length && source[0 .. pattern.length] == pattern[];
11 }
12 6
13 string __toString(long v) 7 string __toString(long v)
14 { 8 {
15 if (v == 0) 9 if (v == 0)
16 return "0"; 10 return "0";
34 ret = "-" ~ ret; 28 ret = "-" ~ ret;
35 29
36 return ret; 30 return ret;
37 } 31 }
38 32
39 template templateParam(U : V!(U), alias V)
40 {
41 alias U templateParam;
42 }
43
44
45 /*
46 * actual stuff
47 */
48
49 template isQObjectType(T) // is a QObject type that belongs to the library 33 template isQObjectType(T) // is a QObject type that belongs to the library
50 { 34 {
51 enum isQObjectType = is(T.__isQObjectType); 35 enum isQObjectType = is(T.__isQObjectType);
52 } 36 }
53 37
69 template isStringType(T) // string type 53 template isStringType(T) // string type
70 { 54 {
71 enum isStringType = is(T == string); 55 enum isStringType = is(T == string);
72 } 56 }
73 57
74 template isQList(T)
75 {
76 enum isQList = startsWith(Unqual!(T).stringof, "QList!");
77 }
78
79 // converts an argumnent from C++ to D in qt_metacall 58 // converts an argumnent from C++ to D in qt_metacall
80 string metaCallArgument(T)(string ptr) 59 string metaCallArgument(T)(string ptr)
81 { 60 {
82 static if (isQObjectType!T || isObjectType!T) 61 static if (isQObjectType!T || isObjectType!T)
83 return T.stringof ~ ".__getObject(*cast(void**)(" ~ ptr ~ "))"; 62 return T.stringof ~ ".__getObject(*cast(void**)(" ~ ptr ~ "))";
95 { 74 {
96 static if (isQObjectType!T || isObjectType!T) 75 static if (isQObjectType!T || isObjectType!T)
97 return T.stringof ~ "*"; 76 return T.stringof ~ "*";
98 else static if (isStringType!T) 77 else static if (isStringType!T)
99 return "QString"; 78 return "QString";
100 else static if (isQList!T)
101 return "QList<" ~ qtDeclArg!(templateParam!T)() ~ ">";
102 else static if (isNativeType!T) 79 else static if (isNativeType!T)
103 return Unqual!T.stringof; 80 return Unqual!T.stringof;
104 else 81 else
105 return T.stringof; 82 return T.stringof;
106 } 83 }