diff options
author | David Robillard <d@drobilla.net> | 2018-08-18 18:43:59 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-09-29 14:47:12 +0200 |
commit | 0dc0ebb495dd2be014e705674d1acdf114eb594d (patch) | |
tree | 1a4d6cc865d94ade182e8278dfd2b5f421c59e02 | |
parent | 563313018f06137475402f175520573d1dcfe46b (diff) | |
download | chilbert-0dc0ebb495dd2be014e705674d1acdf114eb594d.tar.gz chilbert-0dc0ebb495dd2be014e705674d1acdf114eb594d.tar.bz2 chilbert-0dc0ebb495dd2be014e705674d1acdf114eb594d.zip |
Add compatible definitions to FixBitVec
-rw-r--r-- | chilbert/FixBitVec.hpp | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/chilbert/FixBitVec.hpp b/chilbert/FixBitVec.hpp index 610119f..36667f3 100644 --- a/chilbert/FixBitVec.hpp +++ b/chilbert/FixBitVec.hpp @@ -43,20 +43,24 @@ typedef uint64_t FBV_UINT; class CFixBitVec { public: - CFixBitVec(const size_t bits = FBV_BITS) + using Rack = uintptr_t; + + static constexpr size_t bits_per_rack = sizeof(Rack) * CHAR_BIT; + + CFixBitVec(const size_t bits = bits_per_rack) : m_rack{0} { - assert(bits <= FBV_BITS); + assert(bits <= bits_per_rack); } - CFixBitVec(const size_t bits, const FBV_UINT value) + CFixBitVec(const size_t bits, const Rack value) : m_rack{value} { - assert(bits <= FBV_BITS); + assert(bits <= bits_per_rack); } /// Return the size in bits - size_t size() const { return FBV_BITS; } + size_t size() const { return bits_per_rack; } /// Set all bits to one CFixBitVec& set() @@ -75,38 +79,38 @@ public: /// Return the value of the `index`th bit bool test(const size_t index) const { - assert(index < FBV_BITS); + assert(index < bits_per_rack); return ((m_rack & (FBV1 << index)) > 0); } /// Set the `index`th bit to 1 CFixBitVec& set(const size_t index) { - assert(index < FBV_BITS); - m_rack |= (FBV_UINT{1} << index); + assert(index < bits_per_rack); + m_rack |= (Rack{1} << index); return *this; } /// Reset the `index`th bit to 0 CFixBitVec& reset(const size_t index) { - assert(index < FBV_BITS); - m_rack &= ~(FBV_UINT{1} << index); + assert(index < bits_per_rack); + m_rack &= ~(Rack{1} << index); return *this; } /// Set the `index`th bit to `value` CFixBitVec& set(const size_t index, const bool value) { - assert(index < FBV_BITS); - m_rack ^= (-FBV_UINT{value} ^ m_rack) & (FBV_UINT{1U} << index); + assert(index < bits_per_rack); + m_rack ^= (-Rack{value} ^ m_rack) & (Rack{1U} << index); return *this; } /// Flip the value of the `index`th bit CFixBitVec& flip(const size_t index) { - assert(index < FBV_BITS); + assert(index < bits_per_rack); m_rack ^= (FBV1 << index); return *this; } @@ -123,7 +127,7 @@ public: bool operator<(const CFixBitVec& vec) const { return m_rack < vec.m_rack; } - CFixBitVec& operator=(const FBV_UINT i) + CFixBitVec& operator=(const Rack i) { m_rack = i; return *this; @@ -161,7 +165,7 @@ public: return *this; } - CFixBitVec& operator^=(const FBV_UINT i) + CFixBitVec& operator^=(const Rack i) { m_rack ^= i; return *this; @@ -251,21 +255,21 @@ public: } /// Return the first rack - FBV_UINT& rack() { return m_rack; } - FBV_UINT rack() const { return m_rack; } + Rack& rack() { return m_rack; } + Rack rack() const { return m_rack; } /// Return a pointer to the racks - FBV_UINT* racks() { return &m_rack; } - const FBV_UINT* racks() const { return &m_rack; } + Rack* racks() { return &m_rack; } + const Rack* racks() const { return &m_rack; } /// Return the number of racks int rackCount() const { return 1; } private: - static_assert(8 * sizeof(FBV_UINT) == FBV_BITS, ""); - static_assert((sizeof(FBV_UINT) == 4) || (sizeof(FBV_UINT) == 8), ""); + static_assert(8 * sizeof(Rack) == bits_per_rack, ""); + static_assert((sizeof(Rack) == 4) || (sizeof(Rack) == 8), ""); - FBV_UINT m_rack{}; + Rack m_rack{}; }; template <> @@ -279,7 +283,7 @@ template <> void grayCodeInv(CFixBitVec& value) { - grayCodeInv<FBV_UINT>(value.rack()); + grayCodeInv<CFixBitVec::Rack>(value.rack()); } inline std::ostream& |