C++/Tree Mapping Runtime Library
|
Simple binary buffer abstraction. More...
#include <buffer.hxx>
Public Types | |
typedef std::size_t | size_t |
Size type. | |
Constructors | |
buffer (size_t size=0) | |
Allocate a buffer of the specified size. | |
buffer (size_t size, size_t capacity) | |
Allocate a buffer of the specified size and capacity. | |
buffer (const void *data, size_t size) | |
Allocate a buffer of the specified size and copy the data. | |
buffer (const void *data, size_t size, size_t capacity) | |
Allocate a buffer of the specified size and capacity and copy the data. | |
buffer (void *data, size_t size, size_t capacity, bool assume_ownership) | |
Reuse an existing buffer. | |
buffer (const buffer &x) | |
Copy constructor. | |
buffer & | operator= (const buffer &x) |
Copy assignment operator. | |
size_t | capacity () const |
Get buffer's capacity. | |
bool | capacity (size_t c) |
Set buffer's capacity. | |
size_t | size () const |
Get buffer's size. | |
bool | size (size_t s) |
Set buffer's size. | |
const char * | data () const |
Get the underlying memory region. | |
char * | data () |
Get the underlying memory region. | |
const char * | begin () const |
Get the beginning of the underlying memory region. | |
char * | begin () |
Get the beginning of the underlying memory region. | |
const char * | end () const |
Get the end of the underlying memory region. | |
char * | end () |
Get the end of the underlying memory region. | |
void | swap (buffer &x) |
Swap data with another buffer. | |
Simple binary buffer abstraction.
The buffer class manages a continuous binary buffer. The base concepts are data (actual memory region), size (the portion of the buffer that contains useful information), and capacity (the actual size of the underlying memory region). The bounds exception is thrown from the constructors and modifier functions if the (size <= capacity) constraint is violated.
Note that the template parameter is only used to instantiate exception types. The underlying buffer type is always char
.
Allocate a buffer of the specified size.
The resulting buffer has the same size and capacity.
size | A buffer size in bytes. |
Allocate a buffer of the specified size and capacity.
size | A buffer size in bytes. |
capacity | A buffer capacity in bytes. |
bounds | If size exceeds capacity |
Allocate a buffer of the specified size and copy the data.
The resulting buffer has the same size and capacity with size bytes copied from data.
data | A buffer to copy the data from. |
size | A buffer size in bytes. |
Allocate a buffer of the specified size and capacity and copy the data.
size bytes are copied from data to the resulting buffer.
data | A buffer to copy the data from. |
size | A buffer size in bytes. |
capacity | A buffer capacity in bytes. |
bounds | If size exceeds capacity |
Reuse an existing buffer.
If the assume_ownership argument is true, the buffer will assume ownership of data and will release the memory by calling operator
delete()
.
data | A buffer to reuse. |
size | A buffer size in bytes. |
capacity | A buffer capacity in bytes. |
assume_ownership | A boolean value indication whether to assume ownership. |
bounds | If size exceeds capacity |
Copy constructor.
The copy constructor performs a deep copy of the underlying memory buffer.
x | An instance to make a copy of. |
Copy assignment operator.
The copy assignment operator changes the buffer's capacity to x.capacity()
and copies x.size()
bytes from x.
x | An instance to assign. |
|
inline |
Get buffer's capacity.
Referenced by buffer< C >::capacity(), and buffer< C >::size().
|
inline |
Set buffer's capacity.
c | The new capacity in bytes. |
References buffer< C >::capacity().
|
inline |
Get buffer's size.
Referenced by xsd::cxx::tree::operator==().
|
inline |
Set buffer's size.
s | The new size in bytes. |
References buffer< C >::capacity().
|
inline |
Get the underlying memory region.
Referenced by xsd::cxx::tree::operator==().
|
inline |
Get the underlying memory region.
|
inline |
Get the beginning of the underlying memory region.
|
inline |
Get the beginning of the underlying memory region.
|
inline |
Get the end of the underlying memory region.
begin
() +
size
() ).
|
inline |
Get the end of the underlying memory region.
begin
() +
size
() ). void swap | ( | buffer< C > & | x | ) |
Swap data with another buffer.
x | A buffer to swap with. |