File indexing completed on 2025-01-18 09:42:39
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_MYSQL_DETAIL_ROWS_ITERATOR_HPP
0009 #define BOOST_MYSQL_DETAIL_ROWS_ITERATOR_HPP
0010
0011 #include <boost/mysql/field_view.hpp>
0012 #include <boost/mysql/row.hpp>
0013 #include <boost/mysql/row_view.hpp>
0014
0015 #include <boost/mysql/detail/access.hpp>
0016
0017 #include <cstddef>
0018 #include <cstdint>
0019 #include <iterator>
0020
0021 namespace boost {
0022 namespace mysql {
0023 namespace detail {
0024
0025 inline row_view row_slice(const field_view* fields, std::size_t num_columns, std::size_t offset) noexcept
0026 {
0027 return access::construct<row_view>(fields + num_columns * offset, num_columns);
0028 }
0029
0030 class rows_iterator
0031 {
0032 const field_view* fields_{nullptr};
0033 std::size_t num_columns_{0};
0034 std::size_t row_num_{0};
0035
0036 public:
0037 using value_type = row;
0038 using reference = row_view;
0039 using pointer = row_view;
0040 using difference_type = std::ptrdiff_t;
0041 using iterator_category = std::random_access_iterator_tag;
0042
0043 rows_iterator() = default;
0044 rows_iterator(const field_view* fields, std::size_t num_columns, std::size_t rownum) noexcept
0045 : fields_(fields), num_columns_(num_columns), row_num_(rownum)
0046 {
0047 }
0048
0049 rows_iterator& operator++() noexcept
0050 {
0051 ++row_num_;
0052 return *this;
0053 }
0054 rows_iterator operator++(int) noexcept
0055 {
0056 auto res = *this;
0057 ++(*this);
0058 return res;
0059 }
0060 rows_iterator& operator--() noexcept
0061 {
0062 --row_num_;
0063 return *this;
0064 }
0065 rows_iterator operator--(int) noexcept
0066 {
0067 auto res = *this;
0068 --(*this);
0069 return res;
0070 }
0071 rows_iterator& operator+=(std::ptrdiff_t n) noexcept
0072 {
0073 row_num_ += n;
0074 return *this;
0075 }
0076 rows_iterator& operator-=(std::ptrdiff_t n) noexcept
0077 {
0078 row_num_ -= n;
0079 return *this;
0080 }
0081 rows_iterator operator+(std::ptrdiff_t n) const noexcept
0082 {
0083 return rows_iterator(fields_, num_columns_, row_num_ + n);
0084 }
0085 rows_iterator operator-(std::ptrdiff_t n) const noexcept
0086 {
0087 return rows_iterator(fields_, num_columns_, row_num_ - n);
0088 }
0089 std::ptrdiff_t operator-(rows_iterator rhs) const noexcept { return row_num_ - rhs.row_num_; }
0090
0091 pointer operator->() const noexcept { return **this; }
0092 reference operator*() const noexcept { return (*this)[0]; }
0093 reference operator[](std::ptrdiff_t i) const noexcept
0094 {
0095 return row_slice(fields_, num_columns_, row_num_ + i);
0096 }
0097
0098 bool operator==(rows_iterator rhs) const noexcept { return row_num_ == rhs.row_num_; }
0099 bool operator!=(rows_iterator rhs) const noexcept { return !(*this == rhs); }
0100 bool operator<(rows_iterator rhs) const noexcept { return row_num_ < rhs.row_num_; }
0101 bool operator<=(rows_iterator rhs) const noexcept { return row_num_ <= rhs.row_num_; }
0102 bool operator>(rows_iterator rhs) const noexcept { return row_num_ > rhs.row_num_; }
0103 bool operator>=(rows_iterator rhs) const noexcept { return row_num_ >= rhs.row_num_; }
0104 };
0105
0106 inline rows_iterator operator+(std::ptrdiff_t n, rows_iterator it) noexcept { return it + n; }
0107
0108 }
0109 }
0110 }
0111
0112 #endif