annotate d1/qt/core/QMetaType.d @ 344:96a75b1e5b26

project structure changes
author Max Samukha <maxter@spambox.com>
date Fri, 14 May 2010 12:14:37 +0300
parents qt/core/QMetaType.d@7dd099050621
children
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 version (Tango)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
6 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
7 import tango.core.Array;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
8 import tango.stdc.stringz;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
9 import tango.core.Traits;
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
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
12 alias extern(C) void *function(void *copy) Ctor;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
13 alias extern(C) void function(void *obj) Dtor;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
14 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
15
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
16 struct DArrayToC
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
17 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
18 void[] array;
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
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
21 public template MetaTypeOps(T)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
22 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
23 // TODO:
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
24 // 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
25 // 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
26
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
27 extern(C) void* ctor(void* copy)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
28 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
29 static if (is(T == class) || is(T == interface))
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
30 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
31 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
32 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
33 else static if (isDynamicArrayType!(T) || isStaticArrayType!(T) )
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 darray = new DArrayToC;
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 darray.array = (cast(DArrayToC*)copy).array.dup;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
38 return cast(void*)darray;
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 else
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
41 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
42 auto data = new T;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
43 if(copy)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
44 *data = *cast(T*)copy;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
45 return cast(void*)data;
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 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
48
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 extern(C) void dtor(void* obj)
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 static if (is(T == class) || is(T == interface))
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
53 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
54 auto tmp = cast(T)obj;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
55 delete tmp;
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 else
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
58 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
59 auto tmp = cast(T*)obj;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
60 delete tmp;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
61 }
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 }
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 public int qRegisterMetaType(T)(string name = null)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
66 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
67 if (!name.length)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
68 name = typeid(T).toString;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
69
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
70 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
71 }
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 /* Not work....
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
74 private class DataStreamPriv: QDataStream
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 this(void * cobj)
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 super(cobj);
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
79 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
80 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
81 */
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
82 /*
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
83 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
84 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
85 static void function(ref QDataStream, T ) SaveOp;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
86 static void function (ref QDataStream, ref T) LoadOp;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
87 SaveOp = saveOp;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
88 LoadOp = loadOp;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
89
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
90 if (!name.length)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
91 name = typeid(T).toString;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
92
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
93 extern(C) void saveOpC(void *stream, void *object)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
94 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
95 QDataStream dstream = new DataStreamPriv(stream);
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
96 Stdout(object).newline;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
97 static if (is(T == class) || is(T == interface))
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
98 SaveOp(dstream, cast(T)object);
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
99 else
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
100 SaveOp(dstream, *cast(T*)object);
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
101 }
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 extern(C) void loadOpC(void *stream, void *object)
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
104 {
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
105 //return stream;
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
106 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
107
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
108 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
109 }
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
110 */
f46133029d8b qtd: Implement QMetaType. QVariant may save D types now.
SokoL_SD
parents:
diff changeset
111 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
112 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
113 extern(C) int qtd_MetatypeId(in char *id); // TODO: wrap to D.