MySQL 9.6.0
Source Code Documentation
nested_set_binary_operation_iterator_base.h
Go to the documentation of this file.
1// Copyright (c) 2025, Oracle and/or its affiliates.
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License, version 2.0,
5// as published by the Free Software Foundation.
6//
7// This program is designed to work with certain software (including
8// but not limited to OpenSSL) that is licensed under separate terms,
9// as designated in a particular file or component or in included license
10// documentation. The authors of MySQL hereby grant you an additional
11// permission to link the program and your derivative works with the
12// separately licensed software that they have either included with
13// the program or referenced in the documentation.
14//
15// This program is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License, version 2.0, for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with this program; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
24#ifndef MYSQL_SETS_NESTED_SET_BINARY_OPERATION_ITERATOR_BASE_H
25#define MYSQL_SETS_NESTED_SET_BINARY_OPERATION_ITERATOR_BASE_H
26
27/// @file
28/// Experimental API header
29
30#include "mysql/iterators/iterator_interface.h" // Iterator_interface
31#include "mysql/sets/base_binary_operation_views.h" // Binary_operation_view_type
32#include "mysql/sets/binary_operation.h" // Binary_operation
33#include "mysql/sets/nested_set_meta.h" // Is_nested_set
34#include "mysql/sets/optional_view_source_set.h" // Optional_view_source_set
35#include "mysql/sets/set_categories_and_traits.h" // Is_compatible_set
36
37/// @addtogroup GroupLibsMysqlSets
38/// @{
39
40namespace mysql::sets::detail {
41
42/// Common base class for the forward iterators over union view, intersection
43/// view, and subtraction view of two nested sets.
44///
45/// @tparam Source1_tp First nested set.
46///
47/// @tparam Source2_tp Second nested set.
48///
49/// @tparam operation_tp The type of operation.
50template <class Self_tp, Is_nested_set Source1_tp, Is_nested_set Source2_tp,
51 Binary_operation operation_tp>
52 requires Is_compatible_set<Source1_tp, Source2_tp>
54 : public mysql::iterators::Iterator_interface<Self_tp> {
55 public:
56 using Source1_t = Source1_tp;
57 using Source2_t = Source2_tp;
60 static constexpr auto operation = operation_tp;
61
62 using Iterator1_t = typename Source1_t::Const_iterator_t;
63 using Iterator2_t = typename Source2_t::Const_iterator_t;
64 using Key_traits_t = typename Source1_tp::Key_traits_t;
65 using Key_t = typename Key_traits_t::Element_t;
66 using Mapped1_t = Source1_t::Mapped_t;
67 using Mapped2_t = Source2_t::Mapped_t;
69 using Value_t = std::pair<const Key_t, Mapped_t>;
70
71 // Default constructor. The resulting iterator is in a "pointless" state,
72 // where the only possible operations are assignment from another iterator,
73 // and comparison.
75
76 // Construct from two sources and one iterator into each of them.
78 const Source2_t *source2,
81 : m_source1(source1),
82 m_source2(source2),
85
86 // Default rule-of-5
88 const Nested_set_binary_operation_iterator_base &other) noexcept =
89 default;
91 Nested_set_binary_operation_iterator_base &&other) noexcept = default;
93 const Nested_set_binary_operation_iterator_base &other) noexcept =
94 default;
96 Nested_set_binary_operation_iterator_base &&other) noexcept = default;
98
99 /// Return const reference to the current iterator into the first set.
100 [[nodiscard]] const auto &iterator1() const { return m_iterator1; }
101
102 /// Return reference to the current iterator into the first set.
103 [[nodiscard]] auto &iterator1() { return m_iterator1; }
104
105 /// Return const reference to the current iterator into the second set.
106 [[nodiscard]] const auto &iterator2() const { return m_iterator2; }
107
108 /// Return reference to the current iterator into the second set.
109 [[nodiscard]] auto &iterator2() { return m_iterator2; }
110
111 protected:
112 /// Return the current value, computed as operation(m_iterator1, m_iterator2).
113 [[nodiscard]] Value_t make_value() const {
114 return Value_t(m_iterator1->first,
115 Mapped_t(m_iterator1->second, m_iterator2->second));
116 }
117
118 /// Return the current value, computed as operation(m_iterator1, nullptr).
119 [[nodiscard]] Value_t make_value1() const {
120 return Value_t(m_iterator1->first, Mapped_t(&m_iterator1->second, nullptr));
121 }
122
123 /// Return the current value, computed as operation(nullptr, m_iterator2).
124 [[nodiscard]] Value_t make_value2() const {
125 return Value_t(m_iterator2->first, Mapped_t(nullptr, &m_iterator2->second));
126 }
127
128 /// The first source.
130
131 /// The second source.
133
134 /// Iterator into the first source.
135 ///
136 /// It is `mutable` because derived classes may be update it lazily.
138
139 /// Iterator into the second source.
140 ///
141 /// It is `mutable` because derived classes may be update it lazily.
143}; // class Nested_set_binary_operation_iterator_base
144
145} // namespace mysql::sets::detail
146
147// addtogroup GroupLibsMysqlSets
148/// @}
149
150#endif // ifndef MYSQL_SETS_NESTED_SET_BINARY_OPERATION_ITERATOR_BASE_H
Experimental API header.
Experimental API header.
CRTP base class (mixin) that makes your class a standard-compliant iterator, given only a minimal set...
Definition: iterator_interface.h:370
Common base class for the forward iterators over union view, intersection view, and subtraction view ...
Definition: nested_set_binary_operation_iterator_base.h:54
auto & iterator2()
Return reference to the current iterator into the second set.
Definition: nested_set_binary_operation_iterator_base.h:109
Source2_tp Source2_t
Definition: nested_set_binary_operation_iterator_base.h:57
Nested_set_binary_operation_iterator_base & operator=(Nested_set_binary_operation_iterator_base &&other) noexcept=default
static constexpr auto operation
Definition: nested_set_binary_operation_iterator_base.h:60
typename Source2_t::Const_iterator_t Iterator2_t
Definition: nested_set_binary_operation_iterator_base.h:63
Nested_set_binary_operation_iterator_base(const Source1_t *source1, const Source2_t *source2, const Iterator1_t &iterator1, const Iterator2_t &iterator2)
Definition: nested_set_binary_operation_iterator_base.h:77
Binary_operation_view_type< operation, Mapped1_t, Mapped2_t > Mapped_t
Definition: nested_set_binary_operation_iterator_base.h:68
typename Source1_tp::Key_traits_t Key_traits_t
Definition: nested_set_binary_operation_iterator_base.h:64
Value_t make_value2() const
Return the current value, computed as operation(nullptr, m_iterator2).
Definition: nested_set_binary_operation_iterator_base.h:124
Source2_t::Mapped_t Mapped2_t
Definition: nested_set_binary_operation_iterator_base.h:67
std::pair< const Key_t, Mapped_t > Value_t
Definition: nested_set_binary_operation_iterator_base.h:69
Value_t make_value1() const
Return the current value, computed as operation(m_iterator1, nullptr).
Definition: nested_set_binary_operation_iterator_base.h:119
Nested_set_binary_operation_iterator_base(const Nested_set_binary_operation_iterator_base &other) noexcept=default
Iterator1_t m_iterator1
Iterator into the first source.
Definition: nested_set_binary_operation_iterator_base.h:137
Source1_tp Source1_t
Definition: nested_set_binary_operation_iterator_base.h:56
Iterator2_t m_iterator2
Iterator into the second source.
Definition: nested_set_binary_operation_iterator_base.h:142
Nested_set_binary_operation_iterator_base(Nested_set_binary_operation_iterator_base &&other) noexcept=default
typename Key_traits_t::Element_t Key_t
Definition: nested_set_binary_operation_iterator_base.h:65
Opt_source1_t m_source1
The first source.
Definition: nested_set_binary_operation_iterator_base.h:129
const auto & iterator2() const
Return const reference to the current iterator into the second set.
Definition: nested_set_binary_operation_iterator_base.h:106
Opt_source2_t m_source2
The second source.
Definition: nested_set_binary_operation_iterator_base.h:132
typename Source1_t::Const_iterator_t Iterator1_t
Definition: nested_set_binary_operation_iterator_base.h:62
auto & iterator1()
Return reference to the current iterator into the first set.
Definition: nested_set_binary_operation_iterator_base.h:103
Value_t make_value() const
Return the current value, computed as operation(m_iterator1, m_iterator2).
Definition: nested_set_binary_operation_iterator_base.h:113
Nested_set_binary_operation_iterator_base & operator=(const Nested_set_binary_operation_iterator_base &other) noexcept=default
const auto & iterator1() const
Return const reference to the current iterator into the first set.
Definition: nested_set_binary_operation_iterator_base.h:100
Source1_t::Mapped_t Mapped1_t
Definition: nested_set_binary_operation_iterator_base.h:66
Experimental API header.
Definition: aliases.h:97
Binary_operation
Identifies the type of a binary operation.
Definition: binary_operation.h:37
std::conditional_t<(int) binary_operation==(int) Binary_operation::op_union, Union_view< Source1_t, Source2_t >, std::conditional_t<(int) binary_operation==(int) Binary_operation::op_intersection, Intersection_view< Source1_t, Source2_t >, std::conditional_t<(int) binary_operation==(int) Binary_operation::op_subtraction, Subtraction_view< Source1_t, Source2_t >, void > > > Binary_operation_view_type
For a Binary_operation and two operand sets, gives the corresponding Union_view, Intersection_view,...
Definition: base_binary_operation_views.h:91
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
Experimental API header.
Experimental API header.
Experimental API header.