bool* arguments can be used by wrappers
[lqt.git] / cpptoxml / parser / codemodel_pointer.h
blob2a7433f5d7c9d869ae220d6923d49af69789e127
1 /****************************************************************************
2 **
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 ** Copyright (C) 2006 Roberto Raggi <roberto@kdevelop.org>
5 **
6 ** This file is part of the Qt Script Generator project on Trolltech Labs.
7 **
8 ** This file may be used under the terms of the GNU General Public
9 ** License version 2.0 as published by the Free Software Foundation
10 ** and appearing in the file LICENSE.GPL included in the packaging of
11 ** this file. Please review the following information to ensure GNU
12 ** General Public Licensing requirements will be met:
13 ** http://www.trolltech.com/products/qt/opensource.html
15 ** If you are unsure which license is appropriate for your use, please
16 ** review the following information:
17 ** http://www.trolltech.com/products/qt/licensing.html or contact the
18 ** sales department at sales@trolltech.com.
20 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
21 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 ****************************************************************************/
25 #ifndef CODEMODEL_POINTER_H
26 #define CODEMODEL_POINTER_H
28 #include <QtCore/QSharedData>
30 // Since the atomic API changed in 4.4 we need to hack a little here
31 // to make it work with both 4.3 and 4.4 until that is not required
33 #if QT_VERSION >= 0x040400
35 # include <QtCore/qatomic.h>
36 template <class T> class CodeModelPointer: public QAtomicPointer<T>
38 #else
40 template <class T> class CodeModelPointer
42 #endif // QT_VERSION >= 0x040400
45 public:
46 typedef T Type;
48 #if QT_VERSION < 0x040400
49 inline T &operator*() { return *d; }
50 inline const T &operator*() const { return *d; }
51 inline T *operator->() { return d; }
52 inline const T *operator->() const { return d; }
53 inline operator T *() { return d; }
54 inline operator const T *() const { return d; }
55 inline T *data() { return d; }
56 inline const T *data() const { return d; }
57 inline const T *constData() const { return d; }
59 inline bool operator==(const CodeModelPointer<T> &other) const { return d == other.d; }
60 inline bool operator!=(const CodeModelPointer<T> &other) const { return d != other.d; }
61 inline bool operator==(const T *ptr) const { return d == ptr; }
62 inline bool operator!=(const T *ptr) const { return d != ptr; }
64 inline CodeModelPointer() { d = 0; }
65 inline ~CodeModelPointer() { if (d && !d->ref.deref()) delete d; }
67 explicit CodeModelPointer(T *data);
68 inline CodeModelPointer(const CodeModelPointer<T> &o) : d(o.d) { if (d) d->ref.ref(); }
69 inline CodeModelPointer<T> & operator=(const CodeModelPointer<T> &o) {
70 if (o.d != d) {
71 T *x = o.d;
72 if (x) x->ref.ref();
73 x = qAtomicSetPtr(&d, x);
74 if (x && !x->ref.deref())
75 delete x;
77 return *this;
79 inline CodeModelPointer &operator=(T *o) {
80 if (o != d) {
81 T *x = o;
82 if (x) x->ref.ref();
83 x = qAtomicSetPtr(&d, x);
84 if (x && !x->ref.deref())
85 delete x;
87 return *this;
90 inline bool operator!() const { return !d; }
92 private:
93 T *d;
94 #else // QT_VERSION < 0x040400
95 inline CodeModelPointer(T *value = 0) : QAtomicPointer<T>(value) {}
97 inline CodeModelPointer &operator=(T *o) {
98 QAtomicPointer<T>::operator=(o);
99 return *this;
102 inline T *data() { return (T *) *this; }
103 inline const T *data() const { return (const T *) *this; }
104 inline const T *constData() const { return (const T *) *this; }
105 #endif
108 #if QT_VERSION < 0x040400
109 template <class T>
110 Q_INLINE_TEMPLATE CodeModelPointer<T>::CodeModelPointer(T *adata) : d(adata)
111 { if (d) d->ref.ref(); }
112 #endif
114 #endif // CODEMODEL_POINTER_H