1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
/** Definitions for the pqxx::result class and support classes.
*
* pqxx::result represents the set of result rows from a database query.
*
* DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/result instead.
*
* Copyright (c) 2000-2019, Jeroen T. Vermeulen.
*
* See COPYING for copyright license. If you did not receive a file called
* COPYING with this source code, please notify the distributor of this mistake,
* or contact the author.
*/
#ifndef PQXX_H_RESULT_ITERATOR
#define PQXX_H_RESULT_ITERATOR
#include "pqxx/compiler-public.hxx"
#include "pqxx/compiler-internal-pre.hxx"
#include "pqxx/row.hxx"
/* Result iterator.
*
* Don't include this header from your own application; it is included for you
* by other libpqxx headers.
*/
namespace pqxx
{
/// Iterator for rows in a result. Use as result::const_iterator.
/** A result, once obtained, cannot be modified. Therefore there is no
* plain iterator type for result. However its const_iterator type can be
* used to inspect its rows without changing them.
*/
class PQXX_LIBEXPORT const_result_iterator : public row
{
public:
using iterator_category = std::random_access_iterator_tag;
using value_type = const row;
using pointer = const row *;
using reference = row;
using size_type = result_size_type;
using difference_type = result_difference_type;
const_result_iterator() noexcept : row{result(), 0} {}
const_result_iterator(const row &t) noexcept : row{t} {}
/**
* @name Dereferencing operators
*/
//@{
/** The iterator "points to" its own row, which is also itself. This
* allows a result to be addressed as a two-dimensional container without
* going through the intermediate step of dereferencing the iterator. I
* hope this works out to be similar to C pointer/array semantics in useful
* cases.
*
* IIRC Alex Stepanov, the inventor of the STL, once remarked that having
* this as standard behaviour for pointers would be useful in some
* algorithms. So even if this makes me look foolish, I would seem to be in
* distinguished company.
*/
pointer operator->() const { return this; } //[t12]
reference operator*() const { return row{*this}; } //[t12]
//@}
/**
* @name Manipulations
*/
//@{
const_result_iterator operator++(int); //[t12]
const_result_iterator &operator++() { ++m_index; return *this; } //[t01]
const_result_iterator operator--(int); //[t12]
const_result_iterator &operator--() { --m_index; return *this; } //[t12]
const_result_iterator &operator+=(difference_type i) //[t12]
{ m_index += i; return *this; }
const_result_iterator &operator-=(difference_type i) //[t12]
{ m_index -= i; return *this; }
//@}
/**
* @name Comparisons
*/
//@{
bool operator==(const const_result_iterator &i) const //[t12]
{return m_index==i.m_index;}
bool operator!=(const const_result_iterator &i) const //[t12]
{return m_index!=i.m_index;}
bool operator<(const const_result_iterator &i) const //[t12]
{return m_index<i.m_index;}
bool operator<=(const const_result_iterator &i) const //[t12]
{return m_index<=i.m_index;}
bool operator>(const const_result_iterator &i) const //[t12]
{return m_index>i.m_index;}
bool operator>=(const const_result_iterator &i) const //[t12]
{return m_index>=i.m_index;}
//@}
/**
* @name Arithmetic operators
*/
//@{
inline const_result_iterator operator+(difference_type) const; //[t12]
friend const_result_iterator operator+( //[t12]
difference_type,
const_result_iterator);
inline const_result_iterator operator-(difference_type) const; //[t12]
inline difference_type operator-(const_result_iterator) const; //[t12]
//@}
private:
friend class pqxx::result;
const_result_iterator(const pqxx::result *r, result_size_type i) noexcept :
row{*r, i} {}
};
/// Reverse iterator for result. Use as result::const_reverse_iterator.
class PQXX_LIBEXPORT const_reverse_result_iterator :
private const_result_iterator
{
public:
using super = const_result_iterator;
using iterator_type = const_result_iterator;
using iterator_type::iterator_category;
using iterator_type::difference_type;
using iterator_type::pointer;
using value_type = iterator_type::value_type;
using reference = iterator_type::reference;
const_reverse_result_iterator( //[t75]
const const_reverse_result_iterator &rhs) :
const_result_iterator{rhs} {}
explicit const_reverse_result_iterator( //[t75]
const const_result_iterator &rhs) :
const_result_iterator{rhs} { super::operator--(); }
PQXX_PURE const_result_iterator base() const noexcept; //[t75]
/**
* @name Dereferencing operators
*/
//@{
using const_result_iterator::operator->; //[t75]
using const_result_iterator::operator*; //[t75]
//@}
/**
* @name Manipulations
*/
//@{
const_reverse_result_iterator &operator=( //[t75]
const const_reverse_result_iterator &r)
{ iterator_type::operator=(r); return *this; }
const_reverse_result_iterator &operator++() //[t75]
{ iterator_type::operator--(); return *this; }
const_reverse_result_iterator operator++(int); //[t75]
const_reverse_result_iterator &operator--() //[t75]
{ iterator_type::operator++(); return *this; }
const_reverse_result_iterator operator--(int); //[t75]
const_reverse_result_iterator &operator+=(difference_type i) //[t75]
{ iterator_type::operator-=(i); return *this; }
const_reverse_result_iterator &operator-=(difference_type i) //[t75]
{ iterator_type::operator+=(i); return *this; }
//@}
/**
* @name Arithmetic operators
*/
//@{
const_reverse_result_iterator operator+(difference_type i) const //[t75]
{ return const_reverse_result_iterator(base() - i); }
const_reverse_result_iterator operator-(difference_type i) //[t75]
{ return const_reverse_result_iterator(base() + i); }
difference_type operator-( //[t75]
const const_reverse_result_iterator &rhs) const
{ return rhs.const_result_iterator::operator-(*this); }
//@}
/**
* @name Comparisons
*/
//@{
bool operator==( //[t75]
const const_reverse_result_iterator &rhs) const noexcept
{ return iterator_type::operator==(rhs); }
bool operator!=( //[t75]
const const_reverse_result_iterator &rhs) const noexcept
{ return not operator==(rhs); }
bool operator<(const const_reverse_result_iterator &rhs) const //[t75]
{ return iterator_type::operator>(rhs); }
bool operator<=(const const_reverse_result_iterator &rhs) const //[t75]
{ return iterator_type::operator>=(rhs); }
bool operator>(const const_reverse_result_iterator &rhs) const //[t75]
{ return iterator_type::operator<(rhs); }
bool operator>=(const const_reverse_result_iterator &rhs) const //[t75]
{ return iterator_type::operator<=(rhs); }
//@}
};
inline const_result_iterator
const_result_iterator::operator+(result::difference_type o) const
{
return const_result_iterator{
&m_result, size_type(result::difference_type(m_index) + o)};
}
inline const_result_iterator
operator+(result::difference_type o, const_result_iterator i)
{ return i + o; }
inline const_result_iterator
const_result_iterator::operator-(result::difference_type o) const
{
return const_result_iterator{
&m_result,
result_size_type(result::difference_type(m_index) - o)};
}
inline result::difference_type
const_result_iterator::operator-(const_result_iterator i) const
{ return result::difference_type(num() - i.num()); }
inline const_result_iterator result::end() const noexcept
{ return const_result_iterator{this, size()}; }
inline const_result_iterator result::cend() const noexcept
{ return end(); }
inline const_reverse_result_iterator
operator+(
result::difference_type n,
const const_reverse_result_iterator &i)
{ return const_reverse_result_iterator{i.base() - n}; }
} // namespace pqxx
#include "pqxx/compiler-internal-post.hxx"
#endif
|