Loading...
Searching...
No Matches
stream_iterator.hxx
#ifndef PQXX_H_STREAM_ITERATOR
#define PQXX_H_STREAM_ITERATOR
#include <memory>
namespace pqxx
{
template<typename... TYPE> class stream_query;
}
namespace pqxx::internal
{
// C++20: Replace with generator?
template<typename... TYPE> class stream_from_input_iterator
{
using stream_t = stream_from;
public:
using value_type = std::tuple<TYPE...>;
stream_from_input_iterator() = default;
explicit stream_from_input_iterator(stream_t &home) : m_home(&home)
{
advance();
}
stream_from_input_iterator(stream_from_input_iterator const &) = default;
stream_from_input_iterator &operator++()
{
advance();
return *this;
}
value_type const &operator*() const { return m_value; }
bool operator==(stream_from_input_iterator const &rhs) const
{
return m_home == rhs.m_home;
}
bool operator!=(stream_from_input_iterator const &rhs) const
{
return not(*this == rhs);
}
private:
void advance()
{
if (m_home == nullptr)
throw usage_error{"Moving stream_from iterator beyond end()."};
if (not((*m_home) >> m_value))
m_home = nullptr;
}
stream_t *m_home{nullptr};
value_type m_value;
};
// C++20: Replace with generator?
template<typename... TYPE> class stream_input_iteration
{
public:
using stream_t = stream_from;
using iterator = stream_from_input_iterator<TYPE...>;
explicit stream_input_iteration(stream_t &home) : m_home{home} {}
iterator begin() const { return iterator{m_home}; }
iterator end() const { return {}; }
private:
stream_t &m_home;
};
} // namespace pqxx::internal
#endif
pqxx::internal::stream_from_input_iterator
Input iterator for stream_from.
Definition stream_iterator.hxx:28
pqxx::internal::stream_from_input_iterator::operator==
bool operator==(stream_from_input_iterator const &rhs) const
Comparison only works for comparing to end().
Definition stream_iterator.hxx:52
pqxx::internal::stream_from_input_iterator::operator!=
bool operator!=(stream_from_input_iterator const &rhs) const
Comparison only works for comparing to end().
Definition stream_iterator.hxx:57
pqxx::internal::stream_from_input_iterator::stream_from_input_iterator
stream_from_input_iterator()=default
Construct an "end" iterator.
pqxx::usage_error
Error in usage of libpqxx library, similar to std::logic_error.
Definition except.hxx:249
pqxx::internal
Internal items for libpqxx' own use. Do not use these yourself.
Definition encodings.cxx:33
pqxx
The home of all libpqxx classes, functions, templates, etc.
Definition array.cxx:27
pqxx::value_type
strip_t< decltype(*std::begin(std::declval< CONTAINER >()))> value_type
The type of a container's elements.
Definition types.hxx:96
pqxx::stream_query
Definition stream_iterator.hxx:16