sparrow
2.4.0
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Toggle main menu visibility
Loading...
Searching...
No Matches
bitset_iterator.hpp
Go to the documentation of this file.
1
// Copyright 2024 Man Group Operations Limited
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#pragma once
16
17
#include "
sparrow/utils/contracts.hpp
"
18
#include "
sparrow/utils/iterator.hpp
"
19
#include "
sparrow/utils/mp_utils.hpp
"
20
21
namespace
sparrow
22
{
23
template
<
class
B>
24
class
bitset_reference
;
25
36
template
<
class
B,
bool
is_const>
37
class
bitset_iterator
:
public
pointer_index_iterator_base
<
38
bitset_iterator<B, is_const>,
39
mpl::constify_t<B, is_const>,
40
mpl::constify_t<typename B::value_type, is_const>,
41
std::conditional_t<is_const, bool, bitset_reference<B>>,
42
std::random_access_iterator_tag>
43
{
44
public
:
45
46
using
self_type
=
bitset_iterator<B, is_const>
;
47
using
base_type
=
pointer_index_iterator_base
<
48
self_type
,
49
mpl::constify_t<B, is_const>
,
50
mpl::constify_t<typename B::value_type, is_const>
,
51
std::conditional_t<is_const, bool, bitset_reference<B>>,
52
std::random_access_iterator_tag>;
53
using
reference
=
typename
base_type::reference;
54
using
difference_type
=
typename
base_type::difference_type
;
55
56
using
block_type
=
mpl::constify_t<typename B::block_type, is_const>
;
57
using
bitset_type
=
mpl::constify_t<B, is_const>
;
58
using
size_type
=
typename
B::size_type;
59
60
constexpr
bitset_iterator
() noexcept = default;
61
constexpr
bitset_iterator
(
bitset_type
* bitset,
size_type
index);
62
63
private:
64
65
constexpr
reference
dereference() const noexcept;
66
constexpr
void
advance(
difference_type
n) noexcept;
67
68
friend class
iterator_access
;
69
};
70
71
template <class B,
bool
is_const>
72
constexpr
bitset_iterator
<B, is_const>::
bitset_iterator
(
bitset_type
* bitset,
size_type
index)
73
:
base_type
(bitset, index)
74
{
75
}
76
77
template
<
class
B,
bool
is_const>
78
constexpr
auto
bitset_iterator<B, is_const>::dereference() const noexcept ->
reference
79
{
80
if
constexpr
(is_const)
81
{
82
return
this->
p_object
->test(this->
m_index
);
83
}
84
else
85
{
86
return
bitset_reference<B>(*this->
p_object
, this->
m_index
);
87
}
88
}
89
90
template
<
class
B,
bool
is_const>
91
constexpr
void
bitset_iterator<B, is_const>::advance
(
difference_type
n)
noexcept
92
{
93
if
(n < 0 &&
static_cast<
size_type
>
(-n) > this->
m_index
)
94
{
95
// Prevent underflow by clamping m_index to 0
96
this->
m_index
= 0;
97
}
98
else
99
{
100
this->
m_index
=
static_cast<
size_type
>
(
static_cast<
difference_type
>
(this->
m_index
) + n);
101
}
102
}
103
}
sparrow::bitset_iterator::reference
typename base_type::reference reference
Definition
bitset_iterator.hpp:53
sparrow::bitset_iterator::bitset_iterator
constexpr bitset_iterator() noexcept=default
sparrow::bitset_iterator::bitset_type
mpl::constify_t< B, is_const > bitset_type
Definition
bitset_iterator.hpp:57
sparrow::bitset_iterator::block_type
mpl::constify_t< typename B::block_type, is_const > block_type
Definition
bitset_iterator.hpp:56
sparrow::bitset_iterator::base_type
pointer_index_iterator_base< self_type, mpl::constify_t< B, is_const >, mpl::constify_t< typename B::value_type, is_const >, std::conditional_t< is_const, bool, bitset_reference< B > >, std::random_access_iterator_tag > base_type
Definition
bitset_iterator.hpp:47
sparrow::bitset_iterator::size_type
typename B::size_type size_type
Definition
bitset_iterator.hpp:58
sparrow::bitset_iterator::self_type
bitset_iterator< B, is_const > self_type
Definition
bitset_iterator.hpp:46
sparrow::bitset_iterator< self_type, false >::iterator_access
friend class iterator_access
Definition
bitset_iterator.hpp:68
sparrow::bitset_iterator::difference_type
typename base_type::difference_type difference_type
Definition
bitset_iterator.hpp:54
sparrow::bitset_reference
A proxy reference class that provides mutable access to individual bits in a bitset.
Definition
bitset_reference.hpp:59
sparrow::pointer_index_iterator_base< bitset_iterator< B, is_const >, mpl::constify_t< B, is_const >, mpl::constify_t< B::value_type, is_const >, std::conditional_t< is_const, bool, bitset_reference< B > >, std::random_access_iterator_tag >::m_index
std::size_t m_index
Definition
iterator.hpp:547
sparrow::pointer_index_iterator_base< bitset_iterator< B, is_const >, mpl::constify_t< B, is_const >, mpl::constify_t< B::value_type, is_const >, std::conditional_t< is_const, bool, bitset_reference< B > >, std::random_access_iterator_tag >::pointer_index_iterator_base
constexpr pointer_index_iterator_base() noexcept=default
sparrow::pointer_index_iterator_base< self_type, mpl::constify_t< B, is_const >, mpl::constify_t< typename B::value_type, is_const >, std::conditional_t< is_const, bool, bitset_reference< B > >, std::random_access_iterator_tag >::difference_type
std::ptrdiff_t difference_type
Definition
iterator.hpp:542
sparrow::pointer_index_iterator_base< bitset_iterator< B, is_const >, mpl::constify_t< B, is_const >, mpl::constify_t< B::value_type, is_const >, std::conditional_t< is_const, bool, bitset_reference< B > >, std::random_access_iterator_tag >::p_object
mpl::constify_t< B, is_const > * p_object
Definition
iterator.hpp:546
contracts.hpp
iterator.hpp
mp_utils.hpp
sparrow::mpl::constify_t
typename constify< T, is_const >::type constify_t
Convenience alias for constify.
Definition
mp_utils.hpp:807
sparrow
Definition
array.hpp:21
sparrow
buffer
dynamic_bitset
bitset_iterator.hpp
Generated by
1.17.0