Loading...
Searching...
No Matches
result_iterator.hxx
/* 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-2024, 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/row.hxx"
/* Result iterator.
*
* Don't include this header from your own application; it is included for you
* by other libpqxx headers.
*/
namespace pqxx
{
class PQXX_LIBEXPORT const_result_iterator : public row
{
public:
// TODO: Change operator[] so this becomes a proper random_access_iterator.
using iterator_category = std::bidirectional_iterator_tag;
using value_type = row const;
using pointer = row const *;
using reference = row;
using size_type = result_size_type;
using difference_type = result_difference_type;
#include "pqxx/internal/ignore-deprecated-pre.hxx"
const_result_iterator() noexcept = default;
const_result_iterator(const_result_iterator const &) noexcept = default;
const_result_iterator(const_result_iterator &&) noexcept = default;
const_result_iterator(row const &t) noexcept : row{t} {}
#include "pqxx/internal/ignore-deprecated-post.hxx"
[[nodiscard]] pointer operator->() const { return this; }
#include "pqxx/internal/ignore-deprecated-pre.hxx"
[[nodiscard]] reference operator*() const { return *this; }
#include "pqxx/internal/ignore-deprecated-post.hxx"
using row::back;
using row::front;
// TODO: Replace with standard operator[]: i[n] == *(i + n).
using row::operator[];
using row::at;
using row::rownumber;
const_result_iterator &operator=(const_result_iterator const &rhs)
{
#include "pqxx/internal/ignore-deprecated-pre.hxx"
row::operator=(rhs);
#include "pqxx/internal/ignore-deprecated-post.hxx"
return *this;
}
const_result_iterator &operator=(const_result_iterator &&rhs)
{
#include "pqxx/internal/ignore-deprecated-pre.hxx"
row::operator=(std::move(rhs));
#include "pqxx/internal/ignore-deprecated-post.hxx"
return *this;
}
const_result_iterator operator++(int) &;
const_result_iterator &operator++()
{
++m_index;
return *this;
}
const_result_iterator operator--(int) &;
const_result_iterator &operator--()
{
--m_index;
return *this;
}
const_result_iterator &operator+=(difference_type i)
{
m_index += i;
return *this;
}
const_result_iterator &operator-=(difference_type i)
{
m_index -= i;
return *this;
}
void swap(const_result_iterator &other) noexcept
{
#include "pqxx/internal/ignore-deprecated-pre.hxx"
row::swap(other);
#include "pqxx/internal/ignore-deprecated-post.hxx"
}
[[nodiscard]] bool operator==(const_result_iterator const &i) const
{
return m_index == i.m_index;
}
[[nodiscard]] bool operator!=(const_result_iterator const &i) const
{
return m_index != i.m_index;
}
[[nodiscard]] bool operator<(const_result_iterator const &i) const
{
return m_index < i.m_index;
}
[[nodiscard]] bool operator<=(const_result_iterator const &i) const
{
return m_index <= i.m_index;
}
[[nodiscard]] bool operator>(const_result_iterator const &i) const
{
return m_index > i.m_index;
}
[[nodiscard]] bool operator>=(const_result_iterator const &i) const
{
return m_index >= i.m_index;
}
[[nodiscard]] inline const_result_iterator operator+(difference_type) const;
friend const_result_iterator
operator+(difference_type, const_result_iterator const &);
[[nodiscard]] inline const_result_iterator operator-(difference_type) const;
[[nodiscard]] inline difference_type
operator-(const_result_iterator const &) const;
private:
friend class pqxx::result;
const_result_iterator(pqxx::result const *r, result_size_type i) noexcept :
row{*r, i, r->columns()}
{}
};
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::difference_type;
using iterator_type::iterator_category;
using iterator_type::pointer;
using value_type = iterator_type::value_type;
using reference = iterator_type::reference;
const_reverse_result_iterator() = default;
const_reverse_result_iterator(const_reverse_result_iterator const &rhs) =
default;
explicit const_reverse_result_iterator(const_result_iterator const &rhs) :
const_result_iterator{rhs}
{
super::operator--();
}
explicit const_reverse_result_iterator(const_result_iterator const &&rhs) :
const_result_iterator{std::move(rhs)}
{
super::operator--();
}
[[nodiscard]] PQXX_PURE const_result_iterator base() const noexcept;
using const_result_iterator::operator->;
using const_result_iterator::operator*;
using const_result_iterator::back;
using const_result_iterator::front;
// TODO: Replace with standard operator[]: i[n] == *(i + n).
using const_result_iterator::operator[];
using const_result_iterator::at;
using const_result_iterator::rownumber;
const_reverse_result_iterator &
operator=(const_reverse_result_iterator const &r)
{
iterator_type::operator=(r);
return *this;
}
const_reverse_result_iterator &operator=(const_reverse_result_iterator &&r)
{
iterator_type::operator=(std::move(r));
return *this;
}
const_reverse_result_iterator &operator++()
{
iterator_type::operator--();
return *this;
}
const_reverse_result_iterator operator++(int) &;
const_reverse_result_iterator &operator--()
{
iterator_type::operator++();
return *this;
}
const_reverse_result_iterator operator--(int) &;
const_reverse_result_iterator &operator+=(difference_type i)
{
iterator_type::operator-=(i);
return *this;
}
const_reverse_result_iterator &operator-=(difference_type i)
{
iterator_type::operator+=(i);
return *this;
}
void swap(const_reverse_result_iterator &other) noexcept
{
const_result_iterator::swap(other);
}
[[nodiscard]] const_reverse_result_iterator
operator+(difference_type i) const
{
return const_reverse_result_iterator(base() - i);
}
[[nodiscard]] const_reverse_result_iterator operator-(difference_type i)
{
return const_reverse_result_iterator(base() + i);
}
[[nodiscard]] difference_type
operator-(const_reverse_result_iterator const &rhs) const
{
return rhs.const_result_iterator::operator-(*this);
}
[[nodiscard]] bool
operator==(const_reverse_result_iterator const &rhs) const noexcept
{
return iterator_type::operator==(rhs);
}
[[nodiscard]] bool
operator!=(const_reverse_result_iterator const &rhs) const noexcept
{
return not operator==(rhs);
}
[[nodiscard]] bool operator<(const_reverse_result_iterator const &rhs) const
{
return iterator_type::operator>(rhs);
}
[[nodiscard]] bool operator<=(const_reverse_result_iterator const &rhs) const
{
return iterator_type::operator>=(rhs);
}
[[nodiscard]] bool operator>(const_reverse_result_iterator const &rhs) const
{
return iterator_type::operator<(rhs);
}
[[nodiscard]] bool operator>=(const_reverse_result_iterator const &rhs) const
{
return iterator_type::operator<=(rhs);
}
};
inline const_result_iterator
const_result_iterator::operator+(result::difference_type o) const
{
return {&m_result, size_type(result::difference_type(m_index) + o)};
}
inline const_result_iterator
operator+(result::difference_type o, const_result_iterator const &i)
{
return i + o;
}
inline const_result_iterator
const_result_iterator::operator-(result::difference_type o) const
{
return {&m_result, result_size_type(result::difference_type(m_index) - o)};
}
inline result::difference_type
const_result_iterator::operator-(const const_result_iterator &i) const
{
return result::difference_type(num() - i.num());
}
inline const_result_iterator result::end() const noexcept
{
return {this, size()};
}
inline const_result_iterator result::cend() const noexcept
{
return end();
}
inline const_reverse_result_iterator
operator+(result::difference_type n, const_reverse_result_iterator const &i)
{
return const_reverse_result_iterator{i.base() - n};
}
} // namespace pqxx
#endif
pqxx::const_result_iterator
Iterator for rows in a result. Use as result::const_iterator.
Definition result_iterator.hxx:33
pqxx::const_result_iterator::swap
void swap(const_result_iterator &other) noexcept
Interchange two iterators in an exception-safe manner.
Definition result_iterator.hxx:135
pqxx::const_result_iterator::operator->
pointer operator->() const
Dereference the iterator.
Definition result_iterator.hxx:70
pqxx::const_result_iterator::const_result_iterator
const_result_iterator() noexcept=default
Create an iterator, but in an unusable state.
pqxx::const_result_iterator::operator*
reference operator*() const
Dereference the iterator.
Definition result_iterator.hxx:74
pqxx::const_reverse_result_iterator
Reverse iterator for result. Use as result::const_reverse_iterator.
Definition result_iterator.hxx:196
pqxx::const_reverse_result_iterator::const_reverse_result_iterator
const_reverse_result_iterator(const_reverse_result_iterator const &rhs)=default
Copy an iterator.
pqxx::const_reverse_result_iterator::const_reverse_result_iterator
const_reverse_result_iterator(const_result_iterator const &rhs)
Copy a reverse iterator from a regular iterator.
Definition result_iterator.hxx:212
pqxx::const_reverse_result_iterator::const_reverse_result_iterator
const_reverse_result_iterator(const_result_iterator const &&rhs)
Move a regular iterator into a reverse iterator.
Definition result_iterator.hxx:219
pqxx::const_reverse_result_iterator::const_reverse_result_iterator
const_reverse_result_iterator()=default
Create an iterator, but in an unusable state.
pqxx::const_reverse_row_iterator
Reverse iterator for a row. Use as row::const_reverse_iterator.
Definition row.hxx:411
pqxx::result
Result set containing data returned by a query or command.
Definition result.hxx:92
pqxx::row
Reference to one row in a result.
Definition row.hxx:47
pqxx::row::m_result
result m_result
Result set of which this is one row.
Definition row.hxx:249
pqxx::row::m_index
result::size_type m_index
Row number.
Definition row.hxx:256
pqxx
The home of all libpqxx classes, functions, templates, etc.
Definition array.cxx:27
pqxx::result_difference_type
int result_difference_type
Difference between result sizes.
Definition types.hxx:31
pqxx::result_size_type
int result_size_type
Number of rows in a result set.
Definition types.hxx:28