Thrill  0.1
BufferBuilder Class Reference

Detailed Description

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.

+ Inheritance diagram for BufferBuilder:
+ Collaboration diagram for BufferBuilder:

#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...
 
BufferBuilderoperator= (const BufferBuilder &other)
 Assignment operator: copy other's memory range into buffer. More...
 
BufferBuilderoperator= (BufferBuilder &&other) noexcept
 Move-Assignment operator: move other's memory area into buffer. More...
 
 ~BufferBuilder ()
 Destroys the memory space. More...
 
BufferBuilderDeallocate ()
 
Data, Size, and Capacity Accessors
const Bytedata () const
 Return a pointer to the currently kept memory area. More...
 
Bytedata ()
 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
BufferBuilderClear ()
 Clears the memory contents, does not deallocate the memory. More...
 
BufferBuilderset_size (size_t n)
 
BufferBuilderReserve (size_t n)
 Make sure that at least n bytes are allocated. More...
 
BufferBuilderDynReserve (size_t n)
 
const ByteDetach ()
 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
BufferBuilderAssign (const void *data, size_t len)
 
BufferBuilderAssign (const BufferBuilder &other)
 
BufferBuilderAlign (size_t n)
 Align the size of the buffer to a multiple of n. Fills up with 0s. More...
 
Appending Write Functions
BufferBuilderAppend (const void *data, size_t len)
 Append a memory range to the buffer. More...
 
BufferBuilderAppend (const class BufferBuilder &bb)
 Append the contents of a different buffer object to this one. More...
 
BufferBuilderAppendString (const std::string &s)
 
template<typename Type >
BufferBuilderPut (const Type &item)
 
BufferBuilderPutByte (Byte data)
 Put a single byte to the buffer (used via CRTP from ItemWriterToolsBase) More...
 
