drogon
C++14/17-based HTTP application framework
Loading...
Searching...
No Matches
ResultIterator.h
1
14
15// Taken from libpqxx and modified.
16// The license for libpqxx can be found in the COPYING file.
17
18#pragma once
19
20#include <drogon/orm/Result.h>
21#include <drogon/orm/Row.h>
22
23namespace drogon
24{
25namespace orm
26{
27class ConstResultIterator : protected Row
28{
29 public:
30 using iterator_category = std::random_access_iterator_tag;
31 using pointer = const Row *;
32 using reference = const Row &;
33 using value_type = const Row;
34 using size_type = Result::SizeType;
35 using difference_type = Result::DifferenceType;
36
37 // ConstResultIterator(const Row &t) noexcept : Row(t) {}
38
39 pointer operator->()
40 {
41 return this;
42 }
43
44 reference operator*()
45 {
46 return *this;
47 }
48
49 ConstResultIterator operator++(int);
50
51 ConstResultIterator &operator++()
52 {
53 ++index_;
54 return *this;
55 }
56
57 ConstResultIterator operator--(int);
58
59 ConstResultIterator &operator--()
60 {
61 --index_;
62 return *this;
63 }
64
65 ConstResultIterator &operator+=(difference_type i)
66 {
67 index_ += i;
68 return *this;
69 }
70
71 ConstResultIterator &operator-=(difference_type i)
72 {
73 index_ -= i;
74 return *this;
75 }
76
77 bool operator==(const ConstResultIterator &other) const
78 {
79 return index_ == other.index_;
80 }
81
82 bool operator!=(const ConstResultIterator &other) const
83 {
84 return index_ != other.index_;
85 }
86
87 bool operator>(const ConstResultIterator &other) const
88 {
89 return index_ > other.index_;
90 }
91
92 bool operator<(const ConstResultIterator &other) const
93 {
94 return index_ < other.index_;
95 }
96
97 bool operator>=(const ConstResultIterator &other) const
98 {
99 return index_ >= other.index_;
100 }
101
102 bool operator<=(const ConstResultIterator &other) const
103 {
104 return index_ <= other.index_;
105 }
106
107 ConstResultIterator(const ConstResultIterator &) noexcept = default;
108 ConstResultIterator(ConstResultIterator &&) noexcept = default;
109
110 private:
111 friend class Result;
112
113 ConstResultIterator(const Result &r, SizeType index) noexcept
114 : Row(r, index)
115 {
116 }
117};
118
119class ConstReverseResultIterator : private ConstResultIterator
120{
121 public:
122 using super = ConstResultIterator;
123 using iterator_type = ConstResultIterator;
124 using iterator_type::difference_type;
125 using iterator_type::iterator_category;
126 using iterator_type::pointer;
127 using iterator_type::reference;
128
129 // using iterator_type::value_type;
130
131 ConstReverseResultIterator(const ConstReverseResultIterator &rhs)
132 : ConstResultIterator(rhs)
133 {
134 }
135
136 explicit ConstReverseResultIterator(const ConstResultIterator &rhs)
137 : ConstResultIterator(rhs)
138 {
139 super::operator--();
140 }
141
142 ConstResultIterator base() const noexcept;
143
144 using iterator_type::operator->;
145 using iterator_type::operator*;
146
147 ConstReverseResultIterator operator++(int);
148
149 ConstReverseResultIterator &operator++()
150 {
151 iterator_type::operator--();
152 return *this;
153 }
154
155 ConstReverseResultIterator operator--(int);
156
157 ConstReverseResultIterator &operator--()
158 {
159 iterator_type::operator++();
160 return *this;
161 }
162
163 ConstReverseResultIterator &operator+=(difference_type i)
164 {
165 iterator_type::operator-=(i);
166 return *this;
167 }
168
169 ConstReverseResultIterator &operator-=(difference_type i)
170 {
171 iterator_type::operator+=(i);
172 return *this;
173 }
174
175 bool operator==(const ConstReverseResultIterator &other) const
176 {
177 return index_ == other.index_;
178 }
179
180 bool operator!=(const ConstReverseResultIterator &other) const
181 {
182 return index_ != other.index_;
183 }
184
185 bool operator>(const ConstReverseResultIterator &other) const
186 {
187 return index_ < other.index_;
188 }
189
190 bool operator<(const ConstReverseResultIterator &other) const
191 {
192 return index_ > other.index_;
193 }
194
195 bool operator>=(const ConstReverseResultIterator &other) const
196 {
197 return index_ <= other.index_;
198 }
199
200 bool operator<=(const ConstReverseResultIterator &other) const
201 {
202 return index_ >= other.index_;
203 }
204};
205
206} // namespace orm
207} // namespace drogon
long index_
Definition Row.h:101
Drogon Test is a minimal effort test framework developed because the major C++ test frameworks doesn'...
Definition Attribute.h:23