MySQL 8.4.2
Source Code Documentation
buffer_sequence.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2021, 2024, 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_HTTP_SRC_HTTP_CNO_BUFFER_SEQUENCE_H_
27#define ROUTER_SRC_HTTP_SRC_HTTP_CNO_BUFFER_SEQUENCE_H_
28
29#include <iterator>
30#include <vector>
31
32#include "cno/core.h"
34
35namespace http {
36namespace cno {
37
38template <typename ResultType = net::const_buffer>
39class Sequence {
40 public:
42
43 const ResultType *begin() const { return begin_; }
44 const ResultType *end() const { return begin_ + size_; }
45
46 private:
48 size_t size_;
49};
50
51template <typename SourceType = cno_buffer_t,
54 public:
55 class Iterator {
56 public:
57 using iterator_category = std::input_iterator_tag;
59 using difference_type = void;
62
63 public:
64 Iterator(const BufferSequence *parent, size_t index)
65 : parent_{parent}, index_{index} {
67 }
68
69 void operator++() {
70 ++index_;
72 }
73
74 bool operator!=(const Iterator &it) const { return result_ != it.result_; }
75 bool operator==(const Iterator &it) const { return result_ == it.result_; }
77 Iterator operator+(const int value) const {
78 return {parent_, index_ + value};
79 }
81
82 operator value_type() { return result_; }
83
84 size_t left() { return parent_->source_count_ - index_; }
85 const SourceType *get_buffer() { return parent_->source_ + index_; }
86
87 private:
88 void make_result() {
90 if (index_ >= parent_->source_count_) break;
91
92 auto &src = parent_->source_[index_];
93 parent_->destination_[index_] = {src.data, src.size};
94
96 }
97
99 }
100
102 size_t index_;
103 pointer result_{nullptr};
104 };
105
106 BufferSequence(const SourceType *source, size_t source_count)
107 : source_{source}, source_count_{source_count} {
109 }
110
111 const Iterator begin() const { return Iterator(this, 0); }
112 const Iterator end() const { return Iterator(this, source_count_); }
113
114 const SourceType *source_;
115 size_t source_count_{0};
116 mutable std::vector<ResultType> destination_;
118};
119
120} // namespace cno
121} // namespace http
122
123#endif // ROUTER_SRC_HTTP_SRC_HTTP_CNO_BUFFER_SEQUENCE_H_
Definition: buffer_sequence.h:55
void make_result()
Definition: buffer_sequence.h:88
const SourceType * get_buffer()
Definition: buffer_sequence.h:85
bool operator==(const Iterator &it) const
Definition: buffer_sequence.h:75
ResultType value_type
Definition: buffer_sequence.h:58
void difference_type
Definition: buffer_sequence.h:59
const BufferSequence * parent_
Definition: buffer_sequence.h:101
size_t left()
Definition: buffer_sequence.h:84
Iterator operator+(const int value) const
Definition: buffer_sequence.h:77
size_t index_
Definition: buffer_sequence.h:102
bool operator!=(const Iterator &it) const
Definition: buffer_sequence.h:74
pointer result_
Definition: buffer_sequence.h:103
reference operator*()
Definition: buffer_sequence.h:76
void operator++()
Definition: buffer_sequence.h:69
pointer operator->()
Definition: buffer_sequence.h:80
Iterator(const BufferSequence *parent, size_t index)
Definition: buffer_sequence.h:64
std::input_iterator_tag iterator_category
Definition: buffer_sequence.h:57
Definition: buffer_sequence.h:53
BufferSequence(const SourceType *source, size_t source_count)
Definition: buffer_sequence.h:106
size_t source_count_
Definition: buffer_sequence.h:115
const Iterator begin() const
Definition: buffer_sequence.h:111
const SourceType * source_
Definition: buffer_sequence.h:114
size_t destination_initialized_count_
Definition: buffer_sequence.h:117
const Iterator end() const
Definition: buffer_sequence.h:112
std::vector< ResultType > destination_
Definition: buffer_sequence.h:116
Definition: buffer_sequence.h:39
size_t size_
Definition: buffer_sequence.h:48
const ResultType * begin() const
Definition: buffer_sequence.h:43
Sequence(const ResultType *begin, size_t size)
Definition: buffer_sequence.h:41
const ResultType * end() const
Definition: buffer_sequence.h:44
const ResultType * begin_
Definition: buffer_sequence.h:47
Definition: buffer.h:135
ResultType
Type used to differentiate the three cases that can happen when parsing a geometry.
Definition: geometry_extraction.h:42
Definition: connection.h:56
size_t size(const char *const c)
Definition: base64.h:46
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:42