Thrill
0.1
|
Simple buffer of characters without initialization or growing functionality.
We use Buffer instead of std::string for handling untyped byte arrays. The advantage of Buffer is that we have guaranteed direct byte access, and that it does not initialize memory (faster). A Buffer object is also non-copyable, which makes sure that we use zero-copy overhead as much as possible.
This Buffer allows memory using malloc()/realloc()/free().
Definition at line 40 of file buffer.hpp.
#include <buffer.hpp>
Public Types | |
using | const_iterator = const value_type * |
simple pointer iterators More... | |
using | const_reference = const value_type & |
simple pointer references More... | |
using | iterator = value_type * |
simple pointer iterators More... | |
using | reference = value_type & |
simple pointer references More... | |
using | size_type = size_t |
size and offset type of buffer More... | |
using | value_type = unsigned char |
value type stored in the buffer More... | |
Public Member Functions | |
Data Access | |
iterator | data () noexcept |
return iterator to beginning of Buffer More... | |
const_iterator | data () const noexcept |
return iterator to beginning of Buffer More... | |
size_type | size () const noexcept |
return number of items in Buffer More... | |
reference | operator[] (size_type i) |
return the i-th position of the Buffer More... | |
const_reference | operator[] (size_type i) const |
return constant reference to the i-th position of the Buffer More... | |
Iterator Access | |
iterator | begin () noexcept |
return mutable iterator to first element More... | |
const_iterator | begin () const noexcept |
return constant iterator to first element More... | |
const_iterator | cbegin () const noexcept |
return constant iterator to first element More... | |
iterator | end () noexcept |
return mutable iterator beyond last element More... | |
const_iterator | end () const noexcept |
return constant iterator beyond last element More... | |
const_iterator | cend () const noexcept |
return constant iterator beyond last element More... | |
Resize and Filling | |
void | Zero () |
Zero the whole array content. More... | |
void | Resize (size_type new_size) |
Private Member Functions | |
Buffer (bool, void *data, size_type size) | |
protected constructor used to acquire ownership of a buffer More... | |
Private Attributes | |
value_type * | data_ |
the buffer, typed as character data More... | |
size_type | size_ |
size of the buffer. More... | |
Construction, Moving, Destruction | |
Buffer () noexcept | |
allocate empty buffer More... | |
Buffer (size_type n) noexcept | |
allocate buffer containing n bytes More... | |
Buffer (const void *data, size_type size) | |
allocate buffer and COPY data into it. More... | |
Buffer (const Buffer &)=delete | |
non-copyable: delete copy-constructor More... | |
Buffer & | operator= (const Buffer &)=delete |
non-copyable: delete assignment operator More... | |
Buffer (Buffer &&other) noexcept | |
move-construct other buffer into this one More... | |
Buffer & | operator= (Buffer &&other) noexcept |
move-assignment of other buffer into this one More... | |
~Buffer () | |
delete buffer More... | |
bool | IsValid () const noexcept |
Check for Buffer contents is valid. More... | |
static Buffer | Acquire (void *data, size_type size) |
void | swap (Buffer &a, Buffer &b) noexcept |
swap buffer with another one More... | |
Output | |
std::string | ToString () const |
copy contents into std::string More... | |
std::string | PartialToString (size_t begin, size_t length) const |
copy part of contents into std::string More... | |
std::ostream & | operator<< (std::ostream &os, const Buffer &b) |
make ostream-able More... | |
using const_iterator = const value_type * |
simple pointer iterators
Definition at line 51 of file buffer.hpp.
using const_reference = const value_type& |
simple pointer references
Definition at line 55 of file buffer.hpp.
using iterator = value_type * |
simple pointer iterators
Definition at line 49 of file buffer.hpp.
using reference = value_type& |
simple pointer references
Definition at line 53 of file buffer.hpp.
using size_type = size_t |
size and offset type of buffer
Definition at line 46 of file buffer.hpp.
using value_type = unsigned char |
value type stored in the buffer
Definition at line 44 of file buffer.hpp.
protected constructor used to acquire ownership of a buffer
Definition at line 59 of file buffer.hpp.
|
inlinenoexcept |
allocate empty buffer
Definition at line 68 of file buffer.hpp.
Referenced by Buffer::Acquire(), and Buffer::Buffer().
allocate buffer containing n bytes
Definition at line 73 of file buffer.hpp.
allocate buffer and COPY data into it.
Definition at line 78 of file buffer.hpp.
References Buffer::Buffer(), Buffer::data(), Buffer::data_, and Buffer::operator=().
move-construct other buffer into this one
Definition at line 90 of file buffer.hpp.
|
inline |
construct Buffer by acquiring ownership of a memory buffer. The memory buffer will be FREE()ed (not delete[]-ed).
Definition at line 110 of file buffer.hpp.
References Buffer::Buffer().
Referenced by BufferRef::ToBuffer(), and BufferBuilder::ToBuffer().
|
inlinenoexcept |
return mutable iterator to first element
Definition at line 160 of file buffer.hpp.
References Buffer::data_.
Referenced by Buffer::cbegin(), Buffer::operator[](), and Connection::SyncRecv().
|
inlinenoexcept |
return constant iterator to first element
Definition at line 163 of file buffer.hpp.
References Buffer::data_.
|
inlinenoexcept |
return constant iterator to first element
Definition at line 166 of file buffer.hpp.
References Buffer::begin().
|
inlinenoexcept |
return constant iterator beyond last element
Definition at line 176 of file buffer.hpp.
References Buffer::end().
|
inlinenoexcept |
return iterator to beginning of Buffer
Definition at line 134 of file buffer.hpp.
References Buffer::data_.
Referenced by Buffer::Buffer(), AsyncReadBuffer::data(), AsyncWriteBuffer::data(), AsyncReadBuffer::operator()(), AsyncWriteBuffer::operator()(), Connection::Receive(), Connection::ReceiveN(), Connection::ReceiveSend(), and Connection::SendReceive().
|
inlinenoexcept |
return iterator to beginning of Buffer
Definition at line 137 of file buffer.hpp.
References Buffer::data_.
|
inlinenoexcept |
return mutable iterator beyond last element
Definition at line 170 of file buffer.hpp.
References Buffer::data_, and Buffer::size_.
Referenced by Buffer::cend(), and Connection::SyncRecv().
|
inlinenoexcept |
return constant iterator beyond last element
Definition at line 173 of file buffer.hpp.
References Buffer::data_, and Buffer::size_.
|
inlinenoexcept |
Check for Buffer contents is valid.
Definition at line 126 of file buffer.hpp.
References Buffer::data_.
non-copyable: delete assignment operator
Referenced by Buffer::Buffer().
move-assignment of other buffer into this one
Definition at line 97 of file buffer.hpp.
References Buffer::data_, free(), and Buffer::size_.
return the i-th position of the Buffer
Definition at line 145 of file buffer.hpp.
References Buffer::begin(), and Buffer::size_.
|
inline |
return constant reference to the i-th position of the Buffer
Definition at line 150 of file buffer.hpp.
References Buffer::begin(), and Buffer::size_.
|
inline |
copy part of contents into std::string
Definition at line 218 of file buffer.hpp.
References Buffer::data_, and Buffer::size_.
|
inline |
resize the array to contain exactly new_size items. This should only be used if the Buffer was default constructed containing an empty array. It should NOT be used to resizing it, since this requires it to copy data.
Definition at line 192 of file buffer.hpp.
References Buffer::data_, LOG1, malloc(), realloc(), and Buffer::size_.
|
inlinenoexcept |
return number of items in Buffer
Definition at line 141 of file buffer.hpp.
References Buffer::size_.
Referenced by StreamSink::AppendPinnedBlock(), AsyncReadBuffer::AsyncReadBuffer(), Dispatcher::AsyncWrite(), AsyncWriteBuffer::AsyncWriteBuffer(), AsyncReadBuffer::DoCallback(), AsyncReadBuffer::IsDone(), AsyncWriteBuffer::IsDone(), StreamSet< StreamData >::OnWriterClosed(), AsyncReadBuffer::operator()(), AsyncWriteBuffer::operator()(), Connection::Receive(), Connection::ReceiveN(), Connection::ReceiveSend(), Connection::RecvNext(), Connection::SendReceive(), AsyncReadBuffer::size(), AsyncWriteBuffer::size(), Connection::SyncRecv(), AsyncReadBuffer::~AsyncReadBuffer(), and AsyncWriteBuffer::~AsyncWriteBuffer().
|
inline |
copy contents into std::string
Definition at line 212 of file buffer.hpp.
References Buffer::data_, and Buffer::size_.
|
inline |
Zero the whole array content.
Definition at line 185 of file buffer.hpp.
References Buffer::data_, and Buffer::size_.
|
friend |
make ostream-able
Definition at line 224 of file buffer.hpp.
swap buffer with another one
Definition at line 119 of file buffer.hpp.
|
private |
the buffer, typed as character data
Definition at line 232 of file buffer.hpp.
Referenced by Buffer::begin(), Buffer::Buffer(), Buffer::data(), Buffer::end(), Buffer::IsValid(), Buffer::operator=(), Buffer::PartialToString(), Buffer::Resize(), Buffer::ToString(), Buffer::Zero(), and Buffer::~Buffer().
|
private |
size of the buffer.
Definition at line 235 of file buffer.hpp.
Referenced by Buffer::end(), Buffer::operator=(), Buffer::operator[](), Buffer::PartialToString(), Buffer::Resize(), Buffer::size(), Buffer::ToString(), and Buffer::Zero().