comparison qt/core/QTypeInfo.d @ 292:19498f420252 signals

more QList goodness
author eldar
date Tue, 10 Nov 2009 19:29:42 +0000
parents 0d2094800bdb
children bb37b0ed94c9
comparison
equal deleted inserted replaced
291:0d2094800bdb 292:19498f420252
4 //import qt.qtd.Atomic; 4 //import qt.qtd.Atomic;
5 5
6 /* 6 /*
7 The catch-all template. 7 The catch-all template.
8 */ 8 */
9 import std.traits;
10
11 import qt.qtd.MetaMarshall;
9 12
10 bool qIsDetached(T)(ref T) { return true; } 13 bool qIsDetached(T)(ref T) { return true; }
11 14
12 struct QTypeInfo(T) 15 template QTypeInfo(T)
16 if ( !(isQObjectType!T || isObjectType!T) )
13 { 17 {
14 public: 18 public:
15 enum { 19 enum {
16 isPointer = false, 20 isPointer = isPointer!T,
17 isComplex = true, 21 isComplex = !isPointer,
18 isStatic = true, 22 isStatic = !isPointer,
19 isLarge = (T.sizeof > sizeof(void*)), 23 isLarge = (T.sizeof > (void*).sizeof),
20 isDummy = false 24 isDummy = false
21 } 25 }
22 } 26 }
23 27
24 struct QTypeInfo(T : T*) 28 template QTypeInfo(T)
29 if ( isQObjectType!T || isObjectType!T )
25 { 30 {
26 public: 31 public:
27 enum { 32 enum {
28 isPointer = true, 33 isPointer = true,
29 isComplex = false, 34 isComplex = false,
31 isLarge = false, 36 isLarge = false,
32 isDummy = false 37 isDummy = false
33 } 38 }
34 } 39 }
35 40
36 #else
37
38 template <typename T> char QTypeInfoHelper(T*(*)());
39 void* QTypeInfoHelper(...);
40
41 template <typename T> inline bool qIsDetached(T &) { return true; }
42
43 template <typename T>
44 class QTypeInfo
45 {
46 public:
47 enum {
48 isPointer = (1 == sizeof(QTypeInfoHelper((T(*)())0))),
49 isComplex = !isPointer,
50 isStatic = !isPointer,
51 isLarge = (sizeof(T)>sizeof(void*)),
52 isDummy = false
53 };
54 };
55
56 #endif /* QT_NO_PARTIAL_TEMPLATE_SPECIALIZATION */
57 41
58 /* 42 /*
59 Specialize a specific type with: 43 Specialize a specific type with:
60 44
61 Q_DECLARE_TYPEINFO(type, flags); 45 Q_DECLARE_TYPEINFO(type, flags);
62 46
63 where 'type' is the name of the type to specialize and 'flags' is 47 where 'type' is the name of the type to specialize and 'flags' is
64 logically-OR'ed combination of the flags below. 48 logically-OR'ed combination of the flags below.
65 */ 49 */
66 enum { /* TYPEINFO flags */ 50
51 /* presents in QGlobal
52 enum { /* TYPEINFO flags
67 Q_COMPLEX_TYPE = 0, 53 Q_COMPLEX_TYPE = 0,
68 Q_PRIMITIVE_TYPE = 0x1, 54 Q_PRIMITIVE_TYPE = 0x1,
69 Q_STATIC_TYPE = 0, 55 Q_STATIC_TYPE = 0,
70 Q_MOVABLE_TYPE = 0x2, 56 Q_MOVABLE_TYPE = 0x2,
71 Q_DUMMY_TYPE = 0x4 57 Q_DUMMY_TYPE = 0x4
72 }; 58 }
59 */
73 60
74 #define Q_DECLARE_TYPEINFO(TYPE, FLAGS) \ 61 /*
75 template <> \ 62 template QTypeInfo(alias FLAGS)
76 class QTypeInfo<TYPE> \ 63 {
77 { \ 64 template QTypeInfo(TYPE)
78 public: \ 65 {
79 enum { \ 66 public:
80 isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0), \ 67 enum {
81 isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), \ 68 isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0),
82 isLarge = (sizeof(TYPE)>sizeof(void*)), \ 69 isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0),
83 isPointer = false, \ 70 isLarge = (TYPE.sizeof > (void*).sizeof),
84 isDummy = (((FLAGS) & Q_DUMMY_TYPE) != 0) \ 71 isPointer = false,
85 }; \ 72 isDummy = (((FLAGS) & Q_DUMMY_TYPE) != 0)
86 static inline const char *name() { return #TYPE; } \ 73 }
74 }
87 } 75 }
88 76 */
89 /* 77 /*
90 Specialize a shared type with: 78 Specialize a shared type with:
91 79
92 Q_DECLARE_SHARED(type); 80 Q_DECLARE_SHARED(type);
93 81
94 where 'type' is the name of the type to specialize. NOTE: shared 82 where 'type' is the name of the type to specialize. NOTE: shared
95 types must declare a 'bool isDetached(void) const;' member for this 83 types must declare a 'bool isDetached(void) const;' member for this
96 to work. 84 to work.
97 */ 85 */
86 /*
98 #if defined Q_CC_MSVC && _MSC_VER < 1300 87 #if defined Q_CC_MSVC && _MSC_VER < 1300
99 template <typename T> 88 template <typename T>
100 inline void qSwap_helper(T &value1, T &value2, T*) 89 inline void qSwap_helper(T &value1, T &value2, T*)
101 { 90 {
102 T t = value1; 91 T t = value1;
120 const TYPE::DataPtr t = value1.data_ptr(); \ 109 const TYPE::DataPtr t = value1.data_ptr(); \
121 value1.data_ptr() = value2.data_ptr(); \ 110 value1.data_ptr() = value2.data_ptr(); \
122 value2.data_ptr() = t; \ 111 value2.data_ptr() = t; \
123 } 112 }
124 #endif 113 #endif
114 */