tuple.hxx
/*-------------------------------------------------------------------------
*
* FILE
* pqxx/result.hxx
*
* DESCRIPTION
* definitions for the pqxx::result class and support classes.
* pqxx::result represents the set of result tuples from a database query
* DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/tuple instead.
*
* Copyright (c) 2001-2011, Jeroen T. Vermeulen <jtv@xs4all.nl>
*
* 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_TUPLE
#define PQXX_H_TUPLE
#include "pqxx/compiler-public.hxx"
#include "pqxx/compiler-internal-pre.hxx"
#include "pqxx/except"
#include "pqxx/field"
/* Methods tested in eg. self-test program test001 are marked with "//[t1]"
*/
namespace pqxx
{
class const_tuple_iterator;
class const_reverse_tuple_iterator;
class result;
class range_error;
class PQXX_LIBEXPORT tuple
{
public:
typedef tuple_size_type size_type;
typedef tuple_difference_type difference_type;
typedef const_tuple_iterator const_iterator;
typedef const_iterator iterator;
typedef field reference;
typedef const_tuple_iterator pointer;
typedef const_reverse_tuple_iterator const_reverse_iterator;
typedef const_reverse_iterator reverse_iterator;
tuple(const result *r, size_t i) throw ();
~tuple() throw () {} // Yes Scott Meyers, you're absolutely right[1]
bool PQXX_PURE operator==(const tuple &) const throw (); //[t75]
bool operator!=(const tuple &rhs) const throw () //[t75]
{ return !operator==(rhs); }
const_iterator begin() const throw (); //[t82]
const_iterator end() const throw (); //[t82]
reference front() const throw (); //[t74]
reference back() const throw (); //[t75]
const_reverse_tuple_iterator rbegin() const; //[t82]
const_reverse_tuple_iterator rend() const; //[t82]
reference operator[](size_type) const throw (); //[t11]
reference operator[](int) const throw (); //[t2]
reference operator[](const char[]) const; //[t11]
reference operator[](const PGSTD::string &) const; //[t11]
reference at(size_type) const throw (pqxx::range_error); //[t11]
reference at(int) const throw (pqxx::range_error); //[t11]
reference at(const char[]) const; //[t11]
reference at(const PGSTD::string &) const; //[t11]
size_type size() const throw () //[t11]
{ return m_End-m_Begin; }
void swap(tuple &) throw (); //[t11]
size_t rownumber() const throw () { return m_Index; } //[t11]
size_type column_number(const PGSTD::string &ColName) const //[t30]
{ return column_number(ColName.c_str()); }
size_type column_number(const char[]) const; //[t30]
oid column_type(size_type) const; //[t7]
oid column_type(int ColNum) const //[t7]
{ return column_type(size_type(ColNum)); }
oid column_type(const PGSTD::string &ColName) const //[t7]
{ return column_type(column_number(ColName)); }
oid column_type(const char ColName[]) const //[t7]
{ return column_type(column_number(ColName)); }
oid column_table(size_type ColNum) const; //[t2]
oid column_table(int ColNum) const //[t2]
{ return column_table(size_type(ColNum)); }
oid column_table(const PGSTD::string &ColName) const //[t2]
{ 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 PGSTD::string &ColName) const //[t93]
{ return table_column(column_number(ColName)); }
size_t num() const { return rownumber(); } //[t1]
tuple slice(size_type Begin, size_type End) const;
// Is this an empty slice?
bool PQXX_PURE empty() const throw ();
protected:
friend class field;
const result *m_Home;
size_t m_Index;
size_type m_Begin;
size_type m_End;
private:
// Not allowed:
tuple();
};
class PQXX_LIBEXPORT const_tuple_iterator :
public PGSTD::iterator<PGSTD::random_access_iterator_tag,
const field,
tuple::size_type>,
public field
{
typedef PGSTD::iterator<PGSTD::random_access_iterator_tag,
const field,
tuple::size_type> it;
public:
using it::pointer;
typedef tuple::size_type size_type;
typedef tuple::difference_type difference_type;
typedef field reference;
const_tuple_iterator(const tuple &T, tuple::size_type C) throw () : //[t82]
field(T, C) {}
const_tuple_iterator(const field &F) throw () : field(F) {} //[t82]
pointer operator->() const { return this; } //[t82]
reference operator*() const { return field(*this); } //[t82]
const_tuple_iterator operator++(int); //[t82]
const_tuple_iterator &operator++() { ++m_col; return *this; } //[t82]
const_tuple_iterator operator--(int); //[t82]
const_tuple_iterator &operator--() { --m_col; return *this; } //[t82]
const_tuple_iterator &operator+=(difference_type i) //[t82]
{ m_col = size_type(difference_type(m_col) + i); return *this; }
const_tuple_iterator &operator-=(difference_type i) //[t82]
{ m_col = size_type(difference_type(m_col) - i); return *this; }
bool operator==(const const_tuple_iterator &i) const //[t82]
{return col()==i.col();}
bool operator!=(const const_tuple_iterator &i) const //[t82]
{return col()!=i.col();}
bool operator<(const const_tuple_iterator &i) const //[t82]
{return col()<i.col();}
bool operator<=(const const_tuple_iterator &i) const //[t82]
{return col()<=i.col();}
bool operator>(const const_tuple_iterator &i) const //[t82]
{return col()>i.col();}
bool operator>=(const const_tuple_iterator &i) const //[t82]
{return col()>=i.col();}
inline const_tuple_iterator operator+(difference_type) const; //[t82]
friend const_tuple_iterator operator+( //[t82]
difference_type,
const_tuple_iterator);
inline const_tuple_iterator operator-(difference_type) const; //[t82]
inline difference_type operator-(const_tuple_iterator) const; //[t82]
};
class PQXX_LIBEXPORT const_reverse_tuple_iterator : private const_tuple_iterator
{
public:
typedef const_tuple_iterator super;
typedef const_tuple_iterator iterator_type;
using iterator_type::iterator_category;
using iterator_type::difference_type;
using iterator_type::pointer;
#ifndef _MSC_VER
using iterator_type::value_type;
using iterator_type::reference;
#else
// Workaround for Visual C++.NET 2003, which has access problems
typedef field value_type;
typedef const field &reference;
#endif
const_reverse_tuple_iterator(const const_reverse_tuple_iterator &r) : //[t82]
const_tuple_iterator(r) {}
explicit
const_reverse_tuple_iterator(const super &rhs) throw() : //[t82]
const_tuple_iterator(rhs) { super::operator--(); }
iterator_type PQXX_PURE base() const throw (); //[t82]
using iterator_type::operator->; //[t82]
using iterator_type::operator*; //[t82]
const_reverse_tuple_iterator &
operator=(const const_reverse_tuple_iterator &r) //[t82]
{ iterator_type::operator=(r); return *this; }
const_reverse_tuple_iterator operator++() //[t82]
{ iterator_type::operator--(); return *this; }
const_reverse_tuple_iterator operator++(int); //[t82]
const_reverse_tuple_iterator &operator--() //[t82]
{ iterator_type::operator++(); return *this; }
const_reverse_tuple_iterator operator--(int); //[t82]
const_reverse_tuple_iterator &operator+=(difference_type i) //[t82]
{ iterator_type::operator-=(i); return *this; }
const_reverse_tuple_iterator &operator-=(difference_type i) //[t82]
{ iterator_type::operator+=(i); return *this; }
const_reverse_tuple_iterator operator+(difference_type i) const //[t82]
{ return const_reverse_tuple_iterator(base()-i); }
const_reverse_tuple_iterator operator-(difference_type i) //[t82]
{ return const_reverse_tuple_iterator(base()+i); }
difference_type
operator-(const const_reverse_tuple_iterator &rhs) const //[t82]
{ return rhs.const_tuple_iterator::operator-(*this); }
bool
operator==(const const_reverse_tuple_iterator &rhs) const throw () //[t82]
{ return iterator_type::operator==(rhs); }
bool
operator!=(const const_reverse_tuple_iterator &rhs) const throw () //[t82]
{ return !operator==(rhs); }
bool operator<(const const_reverse_tuple_iterator &rhs) const //[t82]
{ return iterator_type::operator>(rhs); }
bool operator<=(const const_reverse_tuple_iterator &rhs) const //[t82]
{ return iterator_type::operator>=(rhs); }
bool operator>(const const_reverse_tuple_iterator &rhs) const //[t82]
{ return iterator_type::operator<(rhs); }
bool operator>=(const const_reverse_tuple_iterator &rhs) const //[t82]
{ return iterator_type::operator<=(rhs); }
};
inline const_tuple_iterator
const_tuple_iterator::operator+(difference_type o) const
{
return const_tuple_iterator(
tuple(home(), idx()),
size_type(difference_type(col()) + o));
}
inline const_tuple_iterator
operator+(const_tuple_iterator::difference_type o, const_tuple_iterator i)
{ return i + o; }
inline const_tuple_iterator
const_tuple_iterator::operator-(difference_type o) const
{
return const_tuple_iterator(
tuple(home(), idx()),
size_type(difference_type(col()) - o));
}
inline const_tuple_iterator::difference_type
const_tuple_iterator::operator-(const_tuple_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_tuple_iterator::const_tuple_iterator
const_tuple_iterator(const field &F)
Definition: tuple.hxx:216
pqxx::const_tuple_iterator::operator--
const_tuple_iterator & operator--()
Definition: tuple.hxx:233
pqxx::result
Result set containing data returned by a query or command.
Definition: result.hxx:81
pqxx::tuple::operator!=
bool operator!=(const tuple &rhs) const
Definition: tuple.hxx:74
pqxx::tuple::column_table
oid column_table(const std::string &ColName) const
What table did this column come from?
Definition: tuple.hxx:141
pqxx::tuple
Reference to one row in a result.
Definition: tuple.hxx:52
pqxx::field
Reference to a field in a result set.
Definition: field.hxx:43
pqxx::const_tuple_iterator::operator++
const_tuple_iterator & operator++()
Definition: tuple.hxx:231
pqxx::const_reverse_tuple_iterator::super
const_tuple_iterator super
Definition: tuple.hxx:279
pqxx::tuple::~tuple
~tuple()
Definition: tuple.hxx:67
pqxx::const_tuple_iterator::operator-=
const_tuple_iterator & operator-=(difference_type i)
Definition: tuple.hxx:237
pqxx::const_tuple_iterator::operator<
bool operator<(const const_tuple_iterator &i) const
Definition: tuple.hxx:249
pqxx::tuple::const_iterator
const_tuple_iterator const_iterator
Definition: tuple.hxx:57
pqxx::tuple::column_table
oid column_table(int ColNum) const
What table did this column come from?
Definition: tuple.hxx:138
pqxx::const_tuple_iterator::operator!=
bool operator!=(const const_tuple_iterator &i) const
Definition: tuple.hxx:247
pqxx::const_tuple_iterator::operator+
const_tuple_iterator operator+(difference_type) const
Definition: tuple.hxx:365
pqxx::tuple::difference_type
tuple_difference_type difference_type
Definition: tuple.hxx:56
pqxx::tuple::column_type
oid column_type(const std::string &ColName) const
Type of given column.
Definition: tuple.hxx:127
pqxx::tuple::m_Index
size_t m_Index
Definition: tuple.hxx:188
pqxx::const_reverse_tuple_iterator::operator-=
const_reverse_tuple_iterator & operator-=(difference_type i)
Definition: tuple.hxx:324
pqxx::const_reverse_tuple_iterator::operator+=
const_reverse_tuple_iterator & operator+=(difference_type i)
Definition: tuple.hxx:322
pqxx::const_reverse_tuple_iterator::operator>=
bool operator>=(const const_reverse_tuple_iterator &rhs) const
Definition: tuple.hxx:358
pqxx::const_reverse_tuple_iterator::operator<=
bool operator<=(const const_reverse_tuple_iterator &rhs) const
Definition: tuple.hxx:354
pqxx::tuple::pointer
const_tuple_iterator pointer
Definition: tuple.hxx:60
pqxx::const_tuple_iterator::const_tuple_iterator
const_tuple_iterator(const tuple &T, tuple::size_type C)
Definition: tuple.hxx:214
pqxx::const_reverse_tuple_iterator::operator!=
bool operator!=(const const_reverse_tuple_iterator &rhs) const
Definition: tuple.hxx:349
pqxx::const_tuple_iterator::size_type
tuple::size_type size_type
Definition: tuple.hxx:210
pqxx::const_reverse_tuple_iterator
Reverse iterator for a tuple. Use as tuple::const_reverse_iterator.
Definition: tuple.hxx:276
pqxx::tuple::m_Home
const result * m_Home
Definition: tuple.hxx:187
pqxx::const_tuple_iterator::operator<=
bool operator<=(const const_tuple_iterator &i) const
Definition: tuple.hxx:251
pqxx::const_tuple_iterator::reference
field reference
Definition: tuple.hxx:212
pqxx::tuple::column_type
oid column_type(int ColNum) const
Type of given column.
Definition: tuple.hxx:123
pqxx::const_tuple_iterator
Iterator for fields in a tuple. Use as tuple::const_iterator.
Definition: tuple.hxx:199
pqxx::const_reverse_tuple_iterator::const_reverse_tuple_iterator
const_reverse_tuple_iterator(const const_reverse_tuple_iterator &r)
Definition: tuple.hxx:293
pqxx::const_reverse_tuple_iterator::iterator_type
const_tuple_iterator iterator_type
Definition: tuple.hxx:280
pqxx::const_reverse_tuple_iterator::operator-
difference_type operator-(const const_reverse_tuple_iterator &rhs) const
Definition: tuple.hxx:337
pqxx::tuple::iterator
const_iterator iterator
Definition: tuple.hxx:58
pqxx::const_tuple_iterator::operator>
bool operator>(const const_tuple_iterator &i) const
Definition: tuple.hxx:253
pqxx::operator+
const_result_iterator operator+(result::difference_type o, const_result_iterator i)
Definition: result.hxx:479
pqxx::tuple::size_type
tuple_size_type size_type
Definition: tuple.hxx:55
pqxx::tuple::m_End
size_type m_End
Definition: tuple.hxx:190
pqxx::const_tuple_iterator::operator==
bool operator==(const const_tuple_iterator &i) const
Definition: tuple.hxx:245
pqxx::const_reverse_tuple_iterator::operator+
const_reverse_tuple_iterator operator+(difference_type i) const
Definition: tuple.hxx:332
pqxx::const_tuple_iterator::operator*
reference operator*() const
Definition: tuple.hxx:223
pqxx::tuple::m_Begin
size_type m_Begin
Definition: tuple.hxx:189
pqxx::const_reverse_tuple_iterator::operator<
bool operator<(const const_reverse_tuple_iterator &rhs) const
Definition: tuple.hxx:352
pqxx::const_reverse_tuple_iterator::operator--
const_reverse_tuple_iterator & operator--()
Definition: tuple.hxx:319
pqxx::const_tuple_iterator::operator+=
const_tuple_iterator & operator+=(difference_type i)
Definition: tuple.hxx:235
pqxx::tuple::num
size_t num() const
Definition: tuple.hxx:166
pqxx::tuple::table_column
size_type table_column(int ColNum) const
What column number in its table did this result column come from?
Definition: tuple.hxx:158
pqxx::const_reverse_tuple_iterator::operator=
const_reverse_tuple_iterator & operator=(const const_reverse_tuple_iterator &r)
Definition: tuple.hxx:314
pqxx::tuple_size_type
unsigned int tuple_size_type
Definition: field.hxx:34
pqxx::tuple::table_column
size_type table_column(const std::string &ColName) const
What column number in its table did this result column come from?
Definition: tuple.hxx:162
pqxx::tuple::size
size_type size() const
Definition: tuple.hxx:101
pqxx::const_reverse_tuple_iterator::operator>
bool operator>(const const_reverse_tuple_iterator &rhs) const
Definition: tuple.hxx:356
pqxx::const_reverse_tuple_iterator::operator-
const_reverse_tuple_iterator operator-(difference_type i)
Definition: tuple.hxx:334
pqxx::tuple::column_type
oid column_type(const char ColName[]) const
Type of given column.
Definition: tuple.hxx:131
pqxx::tuple::reference
field reference
Definition: tuple.hxx:59
pqxx::const_tuple_iterator::operator-
const_tuple_iterator operator-(difference_type) const
Definition: tuple.hxx:377
pqxx::tuple::rownumber
size_t rownumber() const
Definition: tuple.hxx:106
pqxx::const_tuple_iterator::operator->
pointer operator->() const
Definition: tuple.hxx:222
pqxx::const_reverse_tuple_iterator::const_reverse_tuple_iterator
const_reverse_tuple_iterator(const super &rhs)
Definition: tuple.hxx:296
pqxx::const_tuple_iterator::operator>=
bool operator>=(const const_tuple_iterator &i) const
Definition: tuple.hxx:255
pqxx
The home of all libpqxx classes, functions, templates, etc.
Definition: basic_connection.hxx:35
pqxx::const_reverse_tuple_iterator::operator++
const_reverse_tuple_iterator operator++()
Definition: tuple.hxx:316
pqxx::tuple_difference_type
signed int tuple_difference_type
Definition: field.hxx:37
pqxx::range_error
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:203
pqxx::const_reverse_tuple_iterator::operator==
bool operator==(const const_reverse_tuple_iterator &rhs) const
Definition: tuple.hxx:346
pqxx::const_tuple_iterator::difference_type
tuple::difference_type difference_type
Definition: tuple.hxx:211
pqxx::tuple::const_reverse_iterator
const_reverse_tuple_iterator const_reverse_iterator
Definition: tuple.hxx:61
pqxx::tuple::reverse_iterator
const_reverse_iterator reverse_iterator
Definition: tuple.hxx:62
pqxx::field::num
tuple_size_type num() const
Definition: field.hxx:98