1#ifndef LIBFILEZILLA_NONOWNING_BUFFER_HEADER
2#define LIBFILEZILLA_NONOWNING_BUFFER_HEADER
22class FZ_PUBLIC_SYMBOL nonowning_buffer final
25 constexpr nonowning_buffer()
noexcept =
default;
27 explicit nonowning_buffer(uint8_t *
buffer,
size_t capacity) noexcept
33 explicit nonowning_buffer(uint8_t *
buffer,
size_t capacity,
size_t size) noexcept
38 if (size > capacity) {
44 nonowning_buffer(nonowning_buffer
const&) =
default;
45 nonowning_buffer& operator=(nonowning_buffer
const&) =
default;
47 nonowning_buffer(nonowning_buffer &&)
noexcept =
default;
48 nonowning_buffer& operator=(nonowning_buffer &&)
noexcept =
default;
50 ~nonowning_buffer()
noexcept =
default;
52 size_t capacity()
const {
return capacity_; }
53 size_t size()
const {
return size_; }
54 bool empty()
const {
return size_ == 0; }
55 explicit operator bool()
const {
return !empty(); }
64 void clear() {
resize(0); }
67 uint8_t
operator[](
size_t offset) {
return *(buffer_ + start_ + offset); }
70 uint8_t
const*
get()
const {
return buffer_ + start_; }
71 uint8_t * get() {
return buffer_ + start_; }
81 uint8_t*
get(
size_t bytes);
88 void add(
size_t bytes);
98 void append(uint8_t
const* data,
size_t len);
99 void append(uint8_t c) { append(&c, 1); }
101 std::string_view to_view()
const;
The buffer class is a simple buffer where data can be appended at the end and consumed at the front....
Definition buffer.hpp:27
void consume(size_t bytes)
Removes consumed bytes from the beginning of the buffer.
void resize(size_t size)
Resizes the buffer.
uint8_t operator[](size_t offset)
Gets element at offset. No safety check.
Definition nonowning_buffer.hpp:67
uint8_t const * get() const
Gets buffer.
Definition nonowning_buffer.hpp:70
uint8_t * get(size_t bytes)
Returns a writable buffer guaranteed to be large enough for write_size bytes, call add when done.
void add(size_t bytes)
Grows size by passed amount.
Sets some global macros and further includes string.hpp.
The namespace used by libfilezilla.
Definition apply.hpp:17