1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
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.
56 #include <QtCore/qglobal.h>
64 inline QBitField(const quint32 *, int bits);
65 inline QBitField(const QBitField &);
68 inline QBitField &operator=(const QBitField &);
70 inline quint32 size() const;
71 inline QBitField united(const QBitField &);
72 inline bool testBit(int) const;
80 QBitField::QBitField()
81 : bits(0), ownData(0), data(0)
85 QBitField::QBitField(const quint32 *bitData, int bitCount)
86 : bits((quint32)bitCount), ownData(0), data(bitData)
90 QBitField::QBitField(const QBitField &other)
91 : bits(other.bits), ownData(other.ownData), data(other.data)
97 QBitField::~QBitField()
100 if(0 == --(*ownData)) delete [] ownData;
103 QBitField &QBitField::operator=(const QBitField &other)
105 if (other.data == data)
109 if(0 == --(*ownData)) delete [] ownData;
112 ownData = other.ownData;
121 inline quint32 QBitField::size() const
126 QBitField QBitField::united(const QBitField &o)
130 } else if (bits == 0) {
133 int max = (bits > o.bits)?bits:o.bits;
134 int length = (max + 31) / 32;
137 rv.ownData = new quint32[length + 1];
139 rv.data = rv.ownData + 1;
141 ::memcpy((quint32 *)rv.data, data, length * sizeof(quint32));
142 for (quint32 ii = 0; ii < (o.bits + quint32(31)) / 32; ++ii)
143 ((quint32 *)rv.data)[ii] |= o.data[ii];
145 ::memcpy((quint32 *)rv.data, o.data, length * sizeof(quint32));
146 for (quint32 ii = 0; ii < (bits + quint32(31)) / 32; ++ii)
147 ((quint32 *)rv.data)[ii] |= data[ii];
153 bool QBitField::testBit(int b) const
156 if ((quint32)b < bits) {
157 return data[b / 32] & (1 << (b % 32));
165 #endif // QBITFIELD_P_H