libfilezilla
Toggle main menu visibility
Loading...
Searching...
No Matches
lib
libfilezilla
nonowning_buffer.hpp
Go to the documentation of this file.
1
#ifndef LIBFILEZILLA_NONOWNING_BUFFER_HEADER
2
#define LIBFILEZILLA_NONOWNING_BUFFER_HEADER
3
4
#include "
libfilezilla.hpp
"
5
6
#include <cstdint>
7
11
12
namespace
fz
{
13
24
class
FZ_PUBLIC_SYMBOL nonowning_buffer final
25
{
26
public
:
27
constexpr
nonowning_buffer()
noexcept
=
default
;
28
29
explicit
nonowning_buffer(uint8_t *
buffer
,
size_t
capacity) noexcept
30
: buffer_(
buffer
)
31
, capacity_(capacity)
32
{
33
}
34
35
explicit
nonowning_buffer(uint8_t *
buffer
,
size_t
capacity,
size_t
size) noexcept
36
: buffer_(
buffer
)
37
, capacity_(capacity)
38
, size_(size)
39
{
40
if
(size > capacity) {
41
abort();
42
}
43
}
44
45
// Copy is shallow!
46
nonowning_buffer(nonowning_buffer
const
&) =
default
;
47
nonowning_buffer& operator=(nonowning_buffer
const
&) =
default
;
48
49
nonowning_buffer(nonowning_buffer &&)
noexcept
=
default
;
50
nonowning_buffer& operator=(nonowning_buffer &&)
noexcept
=
default
;
51
52
~nonowning_buffer()
noexcept
=
default
;
53
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(); }
58
65
void
resize
(
size_t
size);
66
void
clear() {
resize
(0); }
67
69
uint8_t
operator[]
(
size_t
offset) {
return
*(buffer_ + start_ + offset); }
70
72
uint8_t
const
*
get
()
const
{
return
buffer_ + start_; }
73
uint8_t * get() {
return
buffer_ + start_; }
74
83
uint8_t*
get
(
size_t
bytes);
84
90
void
add
(
size_t
bytes);
91
96
void
consume
(
size_t
bytes);
97
98
void
reset();
99
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);
103
104
std::string_view to_view()
const
;
105
106
private
:
107
uint8_t* buffer_{};
108
size_t
capacity_{};
109
size_t
size_{};
110
size_t
start_{};
111
};
112
}
113
114
#endif
fz::buffer
Definition
buffer.hpp:201
fz::nonowning_buffer::consume
void consume(size_t bytes)
Removes consumed bytes from the beginning of the buffer.
fz::nonowning_buffer::resize
void resize(size_t size)
Resizes the buffer.
fz::nonowning_buffer::operator[]
uint8_t operator[](size_t offset)
Gets element at offset. No safety check.
Definition
nonowning_buffer.hpp:69
fz::nonowning_buffer::get
uint8_t const * get() const
Gets buffer.
Definition
nonowning_buffer.hpp:72
fz::nonowning_buffer::get
uint8_t * get(size_t bytes)
Returns a writable buffer guaranteed to be large enough for write_size bytes, call add when done.
fz::nonowning_buffer::add
void add(size_t bytes)
Grows size by passed amount.
libfilezilla.hpp
Sets some global macros and further includes string.hpp.
fz
The namespace used by libfilezilla.
Definition
apply.hpp:17
Generated by
1.17.0