libpqxx
The C++ client library for PostgreSQL
stream_iterator.hxx
1 
9 #ifndef PQXX_H_STREAM_ITERATOR
10 #define PQXX_H_STREAM_ITERATOR
11 
12 #include <memory>
13 
14 namespace pqxx
15 {
16 template<typename... TYPE> class stream_query;
17 }
18 
19 
20 namespace pqxx::internal
21 {
22 // C++20: Replace with generator?
24 
27 template<typename... TYPE> class stream_from_input_iterator
28 {
29  using stream_t = stream_from;
30 
31 public:
32  using value_type = std::tuple<TYPE...>;
33 
35  stream_from_input_iterator() = default;
36 
37  explicit stream_from_input_iterator(stream_t &home) : m_home(&home)
38  {
39  advance();
40  }
42 
43  stream_from_input_iterator &operator++()
44  {
45  advance();
46  return *this;
47  }
48 
49  value_type const &operator*() const { return m_value; }
50 
52  bool operator==(stream_from_input_iterator const &rhs) const
53  {
54  return m_home == rhs.m_home;
55  }
57  bool operator!=(stream_from_input_iterator const &rhs) const
58  {
59  return not(*this == rhs);
60  }
61 
62 private:
63  void advance()
64  {
65  if (m_home == nullptr)
66  throw usage_error{"Moving stream_from iterator beyond end()."};
67  if (not((*m_home) >> m_value))
68  m_home = nullptr;
69  }
70 
71  stream_t *m_home{nullptr};
72  value_type m_value;
73 };
74 
75 
76 // C++20: Replace with generator?
78 template<typename... TYPE> class stream_input_iteration
79 {
80 public:
81  using stream_t = stream_from;
82  using iterator = stream_from_input_iterator<TYPE...>;
83  explicit stream_input_iteration(stream_t &home) : m_home{home} {}
84  iterator begin() const { return iterator{m_home}; }
85  iterator end() const { return {}; }
86 
87 private:
88  stream_t &m_home;
89 };
90 } // namespace pqxx::internal
91 #endif
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:248
Internal items for libpqxx' own use. Do not use these yourself.
Definition: encodings.cxx:32
stream_from_input_iterator()=default
Construct an "end" iterator.
bool operator!=(stream_from_input_iterator const &rhs) const
Comparison only works for comparing to end().
Definition: stream_iterator.hxx:57
bool operator==(stream_from_input_iterator const &rhs) const
Comparison only works for comparing to end().
Definition: stream_iterator.hxx:52
Stream data from the database.
Definition: stream_from.hxx:78
Definition: stream_iterator.hxx:16
Input iterator for stream_from.
Definition: stream_iterator.hxx:27
The home of all libpqxx classes, functions, templates, etc.
Definition: array.cxx:26
Iteration over a stream_query.
Definition: stream_iterator.hxx:78