Thrill
0.1
|
BufferBuilder represents a dynamically growable area of memory, which can be modified by appending integral data types via Put() and other basic operations.
Definition at line 42 of file buffer_builder.hpp.
#include <buffer_builder.hpp>
Public Member Functions | |
Construction, Movement, Destruction | |
BufferBuilder ()=default | |
Create a new empty object. More... | |
BufferBuilder (const BufferBuilder &other) | |
Copy-Constructor, duplicates memory content. More... | |
BufferBuilder (BufferBuilder &&other) noexcept | |
Move-Constructor, moves memory area. More... | |
BufferBuilder (const void *data, size_t size) | |
Constructor, copy memory area. More... | |
BufferBuilder (size_t size) | |
Constructor, create object with n bytes pre-allocated. More... | |
BufferBuilder (const std::string &str) | |
Constructor from std::string, COPIES string content. More... | |
BufferBuilder & | operator= (const BufferBuilder &other) |
Assignment operator: copy other's memory range into buffer. More... | |
BufferBuilder & | operator= (BufferBuilder &&other) noexcept |
Move-Assignment operator: move other's memory area into buffer. More... | |
~BufferBuilder () | |
Destroys the memory space. More... | |
BufferBuilder & | Deallocate () |
Data, Size, and Capacity Accessors | |
const Byte * | data () const |
Return a pointer to the currently kept memory area. More... | |
Byte * | data () |
Return a writeable pointer to the currently kept memory area. More... | |
size_t | size () const |
Return the currently used length in bytes. More... | |
size_t | capacity () const |
Return the currently allocated buffer capacity. More... | |
Buffer Growing, Clearing, and other Management | |
BufferBuilder & | Clear () |
Clears the memory contents, does not deallocate the memory. More... | |
BufferBuilder & | set_size (size_t n) |
BufferBuilder & | Reserve (size_t n) |
Make sure that at least n bytes are allocated. More... | |
BufferBuilder & | DynReserve (size_t n) |
const Byte * | Detach () |
Detach the memory from the object, returns the memory pointer. More... | |
std::string | ToString () const |
Explicit conversion to std::string (copies memory of course). More... | |
Buffer | ToBuffer () |
Explicit conversion to Buffer MOVING the memory ownership. More... | |
Assignment or Alignment | |
BufferBuilder & | Assign (const void *data, size_t len) |
BufferBuilder & | Assign (const BufferBuilder &other) |
BufferBuilder & | Align (size_t n) |
Align the size of the buffer to a multiple of n. Fills up with 0s. More... | |
Appending Write Functions | |
BufferBuilder & | Append (const void *data, size_t len) |
Append a memory range to the buffer. More... | |
BufferBuilder & | Append (const class BufferBuilder &bb) |
Append the contents of a different buffer object to this one. More... | |
BufferBuilder & | AppendString (const std::string &s) |
template<typename Type > | |
BufferBuilder & | Put (const Type &item) |
BufferBuilder & | PutByte (Byte data) |
Put a single byte to the buffer (used via CRTP from ItemWriterToolsBase) More... | |
template<typename Type > | |
BufferBuilder & | PutRaw (const Type &item) |
Access | |
iterator | begin () |
return mutable iterator to first element More... | |
const_iterator | begin () const |
return constant iterator to first element More... | |
const_iterator | cbegin () const |
return constant iterator to first element More... | |
iterator | end () |
return mutable iterator beyond last element More... | |
const_iterator | end () const |
return constant iterator beyond last element More... | |
const_iterator | cend () const |
return constant iterator beyond last element More... | |
reference | operator[] (size_t i) |
return the i-th position of the vector More... | |
Public Member Functions inherited from ItemWriterToolsBase< BufferBuilder > | |
BufferBuilder & | PutString (const char *data, size_t len) |
Put a string by saving it's length followed by the data itself. More... | |
BufferBuilder & | PutString (const uint8_t *data, size_t len) |
Put a string by saving it's length followed by the data itself. More... | |
BufferBuilder & | PutString (const std::string &str) |
Put a string by saving it's length followed by the data itself. More... | |
BufferBuilder & | PutVarint (uint64_t v) |
Append a varint to the writer. More... | |
BufferBuilder & | PutVarint32 (uint32_t v) |
Append a varint to the writer. More... | |
Private Types | |
using | Byte = unsigned char |
type used to store the bytes More... | |
using | const_iterator = const Byte * |
simple pointer iterators More... | |
using | const_reference = const Byte & |
simple pointer references More... | |
using | iterator = Byte * |
simple pointer iterators More... | |
using | reference = Byte & |
simple pointer references More... | |
Private Attributes | |
size_t | capacity_ = 0 |
Total capacity of buffer. More... | |
Byte * | data_ = nullptr |
Allocated buffer pointer. More... | |
size_t | size_ = 0 |
Size of valid data. More... | |
|
private |
type used to store the bytes
Definition at line 47 of file buffer_builder.hpp.
|
private |
simple pointer iterators
Definition at line 52 of file buffer_builder.hpp.
|
private |
simple pointer references
Definition at line 56 of file buffer_builder.hpp.
simple pointer iterators
Definition at line 50 of file buffer_builder.hpp.
simple pointer references
Definition at line 54 of file buffer_builder.hpp.
|
default |
Create a new empty object.
|
inline |
Copy-Constructor, duplicates memory content.
Definition at line 75 of file buffer_builder.hpp.
References BufferBuilder::Assign().
|
inlinenoexcept |
Move-Constructor, moves memory area.
Definition at line 80 of file buffer_builder.hpp.
|
inline |
Constructor, copy memory area.
Definition at line 88 of file buffer_builder.hpp.
References BufferBuilder::Assign().
|
inlineexplicit |
Constructor, create object with n bytes pre-allocated.
Definition at line 93 of file buffer_builder.hpp.
References BufferBuilder::Reserve().
|
inlineexplicit |
Constructor from std::string, COPIES string content.
Definition at line 98 of file buffer_builder.hpp.
References BufferBuilder::Assign().
|
inline |
Destroys the memory space.
Definition at line 126 of file buffer_builder.hpp.
References BufferBuilder::Deallocate().
|
inline |
Align the size of the buffer to a multiple of n. Fills up with 0s.
Definition at line 263 of file buffer_builder.hpp.
References BufferBuilder::DynReserve().
|
inline |
Append a memory range to the buffer.
Definition at line 284 of file buffer_builder.hpp.
References BufferBuilder::data(), and BufferBuilder::DynReserve().
Referenced by BufferBuilder::Append(), and BufferBuilder::AppendString().
|
inline |
Append the contents of a different buffer object to this one.
Definition at line 295 of file buffer_builder.hpp.
References BufferBuilder::Append(), BufferBuilder::data(), and BufferBuilder::size().
|
inline |
Append to contents of a std::string, excluding the null (which isn't contained in the string size anyway).
Definition at line 301 of file buffer_builder.hpp.
References BufferBuilder::Append().
Referenced by WriteLinesNode< ValueType >::PreOp().
|
inline |
Copy a memory range into the buffer, overwrites all current data. Roughly equivalent to clear() followed by append().
Definition at line 243 of file buffer_builder.hpp.
References BufferBuilder::data(), and BufferBuilder::Reserve().
Referenced by BufferBuilder::Assign(), BufferBuilder::BufferBuilder(), and BufferBuilder::operator=().
|
inline |
Copy the contents of another buffer object into this buffer, overwrites all current data. Roughly equivalent to clear() followed by append().
Definition at line 255 of file buffer_builder.hpp.
References BufferBuilder::Assign(), BufferBuilder::data(), and BufferBuilder::size().
|
inline |
return mutable iterator to first element
Definition at line 339 of file buffer_builder.hpp.
References BufferBuilder::data_.
Referenced by BufferBuilder::cbegin(), ReadLinesNode::InputLineIteratorUncompressed::HasNext(), ReadLinesNode::InputLineIteratorCompressed::InputLineIteratorCompressed(), ReadLinesNode::InputLineIteratorUncompressed::Next(), ReadLinesNode::InputLineIteratorCompressed::Next(), BufferBuilder::operator[](), and ReadLinesNode::InputLineIterator::ReadBlock().
|
inline |
return constant iterator to first element
Definition at line 342 of file buffer_builder.hpp.
References BufferBuilder::data_.
|
inline |
Return the currently allocated buffer capacity.
Definition at line 161 of file buffer_builder.hpp.
References BufferBuilder::capacity_.
|
inline |
return constant iterator to first element
Definition at line 345 of file buffer_builder.hpp.
References BufferBuilder::begin().
|
inline |
return constant iterator beyond last element
Definition at line 355 of file buffer_builder.hpp.
References BufferBuilder::end().
|
inline |
Clears the memory contents, does not deallocate the memory.
Definition at line 171 of file buffer_builder.hpp.
|
inline |
Return a pointer to the currently kept memory area.
Definition at line 146 of file buffer_builder.hpp.
References BufferBuilder::data_.
Referenced by BufferBuilder::Append(), BufferBuilder::Assign(), BufferBuilder::Detach(), BufferBuilder::operator=(), WriteLinesNode< ValueType >::PreOp(), BufferBuilder::PutByte(), ReadLinesNode::InputLineIterator::ReadBlock(), Connection::ReceiveSend(), Connection::Send(), Connection::SendN(), Connection::SendReceive(), and WriteLinesNode< ValueType >::StopPreOp().
|
inline |
Return a writeable pointer to the currently kept memory area.
Definition at line 151 of file buffer_builder.hpp.
References BufferBuilder::data_.
|
inline |
Deallocates the kept memory space (we use dealloc() instead of free() as a name, because sometimes "free" is replaced by the preprocessor)
Definition at line 132 of file buffer_builder.hpp.
References free().
Referenced by BufferBuilder::~BufferBuilder().
|
inline |
Detach the memory from the object, returns the memory pointer.
Definition at line 217 of file buffer_builder.hpp.
References BufferBuilder::data(), and BufferBuilder::data_.
Referenced by BufferBuilder::ToBuffer().
|
inline |
Dynamically allocate more memory. At least n bytes will be available, probably more to compensate future growth.
Definition at line 198 of file buffer_builder.hpp.
References BufferBuilder::capacity_, and BufferBuilder::Reserve().
Referenced by BufferBuilder::Align(), BufferBuilder::Append(), and BufferBuilder::Put().
|
inline |
return mutable iterator beyond last element
Definition at line 349 of file buffer_builder.hpp.
References BufferBuilder::size_.
Referenced by BufferBuilder::cend(), ReadLinesNode::InputLineIteratorCompressed::HasNext(), ReadLinesNode::InputLineIteratorUncompressed::InputLineIteratorUncompressed(), ReadLinesNode::InputLineIteratorUncompressed::Next(), and ReadLinesNode::InputLineIteratorCompressed::Next().
|
inline |
return constant iterator beyond last element
Definition at line 352 of file buffer_builder.hpp.
References BufferBuilder::size_.
|
inline |
Assignment operator: copy other's memory range into buffer.
Definition at line 103 of file buffer_builder.hpp.
References BufferBuilder::Assign(), BufferBuilder::data(), and BufferBuilder::size().
|
inlinenoexcept |
Move-Assignment operator: move other's memory area into buffer.
Definition at line 111 of file buffer_builder.hpp.
References free().
|
inline |
return the i-th position of the vector
Definition at line 359 of file buffer_builder.hpp.
References BufferBuilder::begin().
|
inline |
Put (append) a single item of the template type T to the buffer. Be careful with implicit type conversions!
Definition at line 308 of file buffer_builder.hpp.
References BufferBuilder::DynReserve(), and BufferBuilder::size_.
Referenced by StreamMultiplexerHeader::Serialize(), and PartitionMultiplexerHeader::Serialize().
|
inline |
Put a single byte to the buffer (used via CRTP from ItemWriterToolsBase)
Definition at line 322 of file buffer_builder.hpp.
References BufferBuilder::data().
Referenced by WriteLinesNode< ValueType >::PreOp().
|
inline |
Put (append) a single item of the template type T to the buffer. Be careful with implicit type conversions!
Definition at line 329 of file buffer_builder.hpp.
|
inline |
Make sure that at least n bytes are allocated.
Definition at line 186 of file buffer_builder.hpp.
References realloc().
Referenced by BufferBuilder::Assign(), BufferBuilder::BufferBuilder(), BufferBuilder::DynReserve(), ReadLinesNode::InputLineIteratorCompressed::InputLineIteratorCompressed(), ReadLinesNode::InputLineIteratorUncompressed::InputLineIteratorUncompressed(), StreamMultiplexerHeader::Serialize(), PartitionMultiplexerHeader::Serialize(), and WriteLinesNode< ValueType >::StartPreOp().
|
inline |
Set the valid bytes in the buffer, use if the buffer is filled directly.
Definition at line 178 of file buffer_builder.hpp.
Referenced by ReadLinesNode::InputLineIteratorCompressed::InputLineIteratorCompressed(), WriteLinesNode< ValueType >::PreOp(), and ReadLinesNode::InputLineIterator::ReadBlock().
|
inline |
Return the currently used length in bytes.
Definition at line 156 of file buffer_builder.hpp.
References BufferBuilder::size_.
Referenced by BufferBuilder::Append(), BufferBuilder::Assign(), ReadLinesNode::InputLineIteratorCompressed::HasNext(), ReadLinesNode::InputLineIteratorUncompressed::InputLineIteratorUncompressed(), ReadLinesNode::InputLineIteratorUncompressed::Next(), BufferBuilder::operator=(), WriteLinesNode< ValueType >::PreOp(), Connection::ReceiveSend(), Connection::Send(), Connection::SendN(), and Connection::SendReceive().
|
inline |
Explicit conversion to Buffer MOVING the memory ownership.
Definition at line 230 of file buffer_builder.hpp.
References Buffer::Acquire(), and BufferBuilder::Detach().
Referenced by StreamSink::AppendPinnedBlock(), and StreamSet< StreamData >::OnWriterClosed().
|
inline |
Explicit conversion to std::string (copies memory of course).
Definition at line 225 of file buffer_builder.hpp.
|
private |
Total capacity of buffer.
Definition at line 65 of file buffer_builder.hpp.
Referenced by BufferBuilder::capacity(), and BufferBuilder::DynReserve().
|
private |
Allocated buffer pointer.
Definition at line 59 of file buffer_builder.hpp.
Referenced by BufferBuilder::begin(), BufferBuilder::data(), and BufferBuilder::Detach().
|
private |
Size of valid data.
Definition at line 62 of file buffer_builder.hpp.
Referenced by BufferBuilder::end(), BufferBuilder::Put(), and BufferBuilder::size().