19#include "pw_assert/assert.h"
20#include "pw_bytes/span.h"
21#include "pw_sync/mutex.h"
23namespace pw::multibuf {
25class ChunkRegionTracker;
56 std::byte* data() {
return span_.data(); }
57 const std::byte* data()
const {
return span_.data(); }
58 size_t size()
const {
return span_.size(); }
59 [[nodiscard]]
bool empty()
const {
return span_.empty(); }
61 std::byte& operator[](
size_t index) {
return span_[index]; }
62 const std::byte& operator[](
size_t index)
const {
return span_[index]; }
65 using element_type = std::byte;
66 using value_type = std::byte;
67 using size_type = size_t;
68 using difference_type = ptrdiff_t;
69 using pointer = std::byte*;
70 using const_pointer =
const std::byte*;
71 using reference = std::byte&;
72 using const_reference =
const std::byte&;
73 using iterator = std::byte*;
74 using const_iterator =
const std::byte*;
75 using reverse_iterator = std::byte*;
76 using const_reverse_iterator =
const std::byte*;
78 std::byte* begin() {
return span_.data(); }
79 const std::byte* begin()
const {
return cbegin(); }
80 const std::byte* cbegin()
const {
return span_.data(); }
81 std::byte* end() {
return span_.data() + span_.size(); }
82 const std::byte* end()
const {
return cend(); }
83 const std::byte* cend()
const {
return span_.data() + span_.size(); }
142 void Slice(
size_t begin,
size_t end);
175 : region_tracker_(region_tracker),
176 next_in_region_(nullptr),
177 prev_in_region_(nullptr),
178 next_in_buf_(nullptr),
185 void InsertAfterInRegionList(
Chunk* new_chunk);
186 void InsertBeforeInRegionList(
Chunk* new_chunk);
187 void RemoveFromRegionList();
210 Chunk* next_in_region_;
219 Chunk* prev_in_region_;
327 other.inner_ =
nullptr;
330 inner_ = other.inner_;
331 other.inner_ =
nullptr;
338 return const_cast<std::byte*
>(std::as_const(*this).data());
340 const std::byte* data()
const {
341 return inner_ ==
nullptr ? nullptr : inner_->data();
344 size_t size()
const {
return inner_ ==
nullptr ? 0 : inner_->size(); }
346 std::byte& operator[](
size_t index) {
return data()[index]; }
347 std::byte operator[](
size_t index)
const {
return data()[index]; }
350 using element_type = std::byte;
351 using value_type = std::byte;
352 using size_type = size_t;
353 using difference_type = ptrdiff_t;
354 using pointer = std::byte*;
355 using const_pointer =
const std::byte*;
356 using reference = std::byte&;
357 using const_reference =
const std::byte&;
358 using iterator = std::byte*;
359 using const_iterator =
const std::byte*;
360 using reverse_iterator = std::byte*;
361 using const_reverse_iterator =
const std::byte*;
363 std::byte* begin() {
return data(); }
364 const std::byte* begin()
const {
return cbegin(); }
365 const std::byte* cbegin()
const {
return data(); }
366 std::byte* end() {
return data() + size(); }
367 const std::byte* end()
const {
return cend(); }
368 const std::byte* cend()
const {
return data() + size(); }
370 Chunk& operator*() {
return *inner_; }
371 const Chunk& operator*()
const {
return *inner_; }
372 Chunk* operator->() {
return inner_; }
373 const Chunk* operator->()
const {
return inner_; }
389 Chunk* result = inner_;
std::optional< OwnedChunk > TakeSuffix(size_t bytes_to_take)
void DiscardPrefix(size_t bytes_to_discard)
bool Merge(OwnedChunk &next_chunk)
void Truncate(size_t len)
void Slice(size_t begin, size_t end)
bool ClaimSuffix(size_t bytes_to_claim)
bool ClaimPrefix(size_t bytes_to_claim)
std::optional< OwnedChunk > TakePrefix(size_t bytes_to_take)
bool CanMerge(const Chunk &next_chunk) const
virtual void DeallocateChunkClass(void *)=0
Deallocates a pointer returned by AllocateChunkClass.
virtual ByteSpan Region() const =0
std::optional< OwnedChunk > CreateFirstChunk()
virtual void * AllocateChunkClass()=0
A Chunk-oriented view of a MultiBuf.
Definition: multibuf.h:28
Definition: multibuf.h:245
friend class Chunk
Definition: chunk.h:403
~OwnedChunk()
This method will acquire a mutex and is not IRQ safe.
Definition: chunk.h:335
Chunk * Take() &&
Definition: chunk.h:388