libcommonc++
0.7
|
An encapsulation of a block of memory. More...
#include <MemoryBlock.h++>
Public Member Functions | |
MemoryBlock (byte_t *base=NULL, size_t size=0) | |
Construct a new MemoryBlock. More... | |
virtual | ~MemoryBlock () |
Destructor. More... | |
void | zero () |
Zero the memory block. More... | |
void | fill (byte_t value) |
Fill the memory block with the given byte value. More... | |
byte_t * | getBase () |
Get a pointer to the beginning of the memory block. More... | |
const byte_t * | getBase () const |
Get a pointer to the beginning of the memory block. More... | |
virtual void | setBase (byte_t *base) |
Set the pointer to the beginning of the memory block. More... | |
size_t | getSize () const |
Get the size of the memory block. More... | |
void | setSize (size_t size) |
Set the size of the memory block. More... | |
bool | operator== (const MemoryBlock &other) const |
Equality operator. More... | |
bool | operator!= (const MemoryBlock &other) const |
Inequality operator. More... | |
byte_t | operator[] (int index) const |
Bounds-checked access. More... | |
byte_t & | operator[] (int index) |
Bounds-checked access. More... | |
bool | copyFrom (const MemoryBlock &other) |
Copy data from another memory block to this one. More... | |
void | moveFrom (MemoryBlock &other) |
Copy data from another (possibly overlapping) memory block to this one. More... | |
int | indexOf (byte_t val, uint_t startIndex=0) const |
Find the first occurrence of a given byte value in the memory block, starting at a given index. More... | |
bool | operator! () const |
Test if the base of the block is NULL. More... | |
Protected Attributes | |
byte_t * | _base |
A pointer to the beginning of the memory block. More... | |
size_t | _size |
The size of the memory block, in bytes. More... | |
An encapsulation of a block of memory.
The class supports various bounds-checked memory operations.
|
inline |
Construct a new MemoryBlock.
base | The pointer to the beginning of the memory block. |
size | The size of the memory block, in bytes. |
|
inlinevirtual |
Destructor.
bool copyFrom | ( | const MemoryBlock & | other | ) |
Copy data from another memory block to this one.
The number of bytes copied is the minimum of the sizes of the two blocks. The blocks may not overlap.
other | The block to copy from. |
void fill | ( | byte_t | value | ) |
Fill the memory block with the given byte value.
|
inline |
Get a pointer to the beginning of the memory block.
|
inline |
Get a pointer to the beginning of the memory block.
|
inline |
Get the size of the memory block.
Find the first occurrence of a given byte value in the memory block, starting at a given index.
val | The value to search for. |
startIndex | The index to begin searching at. |
void moveFrom | ( | MemoryBlock & | other | ) |
Copy data from another (possibly overlapping) memory block to this one.
The number of bytes copied is the minimum of the sizes of the two blocks.
other | The block to copy from. Note that the copy may result in both blocks being modified, if the source area overlaps the target area. |
|
inline |
Test if the base of the block is NULL.
|
inline |
Inequality operator.
bool operator== | ( | const MemoryBlock & | other | ) | const |
Equality operator.
byte_t operator[] | ( | int | index | ) | const |
Bounds-checked access.
OutOfBoundsException | If the index is out of bounds. |
byte_t & operator[] | ( | int | index | ) |
Bounds-checked access.
OutOfBoundsException | If the index is out of bounds. |
|
inlinevirtual |
Set the pointer to the beginning of the memory block.
Reimplemented in SharedMemoryBlock.
|
inline |
Set the size of the memory block.
|
inline |
Zero the memory block.
|
protected |
A pointer to the beginning of the memory block.
|
protected |
The size of the memory block, in bytes.