template<typename Type >
BufferBuilderPutRaw (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...
 
Bytedata_ = nullptr
 Allocated buffer pointer. More...
 
size_t size_ = 0
 Size of valid data. More...
 

Member Typedef Documentation

◆ Byte

using Byte = unsigned char
private

type used to store the bytes

Definition at line 47 of file buffer_builder.hpp.

◆ const_iterator

using const_iterator = const Byte *
private

simple pointer iterators

Definition at line 52 of file buffer_builder.hpp.

◆ const_reference

using const_reference = const Byte&
private

simple pointer references

Definition at line 56 of file buffer_builder.hpp.

◆ iterator

using iterator = Byte *
private

simple pointer iterators

Definition at line 50 of file buffer_builder.hpp.

◆ reference

using reference = Byte&
private

simple pointer references

Definition at line 54 of file buffer_builder.hpp.

Constructor & Destructor Documentation

◆ BufferBuilder() [1/6]

BufferBuilder ( )
default

Create a new empty object.

◆ BufferBuilder() [2/6]

BufferBuilder ( const BufferBuilder other)
inline

Copy-Constructor, duplicates memory content.

Definition at line 75 of file buffer_builder.hpp.

References BufferBuilder::Assign().

◆ BufferBuilder() [3/6]

BufferBuilder ( BufferBuilder &&  other)
inlinenoexcept

Move-Constructor, moves memory area.

Definition at line 80 of file buffer_builder.hpp.

◆ BufferBuilder() [4/6]

BufferBuilder ( const void *  data,
size_t  size 
)
inline

Constructor, copy memory area.

Definition at line 88 of file buffer_builder.hpp.

References BufferBuilder::Assign().

◆ BufferBuilder() [5/6]

BufferBuilder ( size_t  size)
inlineexplicit

Constructor, create object with n bytes pre-allocated.

Definition at line 93 of file buffer_builder.hpp.

References BufferBuilder::Reserve().

◆ BufferBuilder() [6/6]

BufferBuilder ( const std::string &  str)
inlineexplicit

Constructor from std::string, COPIES string content.

Definition at line 98 of file buffer_builder.hpp.

References BufferBuilder::Assign().

◆ ~BufferBuilder()

~BufferBuilder ( )
inline

Destroys the memory space.

Definition at line 126 of file buffer_builder.hpp.

References BufferBuilder::Deallocate().

Member Function Documentation

◆ Align()

BufferBuilder& Align ( size_t  n)
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().

◆ Append() [1/2]

BufferBuilder& Append ( const void *  data,
size_t  len 
)
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().

◆ Append() [2/2]

BufferBuilder& Append ( const class BufferBuilder bb)
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().

◆ AppendString()

BufferBuilder& AppendString ( const std::string &  s)
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().

◆ Assign() [1/2]

BufferBuilder& Assign ( const void *  data,
size_t  len 
)
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=().

◆ Assign() [2/2]

BufferBuilder& Assign ( const BufferBuilder other)
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().

◆ begin() [1/2]

◆ begin() [2/2]

const_iterator begin ( ) const
inline

return constant iterator to first element

Definition at line 342 of file buffer_builder.hpp.

References BufferBuilder::data_.

◆ capacity()

size_t capacity ( ) const
inline

Return the currently allocated buffer capacity.

Definition at line 161 of file buffer_builder.hpp.

References BufferBuilder::capacity_.

◆ cbegin()

const_iterator cbegin ( ) const
inline

return constant iterator to first element

Definition at line 345 of file buffer_builder.hpp.

References BufferBuilder::begin().

◆ cend()

const_iterator cend ( ) const
inline

return constant iterator beyond last element

Definition at line 355 of file buffer_builder.hpp.

References BufferBuilder::end().

◆ Clear()

BufferBuilder& Clear ( )
inline

Clears the memory contents, does not deallocate the memory.

Definition at line 171 of file buffer_builder.hpp.

◆ data() [1/2]

◆ data() [2/2]

Byte* data ( )
inline

Return a writeable pointer to the currently kept memory area.

Definition at line 151 of file buffer_builder.hpp.

References BufferBuilder::data_.

◆ Deallocate()

BufferBuilder& Deallocate ( )
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().

◆ Detach()

const Byte* Detach ( )
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().

◆ DynReserve()

BufferBuilder& DynReserve ( size_t  n)
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().

◆ end() [1/2]

◆ end() [2/2]

const_iterator end ( ) const
inline

return constant iterator beyond last element

Definition at line 352 of file buffer_builder.hpp.

References BufferBuilder::size_.

◆ operator=() [1/2]

BufferBuilder& operator= ( const BufferBuilder other)
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().

◆ operator=() [2/2]

BufferBuilder& operator= ( BufferBuilder &&  other)
inlinenoexcept

Move-Assignment operator: move other's memory area into buffer.

Definition at line 111 of file buffer_builder.hpp.

References free().

◆ operator[]()

reference operator[] ( size_t  i)
inline

return the i-th position of the vector

Definition at line 359 of file buffer_builder.hpp.

References BufferBuilder::begin().

◆ Put()

BufferBuilder& Put ( const Type &  item)
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().

◆ PutByte()

BufferBuilder& PutByte ( Byte  data)
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().

◆ PutRaw()

BufferBuilder& PutRaw ( const Type &  item)
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.

◆ Reserve()

◆ set_size()

BufferBuilder& set_size ( size_t  n)
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().

◆ size()

◆ ToBuffer()

Buffer ToBuffer ( )
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().

◆ ToString()

std::string ToString ( ) const
inline

Explicit conversion to std::string (copies memory of course).

Definition at line 225 of file buffer_builder.hpp.

Member Data Documentation

◆ capacity_

size_t capacity_ = 0
private

Total capacity of buffer.

Definition at line 65 of file buffer_builder.hpp.

Referenced by BufferBuilder::capacity(), and BufferBuilder::DynReserve().

◆ data_

Byte* data_ = nullptr
private

Allocated buffer pointer.

Definition at line 59 of file buffer_builder.hpp.

Referenced by BufferBuilder::begin(), BufferBuilder::data(), and BufferBuilder::Detach().

◆ size_

size_t size_ = 0
private

Size of valid data.

Definition at line 62 of file buffer_builder.hpp.

Referenced by BufferBuilder::end(), BufferBuilder::Put(), and BufferBuilder::size().


The documentation for this class was generated from the following file: