19#include "pw_allocator/allocator.h"
20#include "pw_allocator/shared_ptr.h"
21#include "pw_assert/assert.h"
22#include "pw_bytes/span.h"
24namespace pw::multibuf::v1_adapter {
30class BasicSimpleAllocator;
57 metadata_allocator_ = other.metadata_allocator_;
58 region_ = other.region_;
65 std::byte* data() {
return span_.data(); }
66 const std::byte* data()
const {
return span_.data(); }
68 size_t size()
const {
return span_.size(); }
70 [[nodiscard]]
bool empty()
const {
return span_.empty(); }
72 std::byte& operator[](
size_t index) {
return span_[index]; }
73 const std::byte& operator[](
size_t index)
const {
return span_[index]; }
80 return metadata_allocator_;
90 using element_type = std::byte;
91 using value_type = std::byte;
92 using size_type = size_t;
93 using difference_type = ptrdiff_t;
94 using pointer = std::byte*;
95 using const_pointer =
const std::byte*;
96 using reference = std::byte&;
97 using const_reference =
const std::byte&;
98 using iterator = std::byte*;
99 using const_iterator =
const std::byte*;
100 using reverse_iterator = std::byte*;
101 using const_reverse_iterator =
const std::byte*;
103 std::byte* begin() {
return span_.data(); }
104 const std::byte* begin()
const {
return cbegin(); }
105 const std::byte* cbegin()
const {
return span_.data(); }
106 std::byte* end() {
return span_.data() + span_.size(); }
107 const std::byte* end()
const {
return cend(); }
108 const std::byte* cend()
const {
return span_.data() + span_.size(); }
130 void Slice(
size_t begin,
size_t end);
165 using element_type = std::byte;
166 using value_type = std::byte;
167 using size_type = size_t;
168 using difference_type = ptrdiff_t;
169 using pointer = std::byte*;
170 using const_pointer =
const std::byte*;
171 using reference = std::byte&;
172 using const_reference =
const std::byte&;
173 using iterator = std::byte*;
174 using const_iterator =
const std::byte*;
175 using reverse_iterator = std::byte*;
176 using const_reverse_iterator =
const std::byte*;
181 : inner_(
Chunk(metadata_allocator, data)) {}
193 std::byte* data() {
return inner_.has_value() ? inner_->data() :
nullptr; }
194 const std::byte* data()
const {
195 return inner_.has_value() ? inner_->data() :
nullptr;
198 size_t size()
const {
return inner_.has_value() ? inner_->size() : 0; }
200 std::byte& operator[](
size_t index) {
return data()[index]; }
201 std::byte operator[](
size_t index)
const {
return data()[index]; }
203 Chunk& operator*() {
return *inner_; }
204 const Chunk& operator*()
const {
return *inner_; }
205 Chunk* operator->() {
return &(*inner_); }
206 const Chunk* operator->()
const {
return &(*inner_); }
210 std::byte* begin() {
return data(); }
211 const std::byte* begin()
const {
return cbegin(); }
212 const std::byte* cbegin()
const {
return data(); }
213 std::byte* end() {
return data() + size(); }
214 const std::byte* end()
const {
return cend(); }
215 const std::byte* cend()
const {
return data() + size(); }
227 std::optional<Chunk>
Take() && {
228 std::optional<Chunk> result = std::move(inner_);
236 std::optional<Chunk> inner_;
Definition: allocator.h:45
Definition: shared_ptr.h:68
bool ClaimPrefix(size_t bytes_to_claim)
bool Merge(OwnedChunk &next_chunk)
bool CanMerge(const Chunk &next_chunk) const
void Slice(size_t begin, size_t end)
void Truncate(size_t len)
constexpr Allocator * metadata_allocator() const
Definition: chunk.h:79
std::optional< OwnedChunk > TakePrefix(size_t bytes_to_take)
std::optional< OwnedChunk > TakeSuffix(size_t bytes_to_take)
void DiscardPrefix(size_t bytes_to_discard)
bool ClaimSuffix(size_t bytes_to_claim)
constexpr const SharedPtr< std::byte[]> & region() const
Definition: chunk.h:87
Definition: multibuf.h:38
std::optional< Chunk > Take() &&
Definition: chunk.h:227
void Release()
Definition: chunk.h:220