libpqxx
The C++ client library for PostgreSQL
Loading...
Searching...
No Matches
stream_iterator.hxx
Go to the documentation of this file.
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
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 }
56
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;
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
stream_from_input_iterator(stream_from_input_iterator const &)=default
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 & operator++()
Definition stream_iterator.hxx:43
value_type const & operator*() const
Definition stream_iterator.hxx:49
stream_from_input_iterator()=default
Construct an "end" iterator.
std::tuple< TYPE... > value_type
Definition stream_iterator.hxx:32
stream_from_input_iterator(stream_t &home)
Definition stream_iterator.hxx:37
stream_from_input_iterator< TYPE... > iterator
Definition stream_iterator.hxx:82
stream_from stream_t
Definition stream_iterator.hxx:81
iterator end() const
Definition stream_iterator.hxx:85
iterator begin() const
Definition stream_iterator.hxx:84
stream_input_iteration(stream_t &home)
Definition stream_iterator.hxx:83
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
Definition stream_iterator.hxx:16