Mercurial > projects > qtd
comparison d2/qtd/Marshal.d @ 357:9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Q_CLASSINFO implementation
Now Qtd can be built on Windows
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Wed, 02 Jun 2010 19:38:05 +0300 |
parents | 31520b2c0b3c |
children | da4235301224 |
comparison
equal
deleted
inserted
replaced
356:12cec2d14e1c | 357:9784459f0750 |
---|---|
6 qtd.ctfe.Format; | 6 qtd.ctfe.Format; |
7 | 7 |
8 import std.string : startsWith; | 8 import std.string : startsWith; |
9 | 9 |
10 | 10 |
11 template isQObjectType(T) | 11 template isQObjectType(T) // |
12 { | 12 { |
13 enum isQObjectType = is(T.__isQObjectType); | 13 enum isQObjectType = is(T.__isQObjectType); |
14 } | 14 } |
15 | 15 |
16 template isObjectType(T) | 16 template isObjectType(T) |
31 template isQtType(T) | 31 template isQtType(T) |
32 { | 32 { |
33 enum isQtType = isQObjectType!(T) || isObjectType!(T) || isValueType!(T) || is(T.__isQtType); | 33 enum isQtType = isQObjectType!(T) || isObjectType!(T) || isValueType!(T) || is(T.__isQtType); |
34 } | 34 } |
35 */ | 35 */ |
36 template isNativeType(T) // type that doesn't require conversion i.e. is the same in C++ and D | 36 template isNativeType(T) |
37 { | 37 { |
38 enum isNativeType = isNumeric!T || is(T == bool) || is(T == struct); | 38 enum isNativeType = isNumeric!T || is(T == bool) || is(T == struct); |
39 } | 39 } |
40 | 40 |
41 template isStringType(T) // string type | 41 template isStringType(T) // string type |
43 enum isStringType = is(T == string); | 43 enum isStringType = is(T == string); |
44 } | 44 } |
45 | 45 |
46 template isQList(T) | 46 template isQList(T) |
47 { | 47 { |
48 enum isQList = startsWith(Unqual!(T).stringof, "QList!"); | 48 enum isQList = startsWith(Unqual!(T).stringof, "QList!"); //hack |
49 } | 49 } |
50 | 50 |
51 // returns full name of enum: | 51 // returns full name of enum: |
52 // for Qt enum it is in the form of QPaintDevice::PaintDeviceMetric | 52 // for Qt enum it is in the form of QPaintDevice::PaintDeviceMetric |
53 // for pure D enums it is Foo.Bar | 53 // for pure D enums it is Foo.Bar |
62 } | 62 } |
63 else | 63 else |
64 enum enumFullName = qualifiedDName!T; | 64 enum enumFullName = qualifiedDName!T; |
65 } | 65 } |
66 | 66 |
67 | |
68 // converts a D argument type to C++ for registering in Qt meta system | 67 // converts a D argument type to C++ for registering in Qt meta system |
69 string qtDeclArg(T)() | 68 string qtDeclArg(T)() |
70 { | 69 { |
71 static if (isQObjectType!T || isObjectType!T) | 70 static if (isQObjectType!T || isObjectType!T) |
72 return T.stringof ~ "*"; | 71 return T.stringof ~ "*"; |
74 return T.stringof; | 73 return T.stringof; |
75 else static if (isStringType!T) | 74 else static if (isStringType!T) |
76 return "QString"; | 75 return "QString"; |
77 else static if (isQList!T) | 76 else static if (isQList!T) |
78 { | 77 { |
79 alias templateParam!T ElementType; | 78 static if (is(T.ElementType == string)) |
80 static if (is(ElementType == string)) | |
81 return "QStringList"; | 79 return "QStringList"; |
82 else | 80 else |
83 return "QList<" ~ qtDeclArg!(templateParam!T)() ~ ">"; | 81 return "QList<" ~ qtDeclArg!(T.ElementType)() ~ ">"; |
84 } | 82 } |
85 else static if (is(T == enum)) | 83 else static if (is(T == enum)) |
86 return enumFullName!T; | 84 return enumFullName!T; |
87 else static if (isNativeType!T) | 85 else static if (isNativeType!T) |
88 return Unqual!T.stringof; | 86 return Unqual!T.stringof; |
101 static if (isQObjectType!(Args[${0}]) || isObjectType!(Args[${0}])) | 99 static if (isQObjectType!(Args[${0}]) || isObjectType!(Args[${0}])) |
102 auto _out${0} = Args[${0}].__getObject(*cast(void**)_a[${0}]); | 100 auto _out${0} = Args[${0}].__getObject(*cast(void**)_a[${0}]); |
103 else static if (isValueType!(Args[${0}])) | 101 else static if (isValueType!(Args[${0}])) |
104 { | 102 { |
105 // COMPILER BUG: 'new' chokes on Args[argIndex], hence the alias | 103 // COMPILER BUG: 'new' chokes on Args[argIndex], hence the alias |
106 alias Args[${0}] Args${0}; | 104 alias Args[${0}] Args${0}; |
107 auto _out${0} = new Args${0}(Args[${0}].__constructNativeCopy(_a[${0}])); | 105 auto _out${0} = new Args${0}(Args[${0}].__constructNativeCopy(_a[${0}])); |
108 } | 106 } |
109 else static if (isStringType!(Args[${0}])) | 107 else static if (isStringType!(Args[${0}])) |
110 auto _out${0} = QStringUtil.toNativeString(_a[${0}]); | 108 auto _out${0} = QStringUtil.toNativeString(_a[${0}]); |
111 else | 109 else |