Holds a buffer that cannot be modified.
More...
#include <const_buffer.hpp>
List of all members.
Detailed Description
Holds a buffer that cannot be modified.
The const_buffer class provides a representation of an immutable buffer. The object deletes the its data if it has ownership but does not modify it otherwise.
- Warning:
- The given (const) buffer must stay valid for the whole lifetime of the buffer object if
ownership() == false
.
-
The data must have the type
char*
if ownership() == true
because the dtor calls delete[] reinterpret_cast<char*>(data)
.
Member Typedef Documentation
The used integer type to store the size of the buffer.
Constructor & Destructor Documentation
hamcast::util::const_buffer::const_buffer |
( |
|
) |
|
Creates a buffer without data and size() == 0.
Creates a buffer without ownership.
- Parameters:
-
| buf_size | The size of buf . |
| buf | The const C-buffer. |
- Warning:
buf
must stay valid for the whole lifetime of this object.
Creates a buffer with optional ownership.
- Parameters:
-
| buf_size | The size of buf . |
| buf | The C-buffer. |
| ownership | Denotes if this object should take ownership of buf . |
- Warning:
buf
must stay valid for the whole lifetime of this object if ownership() == false
.
-
buf
must be allocated with new char[...]
if ownership() == true
.
hamcast::util::const_buffer::~const_buffer |
( |
|
) |
|
Deletes its data if ownership() == false
.
- Warning:
- Calls
delete[] reinterpret_cast<char*>(data)
if the const buffer has ownership of its data.
Member Function Documentation
const void* hamcast::util::const_buffer::data |
( |
|
) |
const |
Get the data of this buffer.
- Returns:
- The internal C-buffer.
bool hamcast::util::const_buffer::empty |
( |
|
) |
const |
Check if the buffer is empty (equivalent to size() == 0
).
- Returns:
true
if size() == 0; otherwise false
bool hamcast::util::const_buffer::ownership |
( |
|
) |
const |
Check if the buffer owns its data.
- Returns:
true
if this object owns the internal C-buffer; otherwise false
.
void hamcast::util::const_buffer::reset |
( |
|
) |
|
void hamcast::util::const_buffer::reset |
( |
size_type |
buf_size, |
|
|
void * |
buf, |
|
|
bool |
ownership | |
|
) |
| | |
Equivalent to const_buffer(...).swap(*this)
.
- Parameters:
-
| buf_size | The size of buf . |
| buf | The new buffer. |
| ownership | Denotes if this object should take ownership of buf . |
void hamcast::util::const_buffer::reset |
( |
size_type |
buf_size, |
|
|
const void * |
buf | |
|
) |
| | |
Equivalent to const_buffer(buf_size, buf).swap(*this)
.
- Parameters:
-
| buf_size | The size of buf . |
| buf | The new const buffer. |
size_type hamcast::util::const_buffer::size |
( |
|
) |
const |
Get the size of data().
- Returns:
- The size of the internal C-buffer.
void hamcast::util::const_buffer::swap |
( |
const_buffer & |
other |
) |
|
Exchange the contents of the two buffers.
- Parameters:
-
| other | The const_buffer that should be swapped with this object. |
The documentation for this class was generated from the following files:
- hamcast/util/const_buffer.hpp
- src/const_buffer.cpp