Core/Bitset: Add conversion from integer (to mimic internal representation, experimental)
Former-commit-id: 609a2bbed02cad13a3487b2a95c6f24c0756e829
This commit is contained in:
parent
de76b48fdd
commit
226d75a352
|
|
@ -26,11 +26,12 @@ namespace Nz
|
|||
class Bit;
|
||||
|
||||
Bitset();
|
||||
explicit Bitset(unsigned int bitCount, bool val = false);
|
||||
explicit Bitset(unsigned int bitCount, bool val);
|
||||
explicit Bitset(const char* bits);
|
||||
Bitset(const char* bits, unsigned int bitCount);
|
||||
Bitset(const Bitset& bitset) = default;
|
||||
explicit Bitset(const String& bits);
|
||||
template<typename T> explicit Bitset(T value);
|
||||
Bitset(Bitset&& bitset) noexcept = default;
|
||||
~Bitset() noexcept = default;
|
||||
|
||||
|
|
@ -84,6 +85,7 @@ namespace Nz
|
|||
|
||||
Bitset& operator=(const Bitset& bitset) = default;
|
||||
Bitset& operator=(const String& bits);
|
||||
template<typename T> Bitset& operator=(T value);
|
||||
Bitset& operator=(Bitset&& bitset) noexcept = default;
|
||||
|
||||
Bitset& operator&=(const Bitset& bitset);
|
||||
|
|
|
|||
|
|
@ -108,6 +108,35 @@ namespace Nz
|
|||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Bitset copying an unsigned integral number
|
||||
*
|
||||
* \param value Number to be used as a base
|
||||
*/
|
||||
template<typename Block, class Allocator>
|
||||
template<typename T>
|
||||
Bitset<Block, Allocator>::Bitset(T value) :
|
||||
Bitset()
|
||||
{
|
||||
if (sizeof(T) <= sizeof(Block))
|
||||
{
|
||||
m_bitCount = CountBits(value);
|
||||
m_blocks.push_back(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Note: I was kinda tired when I wrote this, there's probably a much easier method than checking bits to write bits
|
||||
unsigned int bitPos = 0;
|
||||
for (T bit = 1; bit < std::numeric_limits<T>::digits; bit <<= 1)
|
||||
{
|
||||
if (value & bit)
|
||||
UnboundedSet(bitPos, true);
|
||||
|
||||
bitPos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Clears the content of the bitset, GetSize() is now equals to 0
|
||||
*
|
||||
|
|
@ -633,7 +662,7 @@ namespace Nz
|
|||
* \param bit Index of the bit
|
||||
* \param val Value of the bit
|
||||
*
|
||||
* \remark if bit is greather than the number of bits, the bitset is enlarged and the added bits are set to false and the one at bit is set to val
|
||||
* \remark if bit is greater than the number of bits, the bitset is enlarged and the added bits are set to false and the one at bit is set to val
|
||||
*
|
||||
* \see Set
|
||||
*/
|
||||
|
|
@ -721,6 +750,22 @@ namespace Nz
|
|||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Copies the internal representation of an unsigned integer
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param value Unsigned number which will be used as a source
|
||||
*/
|
||||
template<typename Block, class Allocator>
|
||||
template<typename T>
|
||||
Bitset<Block, Allocator>& Bitset<Block, Allocator>::operator=(T value)
|
||||
{
|
||||
Bitset bitset(value);
|
||||
std::swap(*this, bitset);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Performs an "AND" with another bitset
|
||||
* \return A reference to this
|
||||
|
|
|
|||
Loading…
Reference in New Issue