MySQL 8.4.1
Source Code Documentation
iterator.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 2024, 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 ITERATOR_INCLUDED
25#define ITERATOR_INCLUDED
26
27#include "cache.h" /* Datacache */
28
29namespace keyring_common {
30
31namespace iterator {
32template <typename Data_extension>
33class Iterator {
34 public:
35 /** Constructor */
36 Iterator() : it_(), end_(), version_(0), valid_(false), cached_(false) {}
39 : it_(datacache.at(metadata)),
40 end_(datacache.end()),
41 version_(datacache.version()),
42 valid_(it_ != end_),
43 cached_(false) {}
44
46 : it_(datacache.begin()),
47 end_(datacache.end()),
48 version_(datacache.version()),
49 valid_(true),
51 if (cached_) {
52 for (std::pair<meta::Metadata, Data_extension> element : datacache)
53 metadata_.store(element.first, element.second);
54
55 it_ = metadata_.begin();
56 end_ = metadata_.end();
57 }
58 }
59
60 /** Destructor */
61 ~Iterator() { metadata_.clear(); }
62
63 /** Get iterator */
65 return it_;
66 }
67
68 /** Move iterator forward */
69 bool next(size_t version) {
70 if (iterator_valid(version) == false) {
71 it_ = end_;
72 valid_ = false;
73 return false;
74 }
75 it_++;
76 return true;
77 }
78
80 if (iterator_valid(version) == false) {
81 it_ = end_;
82 valid_ = false;
83 return false;
84 }
85 metadata = it_->first;
86 return true;
87 }
88
89 bool data(size_t version, Data_extension &data) {
90 if (iterator_valid(version) == false) {
91 it_ = end_;
92 valid_ = false;
93 return false;
94 }
95 data = it_->second;
96 return true;
97 }
98
99 bool valid(size_t version) {
101 return valid_;
102 }
103
104 private:
105 /** Internal validity checker */
106 inline bool iterator_valid(size_t version) {
107 if (cached_) {
108 return valid_ && (it_ != end_);
109 }
110 return valid_ && (version == version_) && (it_ != end_);
111 }
112
113 private:
114 /** Const Iterator */
116 /** End */
118 /** Iterator version */
119 size_t version_;
120 /** validity of the iterator */
121 bool valid_;
122 /** Iterator type */
124 /** Local copy */
126};
127
128} // namespace iterator
129
130} // namespace keyring_common
131
132#endif // !ITERATOR_INCLUDED
Definition: cache.h:41
Definition: iterator.h:33
cache::Cache< Data_extension >::const_iterator get_iterator() const
Get iterator.
Definition: iterator.h:64
bool valid_
validity of the iterator
Definition: iterator.h:121
cache::Cache< Data_extension >::const_iterator it_
Const Iterator.
Definition: iterator.h:115
bool iterator_valid(size_t version)
Internal validity checker.
Definition: iterator.h:106
bool next(size_t version)
Move iterator forward.
Definition: iterator.h:69
cache::Datacache< Data_extension > metadata_
Local copy.
Definition: iterator.h:125
size_t version_
Iterator version.
Definition: iterator.h:119
Iterator(const cache::Datacache< Data_extension > &datacache, const meta::Metadata &metadata)
Definition: iterator.h:37
cache::Cache< Data_extension >::const_iterator end_
End.
Definition: iterator.h:117
bool metadata(size_t version, meta::Metadata &metadata)
Definition: iterator.h:79
bool data(size_t version, Data_extension &data)
Definition: iterator.h:89
bool cached_
Iterator type.
Definition: iterator.h:123
bool valid(size_t version)
Definition: iterator.h:99
Iterator(const cache::Datacache< Data_extension > &datacache, bool cached)
Definition: iterator.h:45
~Iterator()
Destructor.
Definition: iterator.h:61
Iterator()
Constructor.
Definition: iterator.h:36
Common metadata.
Definition: meta.h:39
std::unordered_map< meta::Metadata, Data_extension, meta::Metadata::Hash > Cache
Definition: cache.h:38
Definition: keyring_encryption_service_definition.h:32
const char * begin(const char *const c)
Definition: base64.h:44
required uint64 version
Definition: replication_group_member_actions.proto:41
static double cached
Definition: xcom_statistics.cc:101