19#include <QtCore/qendian.h>
20#include <QtCore/private/qglobal_p.h>
24enum class QSpecialIntegerBitfieldInitializer {};
40template<
class S,
int pos,
int width,
class T =
typename S::StorageType>
43template<
class S,
int pos,
int width,
class T =
typename S::StorageType>
54 if constexpr (std::is_signed_v<Type>) {
55 UnsignedType i = S::fromSpecial(m_storage->val);
56 i <<= (
sizeof(
Type) * 8) - width - pos;
58 t >>= (
sizeof(
Type) * 8) - width;
61 return (S::fromSpecial(m_storage->val) & mask()) >> pos;
64 bool operator!()
const noexcept {
return !(m_storage->val & S::toSpecial(mask())); }
68 if constexpr (width ==
sizeof(UnsignedType) * 8) {
69 static_assert(pos == 0);
70 return ~UnsignedType(0);
72 return ((UnsignedType(1) << width) - 1) << pos;
77 template<
class Storage,
typename... Accessors>
81 explicit QSpecialIntegerConstAccessor(Storage *storage) : m_storage(storage) {}
86 return ((i.m_storage->val ^ j.m_storage->val) & S::toSpecial(mask())) == 0;
92 return ((i.m_storage->val ^ j.m_storage->val) & S::toSpecial(mask())) != 0;
98template<
class S,
int pos,
int width,
class T>
110 UnsignedType i = S::fromSpecial(m_storage->val);
112 i |= (UnsignedType(t) << pos) & Const::mask();
113 m_storage->val = S::toSpecial(i);
123 explicit QSpecialIntegerAccessor(
Storage *storage) : m_storage(storage) {}
128template<
class S,
typename... Accessors>
143 void set(
typename A::Type value)
161 static constexpr bool isAccessor = std::disjunction_v<std::is_same<A, Accessors>...>;
166 static_assert(isAccessor<A>);
171 typename A::Const member()
const
173 static_assert(isAccessor<A>);
174 return typename A::Const(&storage);
180template<
typename T,
typename... Accessors>
181using QLEIntegerBitfieldUnion
182 = QSpecialIntegerBitfieldUnion<QLittleEndianStorageType<T>, Accessors...>;
184template<
typename T,
typename... Accessors>
185using QBEIntegerBitfieldUnion
186 = QSpecialIntegerBitfieldUnion<QBigEndianStorageType<T>, Accessors...>;
188template<
typename... Accessors>
189using qint32_le_bitfield_union = QLEIntegerBitfieldUnion<
int, Accessors...>;
190template<
typename... Accessors>
191using quint32_le_bitfield_union = QLEIntegerBitfieldUnion<uint, Accessors...>;
192template<
typename... Accessors>
193using qint32_be_bitfield_union = QBEIntegerBitfieldUnion<
int, Accessors...>;
194template<
typename... Accessors>
195using quint32_be_bitfield_union = QBEIntegerBitfieldUnion<uint, Accessors...>;
197template<
int pos,
int width,
typename T =
int>
198using qint32_le_bitfield_member
199 = QSpecialIntegerAccessor<QLittleEndianStorageType<
int>, pos, width, T>;
200template<
int pos,
int width,
typename T = uint>
201using quint32_le_bitfield_member
202 = QSpecialIntegerAccessor<QLittleEndianStorageType<uint>, pos, width, T>;
203template<
int pos,
int width,
typename T =
int>
204using qint32_be_bitfield_member
205 = QSpecialIntegerAccessor<QBigEndianStorageType<
int>, pos, width, T>;
206template<
int pos,
int width,
typename T = uint>
207using quint32_be_bitfield_member
208 = QSpecialIntegerAccessor<QBigEndianStorageType<uint>, pos, width, T>;
QSpecialIntegerAccessor & operator=(Type t)
QSpecialIntegerStorage< S > Storage
void set(typename A::Type value)
constexpr QSpecialIntegerBitfieldUnion(QSpecialIntegerBitfieldInitializer initial)
QSpecialIntegerStorage< S >::UnsignedStorageType data() const
constexpr QSpecialIntegerBitfieldUnion(typename QSpecialIntegerStorage< S >::UnsignedStorageType initial)
constexpr QSpecialIntegerBitfieldUnion()=default
friend bool operator!=(const QSpecialIntegerConstAccessor< S, pos, width, T > &i, const QSpecialIntegerConstAccessor< S, pos, width, T > &j) noexcept
operator Type() const noexcept
friend bool operator==(const QSpecialIntegerConstAccessor< S, pos, width, T > &i, const QSpecialIntegerConstAccessor< S, pos, width, T > &j) noexcept
static constexpr UnsignedType mask() noexcept
bool operator!() const noexcept
constexpr QSpecialIntegerStorage(QSpecialIntegerBitfieldInitializer)
constexpr QSpecialIntegerStorage(UnsignedStorageType initial)
constexpr QSpecialIntegerStorage()=default
constexpr QSpecialIntegerBitfieldInitializer QSpecialIntegerBitfieldZero