3#include <Foundation/Containers/DynamicArray.h>
4#include <Foundation/Containers/HybridArray.h>
5#include <Foundation/Containers/Implementation/BitIterator.h>
6#include <Foundation/IO/Stream.h>
7#include <Foundation/Math/Constants.h>
15template <
class Container>
25 template <
typename =
void>
29 void SetCount(plUInt32 uiBitCount,
bool bSetNew =
false);
35 bool IsAnyBitSet(plUInt32 uiFirstBit = 0, plUInt32 uiNumBits = 0xFFFFFFFF)
const;
38 bool IsNoBitSet(plUInt32 uiFirstBit = 0, plUInt32 uiNumBits = 0xFFFFFFFF)
const;
41 bool AreAllBitsSet(plUInt32 uiFirstBit = 0, plUInt32 uiNumBits = 0xFFFFFFFF)
const;
47 void SetBit(plUInt32 uiBit);
65 void SetBitRange(plUInt32 uiFirstBit, plUInt32 uiNumBits);
74 using iterator_category = std::forward_iterator_tag;
75 using value_type = plUInt32;
88 plUInt32
Value()
const;
103 void FindNextChunk(plUInt32 uiStartChunk);
106 plUInt32 m_uiChunk = 0;
121 plUInt32 GetBitInt(plUInt32 uiBitIndex)
const;
122 plUInt32 GetBitMask(plUInt32 uiBitIndex)
const;
124 plUInt32 m_uiCount = 0;
125 Container m_Container;
132template <plUInt32 BITS>
137template <
typename Container>
143template <
typename Container>
149template <
typename Container>
155template <
typename Container>
169 using StorageType = T;
189 void SetBit(plUInt32 uiBit);
198 bool IsBitSet(plUInt32 uiBit)
const;
207 void SetBitRange(plUInt32 uiFirstBit, plUInt32 uiNumBits);
239 inout_writer << m_Storage;
245 inout_reader.ReadVersion(s_Version);
246 inout_reader >> m_Storage;
264 static constexpr plTypeVersion s_Version = 1;
267 : m_Storage(initValue)
271 template <
typename U>
274 template <
typename U>
277 template <
typename U>
280 template <
typename U>
283 template <
typename U>
286 StorageType m_Storage = 0;
310 return lhs.m_Storage == rhs.m_Storage;
316 return lhs.m_Storage != rhs.m_Storage;
321template <
typename Container>
327template <
typename Container>
333template <
typename Container>
339template <
typename Container>
350#include <Foundation/Containers/Implementation/Bitfield_inl.h>
A template interface, that turns any array class into a bitfield.
Definition Bitfield.h:17
bool IsEmpty() const
Returns true, if the bitfield does not store any bits.
Definition Bitfield_inl.h:52
void SetBitValue(plUInt32 uiBit, bool bValue)
Sets the given bit to 1 or 0 depending on the given value.
Definition Bitfield_inl.h:191
void SetCount(plUInt32 uiBitCount, bool bSetNew=false)
Resizes the Bitfield to hold the given number of bits. If bSetNew is true, new bits are set to 1,...
Definition Bitfield_inl.h:32
bool IsNoBitSet(plUInt32 uiFirstBit=0, plUInt32 uiNumBits=0xFFFFFFFF) const
Returns true, if the bitfield is empty or all bits are set to zero.
Definition Bitfield_inl.h:110
void ClearBit(plUInt32 uiBit)
Clears the given bit to 0.
Definition Bitfield_inl.h:183
ConstIterator GetIterator() const
Returns a constant iterator to the very first set bit. Note that due to the way iterating through bit...
Definition Bitfield_inl.h:309
bool IsBitSet(plUInt32 uiBit) const
Returns true, if the given bit is set to 1.
Definition Bitfield_inl.h:204
plUInt32 GetCount() const
Returns the number of bits that this bitfield stores.
Definition Bitfield_inl.h:16
void SetCountUninitialized(plUInt32 uiBitCount)
Resizes the Bitfield to hold the given number of bits. This version does NOT initialize new bits!
Definition Bitfield_inl.h:23
bool AreAllBitsSet(plUInt32 uiFirstBit=0, plUInt32 uiNumBits=0xFFFFFFFF) const
Returns true, if the bitfield is not empty and all bits are set to one.
Definition Bitfield_inl.h:116
void ClearBitRange(plUInt32 uiFirstBit, plUInt32 uiNumBits)
Clears the range starting at uiFirstBit up to (and including) uiLastBit to 0.
Definition Bitfield_inl.h:264
void SetBit(plUInt32 uiBit)
Sets the given bit to 1.
Definition Bitfield_inl.h:175
void SetBitRange(plUInt32 uiFirstBit, plUInt32 uiNumBits)
Sets the range starting at uiFirstBit up to (and including) uiLastBit to 1.
Definition Bitfield_inl.h:226
void Clear()
Discards all bits and sets count to zero.
Definition Bitfield_inl.h:168
void SetAllBits()
Sets all bits to 1.
Definition Bitfield_inl.h:219
ConstIterator GetEndIterator() const
Returns an invalid iterator. Needed to support range based for loops.
Definition Bitfield_inl.h:315
void Swap(plBitfield< Container > &other)
Swaps two bitfields.
Definition Bitfield_inl.h:302
void ClearAllBits()
Clears all bits to 0.
Definition Bitfield_inl.h:212
bool IsAnyBitSet(plUInt32 uiFirstBit=0, plUInt32 uiNumBits=0xFFFFFFFF) const
Returns true, if the bitfield is not empty and any bit is 1.
Definition Bitfield_inl.h:58
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Definition Bitfield.h:167
void Swap(plStaticBitfield< T > &other)
Swaps two bitfields.
Definition Bitfield_inl.h:543
plUInt32 GetLowestBitSet() const
Returns the index of the lowest bit that is set. Returns the max index+1 in case no bit is set,...
Definition Bitfield_inl.h:476
bool IsBitSet(plUInt32 uiBit) const
Returns true, if the given bit is set to 1.
Definition Bitfield_inl.h:494
void ClearBit(plUInt32 uiBit)
Clears the given bit to 0.
Definition Bitfield_inl.h:502
bool IsAnyBitSet() const
Returns true, if the bitfield is not zero.
Definition Bitfield_inl.h:424
void ClearBitRange(plUInt32 uiFirstBit, plUInt32 uiNumBits)
Clears the range starting at uiFirstBit up to (and including) uiLastBit to 0.
Definition Bitfield_inl.h:443
bool AreAllBitsSet() const
Returns true, if the bitfield is not empty and all bits are set to one.
Definition Bitfield_inl.h:436
void SetAllBits()
Sets all bits to 1.
Definition Bitfield_inl.h:482
ConstIterator GetIterator() const
Returns a constant iterator to the very first set bit. Note that due to the way iterating through bit...
Definition Bitfield.h:252
PL_ALWAYS_INLINE void operator|=(const plStaticBitfield< T > &rhs)
Modifies this to also contain the bits from rhs.
Definition Bitfield.h:231
void SetValue(T value)
Sets the raw uint that stores all bits.
Definition Bitfield_inl.h:531
plStaticBitfield()
Initializes the bitfield to all zero.
Definition Bitfield_inl.h:412
bool IsNoBitSet() const
Returns true, if the bitfield is all zero.
Definition Bitfield_inl.h:430
plUInt32 GetNumBitsSet() const
Returns the count of how many bits are set in total.
Definition Bitfield_inl.h:464
void ClearAllBits()
Clears all bits to 0. Same as Clear().
Definition Bitfield_inl.h:488
PL_ALWAYS_INLINE void operator&=(const plStaticBitfield< T > &rhs)
Modifies this to only contain the bits that were set in this and rhs.
Definition Bitfield.h:234
T GetValue() const
Returns the raw uint that stores all bits.
Definition Bitfield_inl.h:537
void SetBitValue(plUInt32 uiBit, bool bValue)
Sets the given bit to 1 or 0 depending on the given value.
Definition Bitfield_inl.h:510
void SetBitRange(plUInt32 uiFirstBit, plUInt32 uiNumBits)
Sets the range starting at uiFirstBit up to (and including) uiLastBit to 1.
Definition Bitfield_inl.h:454
void SetBit(plUInt32 uiBit)
Sets the given bit to 1.
Definition Bitfield_inl.h:523
ConstIterator GetEndIterator() const
Returns an invalid iterator. Needed to support range based for loops.
Definition Bitfield.h:258
plUInt32 GetHighestBitSet() const
Returns the index of the highest bit that is set. Returns the max index+1 in case no bit is set,...
Definition Bitfield_inl.h:470
Interface for binary in (read) streams.
Definition Stream.h:22
Interface for binary out (write) streams.
Definition Stream.h:107
PL_ALWAYS_INLINE void WriteVersion(plTypeVersion version)
Writes a type version to the stream.
Definition Stream_inl.h:154
constexpr plUInt32 NumBits()
Returns the number of bits in the given type. Mostly useful for unsigned integer types.
void operator++()
Shorthand for 'Next'.
Definition Bitfield_inl.h:371
plUInt32 Value() const
Returns the 'value' of the element that this iterator points to.
Definition Bitfield_inl.h:337
bool IsValid() const
Checks whether this iterator points to a valid element.
Definition Bitfield_inl.h:331
plUInt32 operator*() const
Returns 'Value()' to enable foreach.
Definition Bitfield_inl.h:365
void Next()
Advances the iterator to the next element in the map. The iterator will not be valid anymore,...
Definition Bitfield_inl.h:343
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54