1
|
1 /****************************************************************************
|
|
2 **
|
|
3 ** Copyright (C) 1992-2008 Nokia. All rights reserved.
|
|
4 ** Copyright (C) 2006 Roberto Raggi <roberto@kdevelop.org>
|
|
5 **
|
|
6 ** This file is part of Qt Jambi.
|
|
7 **
|
|
8 ** * Commercial Usage
|
|
9 * Licensees holding valid Qt Commercial licenses may use this file in
|
|
10 * accordance with the Qt Commercial License Agreement provided with the
|
|
11 * Software or, alternatively, in accordance with the terms contained in
|
|
12 * a written agreement between you and Nokia.
|
|
13 *
|
|
14 *
|
|
15 * GNU General Public License Usage
|
|
16 * Alternatively, this file may be used under the terms of the GNU
|
|
17 * General Public License versions 2.0 or 3.0 as published by the Free
|
|
18 * Software Foundation and appearing in the file LICENSE.GPL included in
|
|
19 * the packaging of this file. Please review the following information
|
|
20 * to ensure GNU General Public Licensing requirements will be met:
|
|
21 * http://www.fsf.org/licensing/licenses/info/GPLv2.html and
|
|
22 * http://www.gnu.org/copyleft/gpl.html. In addition, as a special
|
|
23 * exception, Nokia gives you certain additional rights. These rights
|
|
24 * are described in the Nokia Qt GPL Exception version 1.2, included in
|
|
25 * the file GPL_EXCEPTION.txt in this package.
|
|
26 *
|
|
27 * Qt for Windows(R) Licensees
|
|
28 * As a special exception, Nokia, as the sole copyright holder for Qt
|
|
29 * Designer, grants users of the Qt/Eclipse Integration plug-in the
|
|
30 * right for the Qt/Eclipse Integration to link to functionality
|
|
31 * provided by Qt Designer and its related libraries.
|
|
32 *
|
|
33 *
|
|
34 * If you are unsure which license is appropriate for your use, please
|
|
35 * contact the sales department at qt-sales@nokia.com.
|
|
36
|
|
37 **
|
|
38 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|
39 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
40 **
|
|
41 ****************************************************************************/
|
|
42
|
|
43 #ifndef CODEMODEL_POINTER_H
|
|
44 #define CODEMODEL_POINTER_H
|
|
45
|
|
46 #include <QtCore/QSharedData>
|
|
47
|
|
48 // Since the atomic API changed in 4.4 we need to hack a little here
|
|
49 // to make it work with both 4.3 and 4.4 until that is not required
|
|
50
|
|
51 #if QT_VERSION >= 0x040400
|
|
52
|
|
53 # include <QtCore/qatomic.h>
|
|
54 template <class T> class CodeModelPointer: public QAtomicPointer<T>
|
|
55
|
|
56 #else
|
|
57
|
|
58 template <class T> class CodeModelPointer
|
|
59
|
|
60 #endif // QT_VERSION >= 0x040400
|
|
61
|
|
62 {
|
|
63 public:
|
|
64 typedef T Type;
|
|
65
|
|
66 #if QT_VERSION < 0x040400
|
|
67 inline T &operator*() { return *d; }
|
|
68 inline const T &operator*() const { return *d; }
|
|
69 inline T *operator->() { return d; }
|
|
70 inline const T *operator->() const { return d; }
|
|
71 inline operator T *() { return d; }
|
|
72 inline operator const T *() const { return d; }
|
|
73 inline T *data() { return d; }
|
|
74 inline const T *data() const { return d; }
|
|
75 inline const T *constData() const { return d; }
|
|
76
|
|
77 inline bool operator==(const CodeModelPointer<T> &other) const { return d == other.d; }
|
|
78 inline bool operator!=(const CodeModelPointer<T> &other) const { return d != other.d; }
|
|
79 inline bool operator==(const T *ptr) const { return d == ptr; }
|
|
80 inline bool operator!=(const T *ptr) const { return d != ptr; }
|
|
81
|
|
82 inline CodeModelPointer() { d = 0; }
|
|
83 inline ~CodeModelPointer() { if (d && !d->ref.deref()) delete d; }
|
|
84
|
|
85 explicit CodeModelPointer(T *data);
|
|
86 inline CodeModelPointer(const CodeModelPointer<T> &o) : d(o.d) { if (d) d->ref.ref(); }
|
|
87 inline CodeModelPointer<T> & operator=(const CodeModelPointer<T> &o) {
|
|
88 if (o.d != d) {
|
|
89 T *x = o.d;
|
|
90 if (x) x->ref.ref();
|
|
91 x = qAtomicSetPtr(&d, x);
|
|
92 if (x && !x->ref.deref())
|
|
93 delete x;
|
|
94 }
|
|
95 return *this;
|
|
96 }
|
|
97 inline CodeModelPointer &operator=(T *o) {
|
|
98 if (o != d) {
|
|
99 T *x = o;
|
|
100 if (x) x->ref.ref();
|
|
101 x = qAtomicSetPtr(&d, x);
|
|
102 if (x && !x->ref.deref())
|
|
103 delete x;
|
|
104 }
|
|
105 return *this;
|
|
106 }
|
|
107
|
|
108 inline bool operator!() const { return !d; }
|
|
109
|
|
110 private:
|
|
111 T *d;
|
|
112 #else // QT_VERSION < 0x040400
|
|
113 inline CodeModelPointer(T *value = 0) : QAtomicPointer<T>(value) {}
|
|
114
|
|
115 inline CodeModelPointer &operator=(T *o) {
|
|
116 QAtomicPointer<T>::operator=(o);
|
|
117 return *this;
|
|
118 }
|
|
119
|
|
120 inline T *data() { return (T *) *this; }
|
|
121 inline const T *data() const { return (const T *) *this; }
|
|
122 inline const T *constData() const { return (const T *) *this; }
|
|
123 #endif
|
|
124 };
|
|
125
|
|
126 #if QT_VERSION < 0x040400
|
|
127 template <class T>
|
|
128 Q_INLINE_TEMPLATE CodeModelPointer<T>::CodeModelPointer(T *adata) : d(adata)
|
|
129 { if (d) d->ref.ref(); }
|
|
130 #endif
|
|
131
|
|
132 #endif // CODEMODEL_POINTER_H
|