hamcast
Version 0.7
|
#include <const_buffer.hpp>
Inherits noncopyable.
Public Types | |
typedef boost::uint32_t | size_type |
Public Member Functions | |
const_buffer () | |
const_buffer (size_type buf_size, const void *buf) | |
const_buffer (size_type buf_size, void *buf, bool ownership) | |
~const_buffer () | |
void | swap (const_buffer &other) |
void | reset () |
void | reset (size_type buf_size, const void *buf) |
void | reset (size_type buf_size, void *buf, bool ownership) |
size_type | size () const |
bool | ownership () const |
const void * | data () const |
bool | empty () const |
std::pair< size_type, void * > | take () |
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.
ownership() == false
. char*
if ownership() == true
because the dtor calls delete[] reinterpret_cast<char*>(data)
. typedef boost::uint32_t hamcast::util::const_buffer::size_type |
The used integer type to store the size of the buffer.
hamcast::util::const_buffer::const_buffer | ( | ) |
Creates a buffer without data and size() == 0.
hamcast::util::const_buffer::const_buffer | ( | const_buffer::size_type | buf_size, |
const void * | buf | ||
) |
Creates a buffer without ownership.
buf_size | The size of buf . |
buf | The const C-buffer. |
buf
must stay valid for the whole lifetime of this object. hamcast::util::const_buffer::const_buffer | ( | const_buffer::size_type | buf_size, |
void * | buf, | ||
bool | ownership | ||
) |
Creates a buffer with optional ownership.
buf_size | The size of buf . |
buf | The C-buffer. |
ownership | Denotes if this object should take ownership of buf . |
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
.
delete[] reinterpret_cast<char*>(data)
if the const buffer has ownership of its data. const void* hamcast::util::const_buffer::data | ( | ) | const |
Get the data of this buffer.
bool hamcast::util::const_buffer::empty | ( | ) | const |
bool hamcast::util::const_buffer::ownership | ( | ) | const |
Check if the buffer owns its data.
true
if this object owns the internal C-buffer; otherwise false
. void hamcast::util::const_buffer::reset | ( | ) |
Equivalent to const_buffer().swap(*this)
.
void hamcast::util::const_buffer::reset | ( | size_type | buf_size, |
const void * | buf | ||
) |
Equivalent to const_buffer(buf_size, buf).swap(*this)
.
buf_size | The size of buf . |
buf | The new const buffer. |
void hamcast::util::const_buffer::reset | ( | size_type | buf_size, |
void * | buf, | ||
bool | ownership | ||
) |
Equivalent to const_buffer(...).swap(*this)
.
buf_size | The size of buf . |
buf | The new buffer. |
ownership | Denotes if this object should take ownership of buf . |
size_type hamcast::util::const_buffer::size | ( | ) | const |
Get the size of data().
void hamcast::util::const_buffer::swap | ( | const_buffer & | other | ) |
Exchange the contents of the two buffers.
other | The const_buffer that should be swapped with this object. |
std::pair< const_buffer::size_type, void * > hamcast::util::const_buffer::take | ( | ) |
Get the internal buffer and reset the buffer afterwards.
!ownership()
. ownership() || empty()
.