1 /*
2  * DQt - D bindings for the Qt Toolkit
3  *
4  * GNU Lesser General Public License Usage
5  * This file may be used under the terms of the GNU Lesser
6  * General Public License version 3 as published by the Free Software
7  * Foundation and appearing in the file LICENSE.LGPL3 included in the
8  * packaging of this file. Please review the following information to
9  * ensure the GNU Lesser General Public License version 3 requirements
10  * will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
11  */
12 module qt.core.bitarray;
13 extern(C++):
14 
15 import qt.config;
16 import qt.core.bytearray;
17 import qt.core.global;
18 import qt.core.sysinfo;
19 import qt.core.typeinfo;
20 import qt.helpers;
21 
22 /// Binding for C++ class [QBitArray](https://doc.qt.io/qt-6/qbitarray.html).
23 @Q_RELOCATABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QBitArray
24 {
25 private:
26     version(QT_NO_DATASTREAM){}else
27     {
28         /+ friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QBitArray &); +/
29         /+ friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QBitArray &); +/
30     }
31     /+ friend Q_CORE_EXPORT size_t qHash(const QBitArray &key, size_t seed) noexcept; +/
32     QByteArray d;
33 
34 public:
35     @disable this();
36     /+pragma(inline, true) this()/+ noexcept+/ {}+/
37     /+ explicit +/this(qsizetype size, bool val = false);
38     /+pragma(inline, true) ref QBitArray operator =(ref const(QBitArray) other) { d = other.d; return this; }+/
39     /+ inline QBitArray(QBitArray &&other) noexcept : d(std::move(other.d)) {} +/
40     /+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QBitArray) +/
41 
42     /+ inline void swap(QBitArray &other) noexcept { qSwap(d, other.d); } +/
43 
44     pragma(inline, true) qsizetype size() const { return (d.size() << 3) - *d.constData(); }
45     pragma(inline, true) qsizetype count() const { return (d.size() << 3) - *d.constData(); }
46     qsizetype count(bool on) const;
47 
48     pragma(inline, true) bool isEmpty() const { return d.isEmpty(); }
49     pragma(inline, true) bool isNull() const { return d.isNull(); }
50 
51     void resize(qsizetype size);
52 
53     pragma(inline, true) void detach() { d.detach(); }
54     pragma(inline, true) bool isDetached() const { return d.isDetached(); }
55     pragma(inline, true) void clear() { d.clear(); }
56 
57     pragma(inline, true) bool testBit(qsizetype i) const
58     { (mixin(Q_ASSERT(q{size_t(i) < size_t(QBitArray.size())})));
59      return (*(reinterpret_cast!(const(uchar)*)(d.constData())+1+(i>>3)) & (1 << (i & 7))) != 0; }
60     pragma(inline, true) void setBit(qsizetype i)
61     { (mixin(Q_ASSERT(q{size_t(i) < size_t(QBitArray.size())})));
62      *(reinterpret_cast!(uchar*)(d.data())+1+(i>>3)) |= cast(uchar)(1 << (i & 7)); }
63     pragma(inline, true) void setBit(qsizetype i, bool val)
64     { if (val) setBit(i); else clearBit(i); }
65     pragma(inline, true) void clearBit(qsizetype i)
66     { (mixin(Q_ASSERT(q{size_t(i) < size_t(QBitArray.size())})));
67      *(reinterpret_cast!(uchar*)(d.data())+1+(i>>3)) &= ~int(uchar(1 << (i & 7))); }
68     pragma(inline, true) bool toggleBit(qsizetype i)
69     { (mixin(Q_ASSERT(q{size_t(i) < size_t(QBitArray.size())})));
70      uchar b = cast(uchar)(1<<(i&7)); uchar* p = reinterpret_cast!(uchar*)(d.data())+1+(i>>3);
71      uchar c = cast(uchar)(*p&b); *p^=b; return c!=0; }
72 
73     pragma(inline, true) bool at(qsizetype i) const { return testBit(i); }
74     pragma(inline, true) QBitRef opIndex(qsizetype i)
75     { (mixin(Q_ASSERT(q{i >= 0}))); return QBitRef(this, i); }
76     pragma(inline, true) bool opIndex(qsizetype i) const { return testBit(i); }
77 
78     ref QBitArray opOpAssign(string op)(ref const(QBitArray) ) if(op == "&");
79     ref QBitArray opOpAssign(string op)(ref const(QBitArray) ) if(op == "|");
80     /+ref QBitArray operator ^=(ref const(QBitArray) );+/
81     /+QBitArray operator ~() const;+/
82 
83     /+pragma(inline, true) bool operator ==(ref const(QBitArray) other) const { return d == other.d; }+/
84     /+pragma(inline, true) bool operator !=(ref const(QBitArray) other) const { return d != other.d; }+/
85 
86     pragma(inline, true) bool fill(bool aval, qsizetype asize = -1)
87     { this = QBitArray((asize < 0 ? this.size() : asize), aval); return true; }
88     void fill(bool val, qsizetype first, qsizetype last);
89 
90     pragma(inline, true) void truncate(qsizetype pos) { if (pos < size()) resize(pos); }
91 
92     const(char)* bits() const { return isEmpty() ? null : d.constData() + 1; }
93     static QBitArray fromBits(const(char)* data, qsizetype len);
94 
95     quint32 toUInt32(QSysInfo.Endian endianness, bool* ok = null) const/+ noexcept+/;
96 
97 public:
98     alias DataPtr = QByteArray.DataPointer;
99     pragma(inline, true) ref DataPtr data_ptr() return { return d.data_ptr(); }
100     mixin(CREATE_CONVENIENCE_WRAPPERS);
101 }
102 
103 /+/+ Q_CORE_EXPORT +/ QBitArray operator &(ref const(QBitArray) , ref const(QBitArray) );+/
104 /+/+ Q_CORE_EXPORT +/ QBitArray operator |(ref const(QBitArray) , ref const(QBitArray) );+/
105 /+/+ Q_CORE_EXPORT +/ QBitArray operator ^(ref const(QBitArray) , ref const(QBitArray) );+/
106 
107 extern(C++, class) struct /+ Q_CORE_EXPORT +/ QBitRef
108 {
109 private:
110     QBitArray *a;
111     qsizetype i;
112     pragma(inline, true) this(ref QBitArray array, qsizetype idx)
113     {
114         this.a = &array;
115         this.i = idx;
116     }
117     /+ friend class QBitArray; +/
118 
119 public:
120     /+pragma(inline, true) auto opCast(T : bool)() const { return a.testBit(i); }+/
121     /+pragma(inline, true) bool operator !() const { return !a.testBit(i); }+/
122     /+ref QBitRef operator =(ref const(QBitRef) val) { a.setBit(i, val); return this; }+/
123     /+ref QBitRef operator =(bool val) { a.setBit(i, val); return this; }+/
124     mixin(CREATE_CONVENIENCE_WRAPPERS);
125 }
126 
127 /+ #ifndef QT_NO_DATASTREAM
128 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QBitArray &);
129 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QBitArray &);
130 #endif
131 
132 #ifndef QT_NO_DEBUG_STREAM
133 Q_CORE_EXPORT QDebug operator<<(QDebug, const QBitArray &);
134 #endif
135 
136 Q_DECLARE_SHARED(QBitArray) +/
137