Belle II Software development
|
dynamic character buffer that knows its size. More...
#include <MsgHandler.h>
Public Member Functions | |
CharBuffer (size_t initial_capacity=0) | |
Constructor, with the initial capacity of the buffer to allocate (in bytes). | |
void | add (const void *data, size_t len) |
copy data to end of buffer, expanding buffer if needed. | |
char * | data () |
return raw pointer. | |
size_t | size () const |
return buffer size (do not access data() beyond this) | |
void | clear () |
reset (without deallocating) | |
void | resize (size_t size) |
resize, similar to std::vector<char>::resize in that it will copy the existing buffer to a new, larger buffer if needed but it will not initialize any elements beyond the existing elements | |
Private Attributes | |
std::unique_ptr< char[]> | m_data |
data buffer. | |
size_t | m_capacity {0} |
size of allocated memory in m_data | |
size_t | m_size {0} |
current size, <= m_capacity | |
dynamic character buffer that knows its size.
This is similar to std::vector<char> but compared with std::vector<char> this saves unnecessary calls to memset() when adding a block. (std::vector initialises memory on allocation, this class does not).
Definition at line 30 of file MsgHandler.h.
|
inlineexplicit |
Constructor, with the initial capacity of the buffer to allocate (in bytes).
size() will remain zero until buffer is filled.
Definition at line 38 of file MsgHandler.h.
|
inline |
copy data to end of buffer, expanding buffer if needed.
This can invalidate previous pointers obtained by data() if the buffer needs to be expanded.
Definition at line 43 of file MsgHandler.h.
|
inline |
|
inline |
|
inline |
resize, similar to std::vector<char>::resize in that it will copy the existing buffer to a new, larger buffer if needed but it will not initialize any elements beyond the existing elements
Definition at line 60 of file MsgHandler.h.
|
inline |
|
private |
size of allocated memory in m_data
Definition at line 32 of file MsgHandler.h.
|
private |
data buffer.
Definition at line 31 of file MsgHandler.h.
|
private |
current size, <= m_capacity
Definition at line 33 of file MsgHandler.h.