diff --git a/include/flatmemory/details/types/bitset.hpp b/include/flatmemory/details/types/bitset.hpp index 873fd1a..421b9f6 100644 --- a/include/flatmemory/details/types/bitset.hpp +++ b/include/flatmemory/details/types/bitset.hpp @@ -662,197 +662,6 @@ size_t Operator>::get_offset(size_t position) noexcept return position % block_size; } -/* View */ - -template -View>::View(uint8_t* buf) : m_buf(buf) -{ - assert(m_buf); -} - -template -bool View>::get(std::size_t position) const -{ - assert(m_buf); - return BitsetOperator::get(*this, position); -} - -template -size_t View>::count() const -{ - assert(m_buf); - return BitsetOperator::count(*this); -} - -template -View>::const_iterator View>::begin() -{ - return const_iterator(get_default_bit_value(), get_blocks().data(), get_blocks().size(), true); -} - -template -View>::const_iterator View>::begin() const -{ - return const_iterator(get_default_bit_value(), get_blocks().data(), get_blocks().size(), true); -} - -template -View>::const_iterator View>::end() -{ - return const_iterator(get_default_bit_value(), get_blocks().data(), get_blocks().size(), false); -} - -template -View>::const_iterator View>::end() const -{ - return const_iterator(get_default_bit_value(), get_blocks().data(), get_blocks().size(), false); -} - -template -uint8_t* View>::buffer() -{ - return m_buf; -} - -template -const uint8_t* View>::buffer() const -{ - return m_buf; -} - -template -buffer_size_type View>::buffer_size() const -{ - assert(m_buf); - assert(test_correct_alignment(m_buf + BitsetLayout::buffer_size_position)); - return read_value(m_buf + BitsetLayout::buffer_size_position); -} - -template -bool& View>::get_default_bit_value() -{ - assert(m_buf); - assert(test_correct_alignment(m_buf + BitsetLayout::default_bit_value_position)); - return read_value(m_buf + BitsetLayout::default_bit_value_position); -} - -template -bool View>::get_default_bit_value() const -{ - assert(m_buf); - assert(test_correct_alignment(m_buf + BitsetLayout::default_bit_value_position)); - return read_value(m_buf + BitsetLayout::default_bit_value_position); -} - -template -View> View>::get_blocks() -{ - assert(m_buf); - return View>(m_buf + BitsetLayout::blocks_position); -} - -template -ConstView> View>::get_blocks() const -{ - assert(m_buf); - return ConstView>(m_buf + BitsetLayout::blocks_position); -} - -/* ConstView */ - -template -ConstView>::ConstView(const uint8_t* data) : m_buf(data) -{ - assert(m_buf); -} - -template -ConstView>::ConstView(const BitsetView& view) : m_buf(view.buffer()) -{ -} - -template -bool ConstView>::get(std::size_t position) const -{ - assert(m_buf); - return BitsetOperator::get(*this, position); -} - -template -size_t ConstView>::count() const -{ - assert(m_buf); - return BitsetOperator::count(*this); -} - -template -ConstView>::const_iterator ConstView>::begin() -{ - return const_iterator(get_default_bit_value(), get_blocks().data(), get_blocks().size(), true); -} - -template -ConstView>::const_iterator ConstView>::begin() const -{ - return const_iterator(get_default_bit_value(), get_blocks().data(), get_blocks().size(), true); -} - -template -ConstView>::const_iterator ConstView>::end() -{ - return const_iterator(get_default_bit_value(), get_blocks().data(), get_blocks().size(), false); -} - -template -ConstView>::const_iterator ConstView>::end() const -{ - return const_iterator(get_default_bit_value(), get_blocks().data(), get_blocks().size(), false); -} - -template -const uint8_t* ConstView>::buffer() const -{ - return m_buf; -} - -template -buffer_size_type ConstView>::buffer_size() const -{ - assert(m_buf); - assert(test_correct_alignment(m_buf + BitsetLayout::buffer_size_position)); - return read_value(m_buf + BitsetLayout::buffer_size_position); -} - -template -bool ConstView>::get_default_bit_value() -{ - assert(m_buf); - assert(test_correct_alignment(m_buf + BitsetLayout::default_bit_value_position)); - return read_value(m_buf + BitsetLayout::default_bit_value_position); -} - -template -bool ConstView>::get_default_bit_value() const -{ - assert(m_buf); - assert(test_correct_alignment(m_buf + BitsetLayout::default_bit_value_position)); - return read_value(m_buf + BitsetLayout::default_bit_value_position); -} - -template -ConstView> ConstView>::get_blocks() -{ - assert(m_buf); - return ConstView>(m_buf + BitsetLayout::blocks_position); -} - -template -ConstView> ConstView>::get_blocks() const -{ - assert(m_buf); - return ConstView>(m_buf + BitsetLayout::blocks_position); -} - /* Builder */ template @@ -1242,6 +1051,197 @@ const auto& Builder>::get_blocks() const return m_blocks; } +/* View */ + +template +View>::View(uint8_t* buf) : m_buf(buf) +{ + assert(m_buf); +} + +template +bool View>::get(std::size_t position) const +{ + assert(m_buf); + return BitsetOperator::get(*this, position); +} + +template +size_t View>::count() const +{ + assert(m_buf); + return BitsetOperator::count(*this); +} + +template +View>::const_iterator View>::begin() +{ + return const_iterator(get_default_bit_value(), get_blocks().data(), get_blocks().size(), true); +} + +template +View>::const_iterator View>::begin() const +{ + return const_iterator(get_default_bit_value(), get_blocks().data(), get_blocks().size(), true); +} + +template +View>::const_iterator View>::end() +{ + return const_iterator(get_default_bit_value(), get_blocks().data(), get_blocks().size(), false); +} + +template +View>::const_iterator View>::end() const +{ + return const_iterator(get_default_bit_value(), get_blocks().data(), get_blocks().size(), false); +} + +template +uint8_t* View>::buffer() +{ + return m_buf; +} + +template +const uint8_t* View>::buffer() const +{ + return m_buf; +} + +template +buffer_size_type View>::buffer_size() const +{ + assert(m_buf); + assert(test_correct_alignment(m_buf + BitsetLayout::buffer_size_position)); + return read_value(m_buf + BitsetLayout::buffer_size_position); +} + +template +bool& View>::get_default_bit_value() +{ + assert(m_buf); + assert(test_correct_alignment(m_buf + BitsetLayout::default_bit_value_position)); + return read_value(m_buf + BitsetLayout::default_bit_value_position); +} + +template +bool View>::get_default_bit_value() const +{ + assert(m_buf); + assert(test_correct_alignment(m_buf + BitsetLayout::default_bit_value_position)); + return read_value(m_buf + BitsetLayout::default_bit_value_position); +} + +template +View> View>::get_blocks() +{ + assert(m_buf); + return View>(m_buf + BitsetLayout::blocks_position); +} + +template +ConstView> View>::get_blocks() const +{ + assert(m_buf); + return ConstView>(m_buf + BitsetLayout::blocks_position); +} + +/* ConstView */ + +template +ConstView>::ConstView(const uint8_t* data) : m_buf(data) +{ + assert(m_buf); +} + +template +ConstView>::ConstView(const BitsetView& view) : m_buf(view.buffer()) +{ +} + +template +bool ConstView>::get(std::size_t position) const +{ + assert(m_buf); + return BitsetOperator::get(*this, position); +} + +template +size_t ConstView>::count() const +{ + assert(m_buf); + return BitsetOperator::count(*this); +} + +template +ConstView>::const_iterator ConstView>::begin() +{ + return const_iterator(get_default_bit_value(), get_blocks().data(), get_blocks().size(), true); +} + +template +ConstView>::const_iterator ConstView>::begin() const +{ + return const_iterator(get_default_bit_value(), get_blocks().data(), get_blocks().size(), true); +} + +template +ConstView>::const_iterator ConstView>::end() +{ + return const_iterator(get_default_bit_value(), get_blocks().data(), get_blocks().size(), false); +} + +template +ConstView>::const_iterator ConstView>::end() const +{ + return const_iterator(get_default_bit_value(), get_blocks().data(), get_blocks().size(), false); +} + +template +const uint8_t* ConstView>::buffer() const +{ + return m_buf; +} + +template +buffer_size_type ConstView>::buffer_size() const +{ + assert(m_buf); + assert(test_correct_alignment(m_buf + BitsetLayout::buffer_size_position)); + return read_value(m_buf + BitsetLayout::buffer_size_position); +} + +template +bool ConstView>::get_default_bit_value() +{ + assert(m_buf); + assert(test_correct_alignment(m_buf + BitsetLayout::default_bit_value_position)); + return read_value(m_buf + BitsetLayout::default_bit_value_position); +} + +template +bool ConstView>::get_default_bit_value() const +{ + assert(m_buf); + assert(test_correct_alignment(m_buf + BitsetLayout::default_bit_value_position)); + return read_value(m_buf + BitsetLayout::default_bit_value_position); +} + +template +ConstView> ConstView>::get_blocks() +{ + assert(m_buf); + return ConstView>(m_buf + BitsetLayout::blocks_position); +} + +template +ConstView> ConstView>::get_blocks() const +{ + assert(m_buf); + return ConstView>(m_buf + BitsetLayout::blocks_position); +} + /* Free function operators */ template