libpqxx
The C++ client library for PostgreSQL
Loading...
Searching...
No Matches
stream_iterator.hxx
1
9#ifndef PQXX_H_STREAM_ITERATOR
10#define PQXX_H_STREAM_ITERATOR
11
12#include <memory>
13
14namespace pqxx
15{
16template<typename... TYPE> class stream_query;
17}
18
19
20namespace pqxx::internal
21{
22// C++20: Replace with generator?
24
27template<typename... TYPE> class stream_from_input_iterator
28{
29 using stream_t = stream_from;
30
31public:
32 using value_type = std::tuple<TYPE...>;
33
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
53 {
54 return m_home == rhs.m_home;
55 }
58 {
59 return not(*this == rhs);
60 }
61
62private:
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?
78template<typename... TYPE> class stream_input_iteration
79{
80public:
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
87private:
88 stream_t &m_home;
89};
90} // namespace pqxx::internal
91#endif
Input iterator for stream_from.
Definition stream_iterator.hxx:28
bool operator==(stream_from_input_iterator const &rhs) const
Comparison only works for comparing to end().
Definition stream_iterator.hxx:52
bool operator!=(stream_from_input_iterator const &rhs) const
Comparison only works for comparing to end().
Definition stream_iterator.hxx:57
stream_from_input_iterator()=default
Construct an "end" iterator.
Iteration over a stream_query.
Definition stream_iterator.hxx:79
Stream data from the database.
Definition stream_from.hxx:79
Error in usage of libpqxx library, similar to std::logic_error.
Definition except.hxx:249
Internal items for libpqxx' own use. Do not use these yourself.
Definition encodings.cxx:33
The home of all libpqxx classes, functions, templates, etc.
Definition array.cxx:27
strip_t< decltype(*std::begin(std::declval< CONTAINER >()))> value_type
The type of a container's elements.
Definition types.hxx:94
Definition stream_iterator.hxx:16