55 return static_cast<int>(*_begin);
63 return static_cast<int>(result);
66 size_t read(
char* dst,
size_t size) {
67 size_t bytes_available =
getSize();
68 size_t size_to_read = (size < bytes_available) ? size : bytes_available;
69 size_t size_read = size_to_read;
70 if(_end < _begin && size_to_read > (
size_t)(
_bufend -
_begin)) {
72 memcpy(dst, _begin, top_size);
74 size_to_read -= top_size;
77 memcpy(dst,
_begin, size_to_read);
83 if(
room() == 0)
return 0;
90 size_t write(
const char* src,
size_t size) {
91 size_t bytes_available =
room();
92 size_t size_to_write = (size < bytes_available) ? size : bytes_available;
93 size_t size_written = size_to_write;
96 memcpy(_end, src, top_size);
98 size_to_write -= top_size;
101 memcpy(
_end, src, size_to_write);
char * wrap_if_bufend(char *ptr)
Definition: cbuf.h:112
size_t write(const char *src, size_t size)
Definition: cbuf.h:90
~cbuf()
Definition: cbuf.h:31
size_t write(char c)
Definition: cbuf.h:82
const size_t _size
Definition: cbuf.h:116
void flush()
Definition: cbuf.h:106
char * _end
Definition: cbuf.h:120
cbuf(size_t size)
Definition: cbuf.h:27
char * _buf
Definition: cbuf.h:117
const char *const _bufend
Definition: cbuf.h:118
int peek()
Definition: cbuf.h:52
char * _begin
Definition: cbuf.h:119
size_t room() const
Definition: cbuf.h:41
size_t read(char *dst, size_t size)
Definition: cbuf.h:66
bool empty() const
Definition: cbuf.h:48
size_t getSize() const
Definition: cbuf.h:35
int read()
Definition: cbuf.h:58