libpqxx
The C++ client library for PostgreSQL
stream_iterator.hxx
Go to the documentation of this file.
1 
9 #ifndef PQXX_INTERNAL_STREAM_ITERATOR_HXX
10 #define PQXX_INTERNAL_STREAM_ITERATOR_HXX
11 
12 #include <memory>
13 
14 namespace pqxx
15 {
16 template<typename... TYPE> class stream_query;
17 } // namespace pqxx
18 
19 
20 namespace pqxx::internal
21 {
23 
26 template<typename... TYPE> class stream_from_input_iterator final
27 {
28  using stream_t = stream_from;
29 
30 public:
31  using value_type = std::tuple<TYPE...>;
32 
35 
36  explicit stream_from_input_iterator(stream_t &home, sl loc) : m_home(&home)
37  {
38  advance(loc);
39  }
42 
44  {
45  advance(sl::current());
46  return *this;
47  }
48 
50 
55 
56  value_type const &operator*() const noexcept { return m_value; }
57 
59  bool operator==(stream_from_input_iterator const &rhs) const noexcept
60  {
61  return m_home == rhs.m_home;
62  }
64  bool operator!=(stream_from_input_iterator const &rhs) const noexcept
65  {
66  return not(*this == rhs);
67  }
68 
69 private:
70  void advance(sl loc)
71  {
72  if (m_home == nullptr)
73  throw usage_error{"Moving stream_from iterator beyond end().", loc};
74  if (not((*m_home) >> m_value))
75  m_home = nullptr;
76  }
77 
78  stream_t *m_home{nullptr};
79  value_type m_value;
80 };
81 
82 
83 // TODO: Use separate type for end().
84 // TODO: Replace with generator?
86 template<typename... TYPE> class stream_input_iteration final
87 {
88 public:
91  explicit stream_input_iteration(stream_t &home) : m_home{home} {}
92  [[nodiscard]] iterator begin(sl loc = sl::current()) const
93  {
94  return iterator{m_home, loc};
95  }
96  [[nodiscard]] iterator end() const { return {}; }
97 
98 private:
99  // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
100  stream_t &m_home;
101 };
102 } // namespace pqxx::internal
103 #endif
Input iterator for stream_from.
Definition: stream_iterator.hxx:27
stream_from_input_iterator & operator=(stream_from_input_iterator &&)=default
stream_from_input_iterator(stream_from_input_iterator const &)=default
stream_from_input_iterator & operator=(stream_from_input_iterator const &)=default
stream_from_input_iterator & operator++()
Definition: stream_iterator.hxx:43
stream_from_input_iterator()=default
Construct an "end" iterator.
bool operator!=(stream_from_input_iterator const &rhs) const noexcept
Comparison only works for comparing to end().
Definition: stream_iterator.hxx:64
bool operator==(stream_from_input_iterator const &rhs) const noexcept
Comparison only works for comparing to end().
Definition: stream_iterator.hxx:59
stream_from_input_iterator(stream_from_input_iterator &&)=default
std::tuple< TYPE... > value_type
Definition: stream_iterator.hxx:31
stream_from_input_iterator(stream_t &home, sl loc)
Definition: stream_iterator.hxx:36
value_type const & operator*() const noexcept
Definition: stream_iterator.hxx:56
Iteration over a stream_query.
Definition: stream_iterator.hxx:87
stream_from stream_t
Definition: stream_iterator.hxx:89
iterator end() const
Definition: stream_iterator.hxx:96
stream_input_iteration(stream_t &home)
Definition: stream_iterator.hxx:91
iterator begin(sl loc=sl::current()) const
Definition: stream_iterator.hxx:92
Stream data from the database.
Definition: stream_from.hxx:79
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:580
Private namespace for libpqxx's internal use; do not access.
Definition: connection.cxx:333
The home of all libpqxx classes, functions, templates, etc.
Definition: array.cxx:26
std::source_location sl
Convenience alias for std::source_location. It's just too long.
Definition: types.hxx:38
Definition: stream_iterator.hxx:16