sparrow 0.3.0
Loading...
Searching...
No Matches
variable_size_binary_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 mplied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
20
21namespace sparrow
22{
29 template <class Layout, iterator_types Iterator_types>
31 : public iterator_base<
32 variable_size_binary_value_iterator<Layout, Iterator_types>,
33 typename Iterator_types::value_type,
34 typename Iterator_types::iterator_tag,
35 typename Iterator_types::reference>
36 {
37 public:
38
42 typename Iterator_types::value_type,
43 typename Iterator_types::iterator_tag,
44 typename Iterator_types::reference>;
45 using reference = typename base_type::reference;
46 using difference_type = typename base_type::difference_type;
49 using value_type = base_type::value_type;
50
53
54 private:
55
56 [[nodiscard]] reference dereference() const;
57
58 void increment();
59 void decrement();
60 void advance(difference_type n);
61 [[nodiscard]] difference_type distance_to(const self_type& rhs) const;
62 [[nodiscard]] bool equal(const self_type& rhs) const;
63 [[nodiscard]] bool less_than(const self_type& rhs) const;
64
65 layout_type* p_layout = nullptr;
66 difference_type m_index;
67
68 friend class iterator_access;
69 };
70
71 /******************************************************
72 * variable_size_binary_value_iterator implementation *
73 ******************************************************/
74
75 template <class Layout, iterator_types Iterator_types>
78 size_type index
79 )
80 : p_layout(layout)
81 , m_index(static_cast<difference_type>(index))
82 {
83 }
84
85 template <class Layout, iterator_types Iterator_types>
86 auto variable_size_binary_value_iterator<Layout, Iterator_types>::dereference() const -> reference
87 {
88 if constexpr (std::same_as<reference, typename Layout::inner_const_reference>)
89 {
90 return p_layout->value(static_cast<size_type>(m_index));
91 }
92 else
93 {
94 return reference(const_cast<Layout*>(p_layout), static_cast<size_type>(m_index));
95 }
96 }
97
98 template <class Layout, iterator_types Iterator_types>
100 {
101 ++m_index;
102 }
103
104 template <class Layout, iterator_types Iterator_types>
106 {
107 --m_index;
108 }
109
110 template <class Layout, iterator_types Iterator_types>
112 {
113 m_index += n;
114 }
115
116 template <class Layout, iterator_types Iterator_types>
119 {
120 return rhs.m_index - m_index;
121 }
122
123 template <class Layout, iterator_types Iterator_types>
125 {
126 return (p_layout == rhs.p_layout) && (m_index == rhs.m_index);
127 }
128
129 template <class Layout, iterator_types Iterator_types>
131 {
132 return (p_layout == rhs.p_layout) && (m_index < rhs.m_index);
133 }
134}
variable_size_binary_value_iterator< array_type, Iterator_types > self_type
variable_size_binary_value_iterator() noexcept=default
iterator_base< self_type, typename Iterator_types::value_type, typename Iterator_types::iterator_tag, typename Iterator_types::reference > base_type
Concept for iterator types.
typename constify< T, is_const >::type constify_t
Definition mp_utils.hpp:390