MySQL 8.0.30
Source Code Documentation
visible_fields.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2020, 2022, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
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 SQL_VISIBLE_FIELDS_H
25#define SQL_VISIBLE_FIELDS_H
26
27/**
28 @file
29 An adapter class to support iteration over an iterator of Item *
30 (typically mem_root_deque<Item *>), while skipping over items that
31 are hidden (item->hidden == true). This is such a common operation
32 that it warrants having its own adapter. You can either do
33
34 for (Item *item : VisibleFields(fields))
35
36 or use select->visible_fields().
37
38 Behavior is undefined if you modify the hidden flag of an item during
39 iteration.
40
41 TODO(sgunders): When we get C++20, replace with an std::views::filter.
42 */
43
44#include "mem_root_deque.h"
45#include "sql/item.h"
46
47template <class Iterator>
49 public:
50 VisibleFieldsAdapter(Iterator base, Iterator end) : m_it(base), m_end(end) {
51 while (m_it != m_end && (*m_it)->hidden) {
52 ++m_it;
53 }
54 }
55
56 // Pre-increment.
58 do {
59 ++m_it;
60 } while (m_it != m_end && (*m_it)->hidden);
61 return *this;
62 }
63
64 // Post-increment.
66 VisibleFieldsAdapter ret = *this;
67 do {
68 m_it++;
69 } while (m_it != m_end && (*m_it)->hidden);
70 return ret;
71 }
72
73 auto &operator*() const { return *m_it; }
74
75 bool operator==(const VisibleFieldsAdapter &other) const {
76 return m_it == other.m_it;
77 }
78 bool operator!=(const VisibleFieldsAdapter &other) const {
79 return m_it != other.m_it;
80 }
81
82 private:
83 Iterator m_it, m_end;
84};
85
86template <class Container, class Iterator>
88 public:
89 explicit VisibleFieldsContainer(Container &fields) : m_fields(fields) {}
92 }
95 }
96
97 private:
98 Container &m_fields;
99};
100
104}
105
106inline auto VisibleFields(const mem_root_deque<Item *> &fields) {
109}
110
111#endif // SQL_VISIBLE_FIELDS_H
Definition: visible_fields.h:48
VisibleFieldsAdapter & operator++()
Definition: visible_fields.h:57
Iterator m_it
Definition: visible_fields.h:83
VisibleFieldsAdapter operator++(int)
Definition: visible_fields.h:65
bool operator==(const VisibleFieldsAdapter &other) const
Definition: visible_fields.h:75
bool operator!=(const VisibleFieldsAdapter &other) const
Definition: visible_fields.h:78
Iterator m_end
Definition: visible_fields.h:83
VisibleFieldsAdapter(Iterator base, Iterator end)
Definition: visible_fields.h:50
auto & operator*() const
Definition: visible_fields.h:73
Definition: visible_fields.h:87
VisibleFieldsContainer(Container &fields)
Definition: visible_fields.h:89
VisibleFieldsAdapter< Iterator > begin()
Definition: visible_fields.h:90
Container & m_fields
Definition: visible_fields.h:98
VisibleFieldsAdapter< Iterator > end()
Definition: visible_fields.h:93
Definition: mem_root_deque.h:286
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:109
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:191
auto VisibleFields(mem_root_deque< Item * > &fields)
Definition: visible_fields.h:101