1#ifndef LIBFILEZILLA_NONOWNING_BUFFER_HEADER
2#define LIBFILEZILLA_NONOWNING_BUFFER_HEADER
24class FZ_PUBLIC_SYMBOL nonowning_buffer final
27 constexpr nonowning_buffer()
noexcept =
default;
29 explicit nonowning_buffer(uint8_t *
buffer,
size_t capacity) noexcept
35 explicit nonowning_buffer(uint8_t *
buffer,
size_t capacity,
size_t size) noexcept
40 if (size > capacity) {
46 nonowning_buffer(nonowning_buffer
const&) =
default;
47 nonowning_buffer& operator=(nonowning_buffer
const&) =
default;
49 nonowning_buffer(nonowning_buffer &&)
noexcept =
default;
50 nonowning_buffer& operator=(nonowning_buffer &&)
noexcept =
default;
52 ~nonowning_buffer()
noexcept =
default;
54 size_t capacity()
const {
return capacity_; }
55 size_t size()
const {
return size_; }
56 bool empty()
const {
return size_ == 0; }
57 explicit operator bool()
const {
return !empty(); }
66 void clear() {
resize(0); }
69 uint8_t
operator[](
size_t offset) {
return *(buffer_ + start_ + offset); }
72 uint8_t
const*
get()
const {
return buffer_ + start_; }
73 uint8_t * get() {
return buffer_ + start_; }
83 uint8_t*
get(
size_t bytes);
90 void add(
size_t bytes);
100 void append(uint8_t
const* data,
size_t len);
101 void append(uint8_t c) { append(&c, 1); }
102 void append(std::string_view
const& str);
104 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:28
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:69
uint8_t const * get() const
Gets buffer.
Definition nonowning_buffer.hpp:72
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