annotate d2/qt/core/QMetaType.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 96a75b1e5b26
children a032df77b6ab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
87
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
1 module qt.core.QMetaType;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
2 public import qt.core.Qt;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
3 private import qt.core.QDataStream;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
4
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
5 alias extern(C) void *function(void *copy) Ctor;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
6 alias extern(C) void function(void *obj) Dtor;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
7 alias extern(C) void function(void *stream, void * object) StreamOp;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
8
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
9 struct DArrayToC
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
10 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
11 void[] array;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
12 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
13
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
14 public template MetaTypeOps(T)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
15 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
16 // TODO:
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
17 // static assert(typeof(new T), "Type " ~ T.stringof ~ " has no default constructor");
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
18 // static assert(typeof(new T(T.init))), "Type " ~ T.stringof ~ " has no default copy constructor");
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
19
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
20 extern(C) void* ctor(void* copy)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
21 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
22 static if (is(T == class) || is(T == interface))
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
23 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
24 return cast(void*)(copy ? new T(cast(T)copy) : new T);
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
25 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
26 else static if (isDynamicArrayType!(T) || isStaticArrayType!(T) )
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
27 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
28 auto darray = new DArrayToC;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
29 if(copy)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
30 darray.array = (cast(DArrayToC*)copy).array.dup;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
31 return cast(void*)darray;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
32 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
33 else
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
34 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
35 auto data = new T;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
36 if(copy)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
37 *data = *cast(T*)copy;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
38 return cast(void*)data;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
39 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
40 }
357
9784459f0750 An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents: 344
diff changeset
41
87
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
42
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
43 extern(C) void dtor(void* obj)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
44 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
45 static if (is(T == class) || is(T == interface))
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
46 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
47 auto tmp = cast(T)obj;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
48 delete tmp;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
49 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
50 else
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
51 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
52 auto tmp = cast(T*)obj;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
53 delete tmp;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
54 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
55 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
56 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
57
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
58 public int qRegisterMetaType(T)(string name = null)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
59 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
60 if (!name.length)
357
9784459f0750 An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents: 344
diff changeset
61 name = typeid(T).toString;
87
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
62
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
63 return qtd_registerType(toStringz(name), &MetaTypeOps!(T).ctor, &MetaTypeOps!(T).dtor);
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
64 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
65
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
66 /* Not work....
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
67 private class DataStreamPriv: QDataStream
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
68 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
69 this(void * cobj)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
70 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
71 super(cobj);
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
72 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
73 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
74 */
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
75 /*
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
76 public void qRegisterMetaTypeStreamOperators(T)(void function(ref QDataStream, T ) saveOp, void function (ref QDataStream, ref T) loadOp, string name = null)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
77 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
78 static void function(ref QDataStream, T ) SaveOp;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
79 static void function (ref QDataStream, ref T) LoadOp;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
80 SaveOp = saveOp;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
81 LoadOp = loadOp;
357
9784459f0750 An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents: 344
diff changeset
82
87
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
83 if (!name.length)
357
9784459f0750 An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents: 344
diff changeset
84 name = typeid(T).toString;
9784459f0750 An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents: 344
diff changeset
85
87
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
86 extern(C) void saveOpC(void *stream, void *object)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
87 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
88 QDataStream dstream = new DataStreamPriv(stream);
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
89 Stdout(object).newline;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
90 static if (is(T == class) || is(T == interface))
357
9784459f0750 An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents: 344
diff changeset
91 SaveOp(dstream, cast(T)object);
9784459f0750 An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents: 344
diff changeset
92 else
87
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
93 SaveOp(dstream, *cast(T*)object);
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
94 }
357
9784459f0750 An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents: 344
diff changeset
95
87
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
96 extern(C) void loadOpC(void *stream, void *object)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
97 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
98 //return stream;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
99 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
100
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
101 qtd_registerStreamOperators(toStringz(name), cast(StreamOp)&saveOpC, cast(StreamOp)&loadOpC);
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
102 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
103 */
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
104 private extern(C) void qtd_registerStreamOperators(char *typeName, StreamOp saveOp, StreamOp loadOp);
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
105 private extern(C) int qtd_registerType(in char* namePtr, Ctor ctor, Dtor dtor);
188
7dd099050621 initial commit for D2 support
eldar
parents: 87
diff changeset
106 extern(C) int qtd_MetatypeId(in char *id); // TODO: wrap to D.