Mercurial > projects > qtd
comparison d2/qt/core/QTypeInfo.d @ 344:96a75b1e5b26
project structure changes
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Fri, 14 May 2010 12:14:37 +0300 |
parents | qt/core/QTypeInfo.d@adae77fdc1ea |
children | 970332a88b72 |
comparison
equal
deleted
inserted
replaced
343:552647ec0f82 | 344:96a75b1e5b26 |
---|---|
1 module qt.core.QTypeInfo; | |
2 | |
3 //import qt.QGlobal; | |
4 //import qtd.Atomic; | |
5 | |
6 /* | |
7 The catch-all template. | |
8 */ | |
9 import std.traits; | |
10 | |
11 import qtd.MetaMarshall; | |
12 import qt.core.QString; | |
13 | |
14 bool qIsDetached(T)(ref T) { return true; } | |
15 | |
16 template isBasicType(T) | |
17 { | |
18 enum isBasicType = isNumeric!T || is(T == bool) || is(T == enum); | |
19 } | |
20 | |
21 template QTypeInfo(T) | |
22 { | |
23 static if(is(T == string)) | |
24 { | |
25 alias QString.QTypeInfo QTypeInfo; | |
26 } | |
27 else static if(isBasicType!T) | |
28 { | |
29 public enum | |
30 { | |
31 isPointer = false, | |
32 isComplex = false, | |
33 isStatic = false, | |
34 isLarge = (T.sizeof > (void*).sizeof), | |
35 isDummy = false | |
36 } | |
37 } | |
38 else static if(is(T.QTypeInfo)) | |
39 { | |
40 alias T.QTypeInfo QTypeInfo; // alias member QTypeInfo | |
41 } | |
42 else static if ( isQObjectType!T || isObjectType!T ) | |
43 { | |
44 public enum // are pointers | |
45 { | |
46 isPointer = true, | |
47 isComplex = false, | |
48 isStatic = false, | |
49 isLarge = false, | |
50 isDummy = false | |
51 } | |
52 } | |
53 else // default parameters | |
54 { | |
55 public enum | |
56 { | |
57 isPointer = isPointer!T, | |
58 isComplex = !isPointer, | |
59 isStatic = !isPointer, | |
60 isLarge = (T.sizeof > (void*).sizeof), | |
61 isDummy = false | |
62 } | |
63 } | |
64 } | |
65 | |
66 | |
67 /* | |
68 Specialize a specific type with: | |
69 | |
70 Q_DECLARE_TYPEINFO(type, flags); | |
71 | |
72 where 'type' is the name of the type to specialize and 'flags' is | |
73 logically-OR'ed combination of the flags below. | |
74 */ | |
75 | |
76 /* presents in QGlobal | |
77 enum { /* TYPEINFO flags | |
78 Q_COMPLEX_TYPE = 0, | |
79 Q_PRIMITIVE_TYPE = 0x1, | |
80 Q_STATIC_TYPE = 0, | |
81 Q_MOVABLE_TYPE = 0x2, | |
82 Q_DUMMY_TYPE = 0x4 | |
83 } | |
84 */ | |
85 | |
86 /* | |
87 template QTypeInfo(alias FLAGS) | |
88 { | |
89 template QTypeInfo(TYPE) | |
90 { | |
91 public: | |
92 enum { | |
93 isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0), | |
94 isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), | |
95 isLarge = (TYPE.sizeof > (void*).sizeof), | |
96 isPointer = false, | |
97 isDummy = (((FLAGS) & Q_DUMMY_TYPE) != 0) | |
98 } | |
99 } | |
100 } | |
101 */ | |
102 /* | |
103 Specialize a shared type with: | |
104 | |
105 Q_DECLARE_SHARED(type); | |
106 | |
107 where 'type' is the name of the type to specialize. NOTE: shared | |
108 types must declare a 'bool isDetached(void) const;' member for this | |
109 to work. | |
110 */ | |
111 /* | |
112 #if defined Q_CC_MSVC && _MSC_VER < 1300 | |
113 template <typename T> | |
114 inline void qSwap_helper(T &value1, T &value2, T*) | |
115 { | |
116 T t = value1; | |
117 value1 = value2; | |
118 value2 = t; | |
119 } | |
120 #define Q_DECLARE_SHARED(TYPE) \ | |
121 template <> inline bool qIsDetached<TYPE>(TYPE &t) { return t.isDetached(); } \ | |
122 template <> inline void qSwap_helper<TYPE>(TYPE &value1, TYPE &value2, TYPE*) \ | |
123 { \ | |
124 const TYPE::DataPtr t = value1.data_ptr(); \ | |
125 value1.data_ptr() = value2.data_ptr(); \ | |
126 value2.data_ptr() = t; \ | |
127 } | |
128 #else | |
129 #define Q_DECLARE_SHARED(TYPE) \ | |
130 template <> inline bool qIsDetached<TYPE>(TYPE &t) { return t.isDetached(); } \ | |
131 template <typename T> inline void qSwap(T &, T &); \ | |
132 template <> inline void qSwap<TYPE>(TYPE &value1, TYPE &value2) \ | |
133 { \ | |
134 const TYPE::DataPtr t = value1.data_ptr(); \ | |
135 value1.data_ptr() = value2.data_ptr(); \ | |
136 value2.data_ptr() = t; \ | |
137 } | |
138 #endif | |
139 */ |