sparrow 0.9.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;
48 using size_type = size_t;
49 using value_type = base_type::value_type;
50
51 constexpr variable_size_binary_value_iterator() noexcept = default;
53
54 private:
55
56 [[nodiscard]] constexpr reference dereference() const;
57
58 constexpr void increment() noexcept;
59 constexpr void decrement() noexcept;
60 constexpr void advance(difference_type n) noexcept;
61 [[nodiscard]] constexpr difference_type distance_to(const self_type& rhs) const noexcept;
62 [[nodiscard]] constexpr bool equal(const self_type& rhs) const noexcept;
63 [[nodiscard]] constexpr bool less_than(const self_type& rhs) const noexcept;
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 constexpr 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>
111 constexpr void
113 {
114 m_index += n;
115 }
116
117 template <class Layout, iterator_types Iterator_types>
118 constexpr auto
121 {
122 return rhs.m_index - m_index;
123 }
124
125 template <class Layout, iterator_types Iterator_types>
126 constexpr bool
128 {
129 return (p_layout == rhs.p_layout) && (m_index == rhs.m_index);
130 }
131
132 template <class Layout, iterator_types Iterator_types>
133 constexpr bool
135 {
136 return (p_layout == rhs.p_layout) && (m_index < rhs.m_index);
137 }
138}
variable_size_binary_value_iterator< Layout, Iterator_types > self_type
iterator_base< self_type, typename Iterator_types::value_type, typename Iterator_types::iterator_tag, typename Iterator_types::reference > base_type
constexpr variable_size_binary_value_iterator() noexcept=default
Concept for iterator types.
Concept for layouts.
typename constify< T, is_const >::type constify_t
Convenience alias for constify.
Definition mp_utils.hpp:807