MySQL 9.3.0
Source Code Documentation
rapid_json_iterator.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 2025, 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 designed to work 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 either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTER_SRC_REST_MRS_SRC_HELPER_JSON_RAPID_JSON_INTERATOR_H_
27#define ROUTER_SRC_REST_MRS_SRC_HELPER_JSON_RAPID_JSON_INTERATOR_H_
28
29#include <utility>
30
31#ifdef RAPIDJSON_NO_SIZETYPEDEFINE
32#include "my_rapidjson_size_t.h"
33#endif
34
35#include <rapidjson/document.h>
36
37namespace helper {
38
39namespace json {
40
41template <typename Object = rapidjson::Document::ConstObject,
42 typename Holder = Object *>
44 public:
45 using Value = rapidjson::Document::ValueType;
46 using MemberIterator = typename Object::ConstMemberIterator;
47 using Pair = std::pair<const char *, const Value *>;
48
49 class It {
50 public:
51 It(MemberIterator it) : it_{it} {}
52
54 ++it_;
55 return *this;
56 }
57 auto operator*() { return Pair(it_->name.GetString(), &it_->value); }
58 bool operator!=(const It &other) { return it_ != other.it_; }
59
60 private:
62 };
63
64 public:
65 IterableObject(Holder object) : obj_{object} {}
66
67 It begin() { return It{obj_->MemberBegin()}; }
68 It end() { return It{obj_->MemberEnd()}; }
69
70 Holder obj_;
71};
72
73template <typename Array = rapidjson::Document::ConstArray,
74 typename Holder = Array *,
75 typename Iterator = typename Array::ValueIterator>
77 public:
78 using Value = rapidjson::Document::ValueType;
79
80 public:
81 IterableArray(Holder a) : arr_{a} {}
82
83 Iterator begin() { return arr_->Begin(); }
84 Iterator end() { return arr_->End(); }
85
86 Holder arr_;
87};
88
89template <typename Obj>
90auto member_iterator(Obj &o) {
91 return IterableObject<Obj>(&o);
92}
93
94inline auto array_iterator(const rapidjson::Value::ConstArray &o) {
95 return IterableArray<const rapidjson::Value::ConstArray,
96 const rapidjson::Value::ConstArray *,
97 rapidjson::Value::ConstArray::ConstValueIterator>(&o);
98}
99
102 rapidjson::Value::Array::ValueIterator>(&o);
103}
104
105} // namespace json
106
107} // namespace helper
108
109#endif // ROUTER_SRC_REST_MRS_SRC_HELPER_JSON_RAPID_JSON_INTERATOR_H_
Definition: rapid_json_iterator.h:76
Iterator end()
Definition: rapid_json_iterator.h:84
rapidjson::Document::ValueType Value
Definition: rapid_json_iterator.h:78
Iterator begin()
Definition: rapid_json_iterator.h:83
Holder arr_
Definition: rapid_json_iterator.h:86
IterableArray(Holder a)
Definition: rapid_json_iterator.h:81
Definition: rapid_json_iterator.h:49
MemberIterator it_
Definition: rapid_json_iterator.h:61
It & operator++()
Definition: rapid_json_iterator.h:53
auto operator*()
Definition: rapid_json_iterator.h:57
bool operator!=(const It &other)
Definition: rapid_json_iterator.h:58
It(MemberIterator it)
Definition: rapid_json_iterator.h:51
Definition: rapid_json_iterator.h:43
typename Object::ConstMemberIterator MemberIterator
Definition: rapid_json_iterator.h:46
IterableObject(Holder object)
Definition: rapid_json_iterator.h:65
It end()
Definition: rapid_json_iterator.h:68
Holder obj_
Definition: rapid_json_iterator.h:70
It begin()
Definition: rapid_json_iterator.h:67
std::pair< const char *, const Value * > Pair
Definition: rapid_json_iterator.h:47
rapidjson::Document::ValueType Value
Definition: rapid_json_iterator.h:45
Define rapidjson::SizeType to be std::uint64_t.
MysqlCacheManager::Object Object
Definition: mysql_cache_manager.cc:101
auto array_iterator(const rapidjson::Value::ConstArray &o)
Definition: rapid_json_iterator.h:94
auto member_iterator(Obj &o)
Definition: rapid_json_iterator.h:90
Definition: cache.h:33
@ Array
C++ Object.
Definition: jit_executor_value.h:67