Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / declarative / qml / ftw / qflagpointer_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QFLAGPOINTER_P_H
43 #define QFLAGPOINTER_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include <QtCore/qglobal.h>
57
58 QT_BEGIN_NAMESPACE
59
60 template<typename T>
61 class QFlagPointer {
62 public:
63     inline QFlagPointer();
64     inline QFlagPointer(T *);
65     inline QFlagPointer(const QFlagPointer<T> &o);
66
67     inline bool isNull() const;
68
69     inline bool flag() const;
70     inline void setFlag();
71     inline void clearFlag();
72
73     inline bool flag2() const;
74     inline void setFlag2();
75     inline void clearFlag2();
76
77     inline QFlagPointer<T> &operator=(const QFlagPointer &o);
78     inline QFlagPointer<T> &operator=(T *);
79
80     inline T *operator->() const;
81     inline T *operator*() const;
82
83 private:
84     intptr_t ptr_value;
85
86     static const intptr_t FlagBit = 0x1;
87     static const intptr_t Flag2Bit = 0x2;
88     static const intptr_t FlagsMask = FlagBit | Flag2Bit;
89 };
90
91 template<typename T>
92 QFlagPointer<T>::QFlagPointer()
93 : ptr_value(0)
94 {
95 }
96
97 template<typename T>
98 QFlagPointer<T>::QFlagPointer(T *v)
99 : ptr_value(intptr_t(v))
100 {
101     Q_ASSERT((ptr_value & FlagsMask) == 0);
102 }
103
104 template<typename T>
105 QFlagPointer<T>::QFlagPointer(const QFlagPointer<T> &o)
106 : ptr_value(o.ptr_value)
107 {
108 }
109
110 template<typename T>
111 bool QFlagPointer<T>::isNull() const
112 {
113     return 0 == (ptr_value & (~FlagsMask));
114 }
115
116 template<typename T>
117 bool QFlagPointer<T>::flag() const
118 {
119     return ptr_value & FlagBit;
120 }
121
122 template<typename T>
123 void QFlagPointer<T>::setFlag()
124 {
125     ptr_value |= FlagBit;
126 }
127
128 template<typename T>
129 void QFlagPointer<T>::clearFlag()
130 {
131     ptr_value &= ~FlagBit;
132 }
133
134 template<typename T>
135 bool QFlagPointer<T>::flag2() const
136 {
137     return ptr_value & Flag2Bit;
138 }
139
140 template<typename T>
141 void QFlagPointer<T>::setFlag2()
142 {
143     ptr_value|= Flag2Bit;
144 }
145
146 template<typename T>
147 void QFlagPointer<T>::clearFlag2()
148 {
149     ptr_value &= ~Flag2Bit;
150 }
151
152 template<typename T>
153 QFlagPointer<T> &QFlagPointer<T>::operator=(const QFlagPointer &o)
154 {
155     ptr_value = o.ptr_value;
156     return *this;
157 }
158
159 template<typename T>
160 QFlagPointer<T> &QFlagPointer<T>::operator=(T *o)
161 {
162     Q_ASSERT((intptr_t(o) & FlagsMask) == 0);
163
164     ptr_value = intptr_t(o) | (ptr_value & FlagsMask);
165     return *this;
166 }
167
168 template<typename T>
169 T *QFlagPointer<T>::operator->() const
170 {
171     return (T *)(ptr_value & ~FlagsMask);
172 }
173
174 template<typename T>
175 T *QFlagPointer<T>::operator*() const
176 {
177     return (T *)(ptr_value & ~FlagsMask);
178 }
179
180 QT_END_NAMESPACE
181
182 #endif // QFLAGPOINTER_P_H