291
|
1 module qt.core.QTypeInfo;
|
|
2
|
|
3 //import qt.QGlobal;
|
|
4 //import qt.qtd.Atomic;
|
|
5
|
|
6 /*
|
|
7 The catch-all template.
|
|
8 */
|
|
9
|
|
10 bool qIsDetached(T)(ref T) { return true; }
|
|
11
|
|
12 struct QTypeInfo(T)
|
|
13 {
|
|
14 public:
|
|
15 enum {
|
|
16 isPointer = false,
|
|
17 isComplex = true,
|
|
18 isStatic = true,
|
|
19 isLarge = (T.sizeof > sizeof(void*)),
|
|
20 isDummy = false
|
|
21 }
|
|
22 }
|
|
23
|
|
24 struct QTypeInfo(T : T*)
|
|
25 {
|
|
26 public:
|
|
27 enum {
|
|
28 isPointer = true,
|
|
29 isComplex = false,
|
|
30 isStatic = false,
|
|
31 isLarge = false,
|
|
32 isDummy = false
|
|
33 }
|
|
34 }
|
|
35
|
|
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
|
|
58 /*
|
|
59 Specialize a specific type with:
|
|
60
|
|
61 Q_DECLARE_TYPEINFO(type, flags);
|
|
62
|
|
63 where 'type' is the name of the type to specialize and 'flags' is
|
|
64 logically-OR'ed combination of the flags below.
|
|
65 */
|
|
66 enum { /* TYPEINFO flags */
|
|
67 Q_COMPLEX_TYPE = 0,
|
|
68 Q_PRIMITIVE_TYPE = 0x1,
|
|
69 Q_STATIC_TYPE = 0,
|
|
70 Q_MOVABLE_TYPE = 0x2,
|
|
71 Q_DUMMY_TYPE = 0x4
|
|
72 };
|
|
73
|
|
74 #define Q_DECLARE_TYPEINFO(TYPE, FLAGS) \
|
|
75 template <> \
|
|
76 class QTypeInfo<TYPE> \
|
|
77 { \
|
|
78 public: \
|
|
79 enum { \
|
|
80 isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0), \
|
|
81 isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), \
|
|
82 isLarge = (sizeof(TYPE)>sizeof(void*)), \
|
|
83 isPointer = false, \
|
|
84 isDummy = (((FLAGS) & Q_DUMMY_TYPE) != 0) \
|
|
85 }; \
|
|
86 static inline const char *name() { return #TYPE; } \
|
|
87 }
|
|
88
|
|
89 /*
|
|
90 Specialize a shared type with:
|
|
91
|
|
92 Q_DECLARE_SHARED(type);
|
|
93
|
|
94 where 'type' is the name of the type to specialize. NOTE: shared
|
|
95 types must declare a 'bool isDetached(void) const;' member for this
|
|
96 to work.
|
|
97 */
|
|
98 #if defined Q_CC_MSVC && _MSC_VER < 1300
|
|
99 template <typename T>
|
|
100 inline void qSwap_helper(T &value1, T &value2, T*)
|
|
101 {
|
|
102 T t = value1;
|
|
103 value1 = value2;
|
|
104 value2 = t;
|
|
105 }
|
|
106 #define Q_DECLARE_SHARED(TYPE) \
|
|
107 template <> inline bool qIsDetached<TYPE>(TYPE &t) { return t.isDetached(); } \
|
|
108 template <> inline void qSwap_helper<TYPE>(TYPE &value1, TYPE &value2, TYPE*) \
|
|
109 { \
|
|
110 const TYPE::DataPtr t = value1.data_ptr(); \
|
|
111 value1.data_ptr() = value2.data_ptr(); \
|
|
112 value2.data_ptr() = t; \
|
|
113 }
|
|
114 #else
|
|
115 #define Q_DECLARE_SHARED(TYPE) \
|
|
116 template <> inline bool qIsDetached<TYPE>(TYPE &t) { return t.isDetached(); } \
|
|
117 template <typename T> inline void qSwap(T &, T &); \
|
|
118 template <> inline void qSwap<TYPE>(TYPE &value1, TYPE &value2) \
|
|
119 { \
|
|
120 const TYPE::DataPtr t = value1.data_ptr(); \
|
|
121 value1.data_ptr() = value2.data_ptr(); \
|
|
122 value2.data_ptr() = t; \
|
|
123 }
|
|
124 #endif
|