row.hxx
#ifndef PQXX_H_ROW
#define PQXX_H_ROW
#include "pqxx/compiler-public.hxx"
#include "pqxx/compiler-internal-pre.hxx"
#include "pqxx/except.hxx"
#include "pqxx/field.hxx"
#include "pqxx/result.hxx"
// Methods tested in eg. test module test01 are marked with "//[t01]".
namespace pqxx
{
class PQXX_LIBEXPORT row
{
public:
using size_type = row_size_type;
using difference_type = row_difference_type;
using const_iterator = const_row_iterator;
using iterator = const_iterator;
using reference = field;
using pointer = const_row_iterator;
using const_reverse_iterator = const_reverse_row_iterator;
using reverse_iterator = const_reverse_iterator;
row() =default;
row(result r, size_t i) noexcept;
~row() noexcept =default; // Yes Scott Meyers, you're absolutely right[1]
PQXX_PURE bool operator==(const row &) const noexcept; //[t75]
bool operator!=(const row &rhs) const noexcept //[t75]
{ return not operator==(rhs); }
const_iterator begin() const noexcept; //[t82]
const_iterator cbegin() const noexcept;
const_iterator end() const noexcept; //[t82]
const_iterator cend() const noexcept;
reference front() const noexcept; //[t74]
reference back() const noexcept; //[t75]
const_reverse_row_iterator rbegin() const; //[t82]
const_reverse_row_iterator crbegin() const;
const_reverse_row_iterator rend() const; //[t82]
const_reverse_row_iterator crend() const;
reference operator[](size_type) const noexcept; //[t11]
reference operator[](int) const noexcept; //[t02]
reference operator[](const char[]) const; //[t11]
reference operator[](const std::string &) const; //[t11]
reference at(size_type) const; //[t11]
reference at(int) const; //[t11]
reference at(const char[]) const; //[t11]
reference at(const std::string &) const; //[t11]
size_type size() const noexcept //[t11]
{ return m_end-m_begin; }
void swap(row &) noexcept; //[t11]
size_t rownumber() const noexcept { return size_t(m_index); } //[t11]
size_type column_number(const std::string &ColName) const //[t30]
{ return column_number(ColName.c_str()); }
size_type column_number(const char[]) const; //[t30]
oid column_type(size_type) const; //[t07]
oid column_type(int ColNum) const //[t07]
{ return column_type(size_type(ColNum)); }
oid column_type(const std::string &ColName) const //[t07]
{ return column_type(column_number(ColName)); }
oid column_type(const char ColName[]) const //[t07]
{ return column_type(column_number(ColName)); }
oid column_table(size_type ColNum) const; //[t02]
oid column_table(int ColNum) const //[t02]
{ return column_table(size_type(ColNum)); }
oid column_table(const std::string &ColName) const //[t02]
{ return column_table(column_number(ColName)); }
size_type table_column(size_type) const; //[t93]
size_type table_column(int ColNum) const //[t93]
{ return table_column(size_type(ColNum)); }
size_type table_column(const std::string &ColName) const //[t93]
{ return table_column(column_number(ColName)); }
size_t num() const { return rownumber(); } //[t01]
row slice(size_type Begin, size_type End) const;
// Is this an empty slice?
PQXX_PURE bool empty() const noexcept;
protected:
friend class field;
result m_result;
long m_index = 0;
size_type m_begin = 0;
size_type m_end = 0;
};
class PQXX_LIBEXPORT const_row_iterator : public field
{
public:
using iterator_category = std::random_access_iterator_tag;
using value_type = const field;
using pointer = const field *;
using size_type = row_size_type;
using difference_type = row_difference_type;
using reference = field;
const_row_iterator(const row &T, row_size_type C) noexcept : //[t82]
field{T, C} {}
const_row_iterator(const field &F) noexcept : field{F} {} //[t82]
pointer operator->() const { return this; } //[t82]
reference operator*() const { return field{*this}; } //[t82]
const_row_iterator operator++(int); //[t82]
const_row_iterator &operator++() { ++m_col; return *this; } //[t82]
const_row_iterator operator--(int); //[t82]
const_row_iterator &operator--() { --m_col; return *this; } //[t82]
const_row_iterator &operator+=(difference_type i) //[t82]
{ m_col = size_type(difference_type(m_col) + i); return *this; }
const_row_iterator &operator-=(difference_type i) //[t82]
{ m_col = size_type(difference_type(m_col) - i); return *this; }
bool operator==(const const_row_iterator &i) const //[t82]
{return col()==i.col();}
bool operator!=(const const_row_iterator &i) const //[t82]
{return col()!=i.col();}
bool operator<(const const_row_iterator &i) const //[t82]
{return col()<i.col();}
bool operator<=(const const_row_iterator &i) const //[t82]
{return col()<=i.col();}
bool operator>(const const_row_iterator &i) const //[t82]
{return col()>i.col();}
bool operator>=(const const_row_iterator &i) const //[t82]
{return col()>=i.col();}
inline const_row_iterator operator+(difference_type) const; //[t82]
friend const_row_iterator operator+( //[t82]
difference_type,
const_row_iterator);
inline const_row_iterator operator-(difference_type) const; //[t82]
inline difference_type operator-(const_row_iterator) const; //[t82]
};
class PQXX_LIBEXPORT const_reverse_row_iterator : private const_row_iterator
{
public:
using super = const_row_iterator;
using iterator_type = const_row_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_row_iterator(const const_reverse_row_iterator &r) : //[t82]
const_row_iterator{r} {}
explicit
const_reverse_row_iterator(const super &rhs) noexcept : //[t82]
const_row_iterator{rhs} { super::operator--(); }
PQXX_PURE iterator_type base() const noexcept; //[t82]
using iterator_type::operator->; //[t82]
using iterator_type::operator*; //[t82]
const_reverse_row_iterator &
operator=(const const_reverse_row_iterator &r) //[t82]
{ iterator_type::operator=(r); return *this; }
const_reverse_row_iterator operator++() //[t82]
{ iterator_type::operator--(); return *this; }
const_reverse_row_iterator operator++(int); //[t82]
const_reverse_row_iterator &operator--() //[t82]
{ iterator_type::operator++(); return *this; }
const_reverse_row_iterator operator--(int); //[t82]
const_reverse_row_iterator &operator+=(difference_type i) //[t82]
{ iterator_type::operator-=(i); return *this; }
const_reverse_row_iterator &operator-=(difference_type i) //[t82]
{ iterator_type::operator+=(i); return *this; }
const_reverse_row_iterator operator+(difference_type i) const //[t82]
{ return const_reverse_row_iterator{base()-i}; }
const_reverse_row_iterator operator-(difference_type i) //[t82]
{ return const_reverse_row_iterator{base()+i}; }
difference_type
operator-(const const_reverse_row_iterator &rhs) const //[t82]
{ return rhs.const_row_iterator::operator-(*this); }
bool operator==(const const_reverse_row_iterator &rhs) const noexcept //[t82]
{ return iterator_type::operator==(rhs); }
bool operator!=(const const_reverse_row_iterator &rhs) const noexcept //[t82]
{ return !operator==(rhs); }
bool operator<(const const_reverse_row_iterator &rhs) const //[t82]
{ return iterator_type::operator>(rhs); }
bool operator<=(const const_reverse_row_iterator &rhs) const //[t82]
{ return iterator_type::operator>=(rhs); }
bool operator>(const const_reverse_row_iterator &rhs) const //[t82]
{ return iterator_type::operator<(rhs); }
bool operator>=(const const_reverse_row_iterator &rhs) const //[t82]
{ return iterator_type::operator<=(rhs); }
};
inline const_row_iterator
const_row_iterator::operator+(difference_type o) const
{
return const_row_iterator{
row(home(), idx()),
size_type(difference_type(col()) + o)};
}
inline const_row_iterator
operator+(const_row_iterator::difference_type o, const_row_iterator i)
{ return i + o; }
inline const_row_iterator
const_row_iterator::operator-(difference_type o) const
{
return const_row_iterator{
row(home(), idx()),
size_type(difference_type(col()) - o)};
}
inline const_row_iterator::difference_type
const_row_iterator::operator-(const_row_iterator i) const
{ return difference_type(num() - i.num()); }
} // namespace pqxx
/*
[1] Scott Meyers, in one of his essential books, "Effective C++" and "More
Effective C++", points out that it is good style to have any class containing
a member of pointer type define a destructor--just to show that it knows what
it is doing with the pointer. This helps prevent nasty memory leak / double
deletion bugs typically resulting from programmers' omission to deal with such
issues in their destructors.
The @c -Weffc++ option in gcc generates warnings for noncompliance with Scott's
style guidelines, and hence necessitates the definition of this destructor,
trivial as it may be.
*/
#include "pqxx/compiler-internal-post.hxx"
#endif
pqxx::const_reverse_row_iterator::operator!=
bool operator!=(const const_reverse_row_iterator &rhs) const noexcept
Definition: row.hxx:344
pqxx::const_reverse_row_iterator
Reverse iterator for a row. Use as row::const_reverse_iterator.
Definition: row.hxx:279
pqxx::const_row_iterator::operator--
const_row_iterator & operator--()
Definition: row.hxx:236
pqxx::const_row_iterator::operator+=
const_row_iterator & operator+=(difference_type i)
Definition: row.hxx:238
pqxx::const_row_iterator::iterator_category
std::random_access_iterator_tag iterator_category
Definition: row.hxx:210
pqxx::row::table_column
size_type table_column(const std::string &ColName) const
What column number in its table did this result column come from?
Definition: row.hxx:166
pqxx::field::size_type
field_size_type size_type
Definition: field.hxx:52
pqxx::result::column_number
row_size_type column_number(const char ColName[]) const
Number of given column (throws exception if it doesn't exist).
Definition: row.cxx:207
pqxx::const_reverse_row_iterator::operator<=
bool operator<=(const const_reverse_row_iterator &rhs) const
Definition: row.hxx:349
pqxx::const_row_iterator::operator-=
const_row_iterator & operator-=(difference_type i)
Definition: row.hxx:240
pqxx::const_row_iterator::operator==
bool operator==(const const_row_iterator &i) const
Definition: row.hxx:248
pqxx::row::row
row()=default
pqxx::const_reverse_row_iterator::base
PQXX_PURE iterator_type base() const noexcept
Definition: row.cxx:254
pqxx::const_row_iterator::difference_type
row_difference_type difference_type
Definition: row.hxx:214
pqxx::const_reverse_row_iterator::operator>
bool operator>(const const_reverse_row_iterator &rhs) const
Definition: row.hxx:351
pqxx::const_reverse_row_iterator::operator++
const_reverse_row_iterator operator++()
Definition: row.hxx:313
pqxx::row::cbegin
const_iterator cbegin() const noexcept
Definition: row.cxx:41
pqxx::const_reverse_row_iterator::const_reverse_row_iterator
const_reverse_row_iterator(const super &rhs) noexcept
Definition: row.hxx:293
pqxx::const_reverse_row_iterator::operator--
const_reverse_row_iterator & operator--()
Definition: row.hxx:316
pqxx::const_row_iterator::const_row_iterator
const_row_iterator(const field &F) noexcept
Definition: row.hxx:219
pqxx::row::cend
const_iterator cend() const noexcept
Definition: row.cxx:53
pqxx::row::at
reference at(size_type) const
Definition: row.cxx:163
pqxx::row::crbegin
const_reverse_row_iterator crbegin() const
Definition: row.cxx:77
pqxx::row_difference_type
signed int row_difference_type
Difference between row sizes.
Definition: types.hxx:27
pqxx::const_row_iterator::operator->
pointer operator->() const
Definition: row.hxx:225
pqxx::const_row_iterator::const_row_iterator
const_row_iterator(const row &T, row_size_type C) noexcept
Definition: row.hxx:217
pqxx::const_row_iterator::operator<=
bool operator<=(const const_row_iterator &i) const
Definition: row.hxx:254
pqxx::const_row_iterator::operator<
bool operator<(const const_row_iterator &i) const
Definition: row.hxx:252
pqxx::row::operator[]
reference operator[](size_type) const noexcept
Definition: row.cxx:106
pqxx::const_reverse_row_iterator::operator+=
const_reverse_row_iterator & operator+=(difference_type i)
Definition: row.hxx:319
pqxx::const_row_iterator::operator!=
bool operator!=(const const_row_iterator &i) const
Definition: row.hxx:250
pqxx::const_row_iterator::operator>=
bool operator>=(const const_row_iterator &i) const
Definition: row.hxx:258
pqxx::result
Result set containing data returned by a query or command.
Definition: result.hxx:69
pqxx::row::num
size_t num() const
Definition: row.hxx:170
pqxx::const_reverse_row_iterator::operator-
difference_type operator-(const const_reverse_row_iterator &rhs) const
Definition: row.hxx:334
pqxx::row_size_type
unsigned int row_size_type
Number of fields in a row of database data.
Definition: types.hxx:24
pqxx::row::column_number
size_type column_number(const std::string &ColName) const
Number of given column (throws exception if it doesn't exist)
Definition: row.hxx:120
pqxx::const_reverse_row_iterator::const_reverse_row_iterator
const_reverse_row_iterator(const const_reverse_row_iterator &r)
Definition: row.hxx:290
pqxx::const_reverse_row_iterator::operator-
const_reverse_row_iterator operator-(difference_type i)
Definition: row.hxx:331
pqxx::row::column_type
oid column_type(size_type) const
Type of given column.
Definition: row.cxx:172
pqxx::row::slice
row slice(size_type Begin, size_type End) const
Definition: row.cxx:219
pqxx::field
Reference to a field in a result set.
Definition: field.hxx:49
pqxx::row::m_begin
size_type m_begin
First column in slice. This row ignores lower-numbered columns.
Definition: row.hxx:200
pqxx::const_row_iterator::operator++
const_row_iterator & operator++()
Definition: row.hxx:234
pqxx::row::column_table
oid column_table(const std::string &ColName) const
What table did this column come from?
Definition: row.hxx:148
pqxx::row::column_type
oid column_type(const std::string &ColName) const
Type of given column.
Definition: row.hxx:134
pqxx::field::num
row_size_type num() const
Definition: field.hxx:104
pqxx::row::operator==
PQXX_PURE bool operator==(const row &) const noexcept
Definition: row.cxx:95
pqxx::row::column_type
oid column_type(int ColNum) const
Type of given column.
Definition: row.hxx:130
pqxx::row::column_table
oid column_table(size_type ColNum) const
What table did this column come from?
Definition: row.cxx:178
pqxx::const_row_iterator::operator*
reference operator*() const
Definition: row.hxx:226
pqxx::const_reverse_row_iterator::operator>=
bool operator>=(const const_reverse_row_iterator &rhs) const
Definition: row.hxx:353
pqxx::const_reverse_row_iterator::operator-=
const_reverse_row_iterator & operator-=(difference_type i)
Definition: row.hxx:321
pqxx::row::column_type
oid column_type(const char ColName[]) const
Type of given column.
Definition: row.hxx:138
pqxx::row::rbegin
const_reverse_row_iterator rbegin() const
Definition: row.cxx:71
pqxx::row::rownumber
size_t rownumber() const noexcept
Row number, assuming this is a real row and not end()/rend().
Definition: row.hxx:113
pqxx::const_reverse_row_iterator::operator==
bool operator==(const const_reverse_row_iterator &rhs) const noexcept
Definition: row.hxx:342
pqxx::const_row_iterator::operator+
const_row_iterator operator+(difference_type) const
Definition: row.hxx:360
pqxx::row::begin
const_iterator begin() const noexcept
Definition: row.cxx:35
pqxx::operator+
const_result_iterator operator+(result::difference_type o, const_result_iterator i)
Definition: result_iterator.hxx:212
pqxx::row::empty
PQXX_PURE bool empty() const noexcept
Definition: row.cxx:231
pqxx::row::front
reference front() const noexcept
Definition: row.cxx:59
pqxx::const_reverse_row_iterator::operator<
bool operator<(const const_reverse_row_iterator &rhs) const
Definition: row.hxx:347
pqxx::const_row_iterator
Iterator for fields in a row. Use as row::const_iterator.
Definition: row.hxx:207
pqxx::argument_error
Invalid argument passed to libpqxx, similar to std::invalid_argument.
Definition: except.hxx:229
pqxx::row::crend
const_reverse_row_iterator crend() const
Definition: row.cxx:89
pqxx::const_row_iterator::operator>
bool operator>(const const_row_iterator &i) const
Definition: row.hxx:256
pqxx::row::end
const_iterator end() const noexcept
Definition: row.cxx:47
pqxx::row::swap
void swap(row &) noexcept
Definition: row.cxx:142
pqxx::row::rend
const_reverse_row_iterator rend() const
Definition: row.cxx:83
pqxx::row::back
reference back() const noexcept
Definition: row.cxx:65
pqxx::row::table_column
size_type table_column(int ColNum) const
What column number in its table did this result column come from?
Definition: row.hxx:162
pqxx::range_error
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:251
pqxx::row::difference_type
row_difference_type difference_type
Definition: row.hxx:44
pqxx::row::table_column
size_type table_column(size_type) const
What column number in its table did this result column come from?
Definition: row.cxx:184
pqxx
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
pqxx::const_reverse_row_iterator::operator+
const_reverse_row_iterator operator+(difference_type i) const
Definition: row.hxx:329
pqxx::row
Reference to one row in a result.
Definition: row.hxx:40
pqxx::row::size_type
row_size_type size_type
Definition: row.hxx:43
pqxx::row::column_table
oid column_table(int ColNum) const
What table did this column come from?
Definition: row.hxx:145
pqxx::const_row_iterator::operator-
const_row_iterator operator-(difference_type) const
Definition: row.hxx:372