20#include "pw_assert/assert.h"
21#include "pw_containers/dynamic_deque.h"
22#include "pw_multibuf/internal/chunk_iterator.h"
23#include "pw_multibuf/internal/entry.h"
25namespace pw::multibuf_impl {
37template <
typename SizeType,
bool kIsConst>
41 using Deque =
typename ChunkIteratorType::Deque;
44 using size_type = SizeType;
45 using difference_type = ptrdiff_t;
46 using value_type =
typename ChunkIteratorType::ByteType;
47 using pointer = value_type*;
48 using reference = value_type&;
49 using iterator_category = std::random_access_iterator_tag;
54 constexpr operator ByteIterator<SizeType,
true>()
const {
55 return {chunk_, offset_};
58 constexpr reference operator*()
const {
return chunk_->data()[offset_]; }
60 constexpr reference operator[](difference_type n)
const {
64 constexpr ByteIterator& operator++() {
return operator+=(1); }
74 return operator-=(-n);
76 size_t delta =
static_cast<size_t>(n);
78 while (delta != 0 && chunk_->size() <= delta) {
79 delta -= chunk_->size();
94 constexpr ByteIterator& operator--() {
return operator-=(1); }
104 return operator+=(-n);
106 size_t delta =
static_cast<size_t>(n);
107 while (delta > offset_) {
110 offset_ = chunk_->size();
120 constexpr friend difference_type operator-(
const ByteIterator& lhs,
125 difference_type delta = 0;
126 auto chunk = rhs.chunk_;
127 size_t offset = rhs.offset_;
128 while (chunk != lhs.chunk_) {
130 delta += bytes.size() - offset;
134 return delta +
static_cast<difference_type
>(lhs.offset_);
137 constexpr friend bool operator==(
const ByteIterator& lhs,
139 return lhs.Compare(rhs) == 0;
142 constexpr friend bool operator!=(
const ByteIterator& lhs,
144 return lhs.Compare(rhs) != 0;
147 constexpr friend bool operator<(
const ByteIterator& lhs,
149 return lhs.Compare(rhs) < 0;
152 constexpr friend bool operator>(
const ByteIterator& lhs,
154 return lhs.Compare(rhs) > 0;
157 constexpr friend bool operator<=(
const ByteIterator& lhs,
159 return lhs.Compare(rhs) <= 0;
162 constexpr friend bool operator>=(
const ByteIterator& lhs,
164 return lhs.Compare(rhs) >= 0;
169 template <
typename,
bool>
176 friend class IteratorTest;
179 : chunk_(chunk), offset_(offset) {}
181 constexpr size_type chunk_index()
const {
return chunk_.index_; }
184 constexpr int Compare(
const ByteIterator& other)
const {
185 if (chunk_ != other.chunk_) {
186 return chunk_.index_ < other.chunk_.index_ ? -1 : 1;
188 if (offset_ != other.offset_) {
189 return offset_ < other.offset_ ? -1 : 1;
Definition: byte_iterator.h:38
Definition: chunk_iterator.h:41
Definition: multibuf_v2.h:1172