libpqxx
result_iterator.hxx
1 
13 #ifndef PQXX_H_RESULT_ITERATOR
14 #define PQXX_H_RESULT_ITERATOR
15 
16 #include "pqxx/compiler-public.hxx"
17 #include "pqxx/compiler-internal-pre.hxx"
18 
19 #include "pqxx/row.hxx"
20 
21 
22 /* Result iterator.
23  *
24  * Don't include this header from your own application; it is included for you
25  * by other libpqxx headers.
26  */
27 
28 namespace pqxx
29 {
31 
35 class PQXX_LIBEXPORT const_result_iterator : public row
36 {
37 public:
38  using iterator_category = std::random_access_iterator_tag;
39  using value_type = const row;
40  using pointer = const row *;
41  using reference = row;
44 
45  const_result_iterator() noexcept : row{result(), 0} {}
46  const_result_iterator(const row &t) noexcept : row{t} {}
47 
63  pointer operator->() const { return this; } //[t12]
64  reference operator*() const { return row{*this}; } //[t12]
66 
71  const_result_iterator operator++(int); //[t12]
72  const_result_iterator &operator++() { ++m_index; return *this; } //[t01]
73  const_result_iterator operator--(int); //[t12]
74  const_result_iterator &operator--() { --m_index; return *this; } //[t12]
75 
77  { m_index += i; return *this; }
79  { m_index -= i; return *this; }
81 
86  bool operator==(const const_result_iterator &i) const //[t12]
87  {return m_index==i.m_index;}
88  bool operator!=(const const_result_iterator &i) const //[t12]
89  {return m_index!=i.m_index;}
90  bool operator<(const const_result_iterator &i) const //[t12]
91  {return m_index<i.m_index;}
92  bool operator<=(const const_result_iterator &i) const //[t12]
93  {return m_index<=i.m_index;}
94  bool operator>(const const_result_iterator &i) const //[t12]
95  {return m_index>i.m_index;}
96  bool operator>=(const const_result_iterator &i) const //[t12]
97  {return m_index>=i.m_index;}
99 
104  inline const_result_iterator operator+(difference_type) const; //[t12]
105  friend const_result_iterator operator+( //[t12]
108  inline const_result_iterator operator-(difference_type) const; //[t12]
109  inline difference_type operator-(const_result_iterator) const; //[t12]
111 
112 private:
113  friend class pqxx::result;
114  const_result_iterator(const pqxx::result *r, result_size_type i) noexcept :
115  row{*r, i} {}
116 };
117 
118 
120 class PQXX_LIBEXPORT const_reverse_result_iterator :
121  private const_result_iterator
122 {
123 public:
131 
133  const const_reverse_result_iterator &rhs) :
134  const_result_iterator{rhs} {}
136  const const_result_iterator &rhs) :
137  const_result_iterator{rhs} { super::operator--(); }
138 
139  PQXX_PURE const_result_iterator base() const noexcept; //[t75]
140 
145  using const_result_iterator::operator->; //[t75]
146  using const_result_iterator::operator*; //[t75]
148 
155  { iterator_type::operator=(r); return *this; }
157  { iterator_type::operator--(); return *this; }
158  const_reverse_result_iterator operator++(int); //[t75]
160  { iterator_type::operator++(); return *this; }
161  const_reverse_result_iterator operator--(int); //[t75]
163  { iterator_type::operator-=(i); return *this; }
165  { iterator_type::operator+=(i); return *this; }
167 
173  { return const_reverse_result_iterator(base() - i); }
175  { return const_reverse_result_iterator(base() + i); }
177  const const_reverse_result_iterator &rhs) const
178  { return rhs.const_result_iterator::operator-(*this); }
180 
185  bool operator==( //[t75]
186  const const_reverse_result_iterator &rhs) const noexcept
187  { return iterator_type::operator==(rhs); }
188  bool operator!=( //[t75]
189  const const_reverse_result_iterator &rhs) const noexcept
190  { return not operator==(rhs); }
191 
192  bool operator<(const const_reverse_result_iterator &rhs) const //[t75]
193  { return iterator_type::operator>(rhs); }
194  bool operator<=(const const_reverse_result_iterator &rhs) const //[t75]
195  { return iterator_type::operator>=(rhs); }
196  bool operator>(const const_reverse_result_iterator &rhs) const //[t75]
197  { return iterator_type::operator<(rhs); }
198  bool operator>=(const const_reverse_result_iterator &rhs) const //[t75]
199  { return iterator_type::operator<=(rhs); }
201 };
202 
203 
206 {
207  return const_result_iterator{
208  &m_result, size_type(result::difference_type(m_index) + o)};
209 }
210 
213  { return i + o; }
214 
217 {
218  return const_result_iterator{
219  &m_result,
221 }
222 
225  { return result::difference_type(num() - i.num()); }
226 
227 inline const_result_iterator result::end() const noexcept
228  { return const_result_iterator{this, size()}; }
229 
230 
231 inline const_result_iterator result::cend() const noexcept
232  { return end(); }
233 
234 
239  { return const_reverse_result_iterator{i.base() - n}; }
240 
241 } // namespace pqxx
242 
243 #include "pqxx/compiler-internal-post.hxx"
244 
245 #endif
bool operator!=(const const_reverse_result_iterator &rhs) const noexcept
Definition: result_iterator.hxx:188
Reference to one row in a result.
Definition: row.hxx:40
bool operator==(const const_reverse_result_iterator &rhs) const noexcept
Definition: result_iterator.hxx:185
const_iterator end() const noexcept
Definition: result_iterator.hxx:227
bool operator>=(const const_result_iterator &i) const
Definition: result_iterator.hxx:96
bool operator>=(const const_reverse_result_iterator &rhs) const
Definition: result_iterator.hxx:198
const_reverse_result_iterator operator-(difference_type i)
Definition: result_iterator.hxx:174
signed long result_difference_type
Difference between result sizes.
Definition: types.hxx:21
Reverse iterator for result. Use as result::const_reverse_iterator.
Definition: result_iterator.hxx:120
bool operator>(const const_reverse_result_iterator &rhs) const
Definition: result_iterator.hxx:196
unsigned long result_size_type
Number of rows in a result set.
Definition: types.hxx:18
bool operator<=(const const_reverse_result_iterator &rhs) const
Definition: result_iterator.hxx:194
const_reverse_result_iterator(const const_result_iterator &rhs)
Definition: result_iterator.hxx:135
const_result_iterator operator+(difference_type) const
Definition: result_iterator.hxx:205
bool operator<=(const const_result_iterator &i) const
Definition: result_iterator.hxx:92
Iterator for rows in a result. Use as result::const_iterator.
Definition: result_iterator.hxx:35
difference_type operator-(const const_reverse_result_iterator &rhs) const
Definition: result_iterator.hxx:176
const_iterator cend() const noexcept
Definition: result_iterator.hxx:231
const_result_iterator & operator-=(difference_type i)
Definition: result_iterator.hxx:78
result_difference_type difference_type
Definition: result_iterator.hxx:43
const_result_iterator operator-(difference_type) const
Definition: result_iterator.hxx:216
const_reverse_result_iterator & operator=(const const_reverse_result_iterator &r)
Definition: result_iterator.hxx:153
pointer operator->() const
Definition: result_iterator.hxx:63
const_reverse_result_iterator & operator+=(difference_type i)
Definition: result_iterator.hxx:162
bool operator<(const const_reverse_result_iterator &rhs) const
Definition: result_iterator.hxx:192
bool operator!=(const const_result_iterator &i) const
Definition: result_iterator.hxx:88
bool operator==(const const_result_iterator &i) const
Definition: result_iterator.hxx:86
const_reverse_result_iterator & operator--()
Definition: result_iterator.hxx:159
size_t num() const
Definition: row.hxx:170
const_reverse_result_iterator & operator-=(difference_type i)
Definition: result_iterator.hxx:164
const_reverse_result_iterator operator+(difference_type i) const
Definition: result_iterator.hxx:172
const_reverse_result_iterator(const const_reverse_result_iterator &rhs)
Definition: result_iterator.hxx:132
const_result_iterator(const row &t) noexcept
Definition: result_iterator.hxx:46
bool operator<(const const_result_iterator &i) const
Definition: result_iterator.hxx:90
reference operator*() const
Definition: result_iterator.hxx:64
const_result_iterator & operator++()
Definition: result_iterator.hxx:72
result_size_type size_type
Definition: result_iterator.hxx:42
result_difference_type difference_type
Definition: result.hxx:73
bool operator>(const const_result_iterator &i) const
Definition: result_iterator.hxx:94
const_result_iterator & operator+=(difference_type i)
Definition: result_iterator.hxx:76
const_result_iterator() noexcept
Definition: result_iterator.hxx:45
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
const_result_iterator & operator--()
Definition: result_iterator.hxx:74
const_reverse_result_iterator & operator++()
Definition: result_iterator.hxx:156
Result set containing data returned by a query or command.
Definition: result.hxx:69
PQXX_PURE const_result_iterator base() const noexcept
Definition: result.cxx:422
std::random_access_iterator_tag iterator_category
Definition: result_iterator.hxx:38
const_result_iterator operator+(result::difference_type o, const_result_iterator i)
Definition: result_iterator.hxx:212