18#include <QtCore/qendian.h>
19#include <QtCore/private/qglobal_p.h>
23enum class QSpecialIntegerBitfieldInitializer {};
39template<
class S,
int pos,
int width,
class T =
typename S::StorageType>
42template<
class S,
int pos,
int width,
class T =
typename S::StorageType>
53 if constexpr (std::is_signed_v<Type>) {
54 UnsignedType i = S::fromSpecial(m_storage->val);
55 i <<= (
sizeof(
Type) * 8) - width - pos;
57 t >>= (
sizeof(
Type) * 8) - width;
60 return (S::fromSpecial(m_storage->val) & mask()) >> pos;
63 bool operator!()
const noexcept {
return !(m_storage->val & S::toSpecial(mask())); }
67 if constexpr (width ==
sizeof(UnsignedType) * 8) {
68 static_assert(pos == 0);
69 return ~UnsignedType(0);
71 return ((UnsignedType(1) << width) - 1) << pos;
76 template<
class Storage,
typename... Accessors>
80 explicit QSpecialIntegerConstAccessor(Storage *storage) : m_storage(storage) {}
85 return ((i.m_storage->val ^ j.m_storage->val) & S::toSpecial(mask())) == 0;
91 return ((i.m_storage->val ^ j.m_storage->val) & S::toSpecial(mask())) != 0;
97template<
class S,
int pos,
int width,
class T>
109 UnsignedType i = S::fromSpecial(m_storage->val);
111 i |= (UnsignedType(t) << pos) & Const::mask();
112 m_storage->val = S::toSpecial(i);
122 explicit QSpecialIntegerAccessor(
Storage *storage) : m_storage(storage) {}
127template<
class S,
typename... Accessors>
142 void set(
typename A::Type value)
160 static constexpr bool isAccessor = std::disjunction_v<std::is_same<A, Accessors>...>;
165 static_assert(isAccessor<A>);
170 typename A::Const member()
const
172 static_assert(isAccessor<A>);
173 return typename A::Const(&storage);
179template<
typename T,
typename... Accessors>
180using QLEIntegerBitfieldUnion
181 = QSpecialIntegerBitfieldUnion<QLittleEndianStorageType<T>, Accessors...>;
183template<
typename T,
typename... Accessors>
184using QBEIntegerBitfieldUnion
185 = QSpecialIntegerBitfieldUnion<QBigEndianStorageType<T>, Accessors...>;
187template<
typename... Accessors>
188using qint32_le_bitfield_union = QLEIntegerBitfieldUnion<
int, Accessors...>;
189template<
typename... Accessors>
190using quint32_le_bitfield_union = QLEIntegerBitfieldUnion<uint, Accessors...>;
191template<
typename... Accessors>
192using qint32_be_bitfield_union = QBEIntegerBitfieldUnion<
int, Accessors...>;
193template<
typename... Accessors>
194using quint32_be_bitfield_union = QBEIntegerBitfieldUnion<uint, Accessors...>;
196template<
int pos,
int width,
typename T =
int>
197using qint32_le_bitfield_member
198 = QSpecialIntegerAccessor<QLittleEndianStorageType<
int>, pos, width, T>;
199template<
int pos,
int width,
typename T = uint>
200using quint32_le_bitfield_member
201 = QSpecialIntegerAccessor<QLittleEndianStorageType<uint>, pos, width, T>;
202template<
int pos,
int width,
typename T =
int>
203using qint32_be_bitfield_member
204 = QSpecialIntegerAccessor<QBigEndianStorageType<
int>, pos, width, T>;
205template<
int pos,
int width,
typename T = uint>
206using quint32_be_bitfield_member
207 = 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