Elm
2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
|
#include <elm/util/Buffer.h>
Public Member Functions | |
Buffer (t::size size=default_size) | |
Buffer (char *buf, t::size size) | |
~Buffer () | |
t::size | size () const |
char | operator[] (t::size i) const |
char & | operator[] (t::size i) |
void | copyTo (void *p, t::size size, t::size offset=0) const |
void | copyFrom (void *p, t::size size, t::size offset=0) |
template<class F > | |
void | read (F f, t::size size, t::size offset=0) const |
template<class F > | |
void | write (F f, t::size size, t::size offset=0) |
Static Public Attributes | |
static const t::size | default_size = 4096 |
The intent of this class is to provide a simple way to prevent errors like buffer-overful by controlling precisely its accesses.
There are different to use a buffer:
In case of an invalid access to the buffer, the exception @BufferException is thrown.
|
inline |
Build and allocate a buffer of the given size. The bytes are automatically allocated and released.
size | Buffer size (default to default_size). |
Build buffer around the given bytes.
buf | Bytes to use. |
size | Size of the given byte buffer. |
|
inline |
Copy a range of bytes into the buffer.
p | Pointer to bytes to copy into the buffer. |
size | Size of range to copy. |
offset | Offset in the buffer to copy to (default to 0). |
References elm::array::copy(), elm::io::p(), and Buffer::size().
Copy a range of bytes from the buffer to the given memory.
p | Pointer to memory to copy to. |
size | Size of range to copy. |
offset | Offset in the buffer of bytes to copy (default to 0). |
References elm::array::copy(), elm::io::p(), and Buffer::size().
|
inline |
|
inline |
Read bytes from the buffer in a controlled way using the given function. This supposes that the function f is not buggy.
f | Function used to read from the buffer. Must be of type void(const char *, t::size). |
size | Size of bytes to read. |
offset | Offset in the buffer to read from (default to 0). |
References Buffer::size().
|
inline |
Get the size of the buffer.
Referenced by Buffer::copyFrom(), Buffer::copyTo(), Buffer::read(), and Buffer::write().
Write bytes in the buffer using a function in a controlled way. This supposes that the function f is not buggy.
f | Function used to write to the buffer. Must be of type void(char *, t::size). |
size | Size of bytes to write. |
offset | Offset in the buffer to write to (default to 0). |
References Buffer::size().