MemoryBlock Class Reference

An encapsulation of a block of memory. More...

#include <MemoryBlock.h++>

Inheritance diagram for MemoryBlock:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 MemoryBlock (byte_t *base=NULL, size_t size=0) throw ()
 Construct a new MemoryBlock.
virtual ~MemoryBlock () throw ()
 Destructor.
void zero () throw ()
 Zero the memory block.
void fill (byte_t value) throw ()
 Fill the memory block with the given byte value.
byte_tgetBase () throw ()
 Get a pointer to the beginning of the memory block.
const byte_tgetBase () const throw ()
 Get a pointer to the beginning of the memory block.
virtual void setBase (byte_t *base) throw ()
 Set the pointer to the beginning of the memory block.
size_t getSize () const throw ()
 Get the size of the memory block.
void setSize (size_t size) throw ()
 Set the size of the memory block.
bool operator== (const MemoryBlock &other) const throw ()
 Equality operator.
bool operator!= (const MemoryBlock &other) const throw ()
 Inequality operator.
byte_t operator[] (int index) const throw (OutOfBoundsException)
 Bounds-checked access.
byte_toperator[] (int index) throw (OutOfBoundsException)
 Bounds-checked access.
bool copyFrom (const MemoryBlock &other) throw ()
 Copy data from another memory block to this one.
void moveFrom (MemoryBlock &other) throw ()
 Copy data from another (possibly overlapping) memory block to this one.
int indexOf (byte_t val, uint_t startIndex=0) const throw ()
 Find the first occurrence of a given byte value in the memory block, starting at a given index.
bool operator! () const throw ()
 Test if the base of the block is NULL.

Protected Attributes

byte_t_base
 A pointer to the beginning of the memory block.
size_t _size
 The size of the memory block, in bytes.

Detailed Description

An encapsulation of a block of memory.

The class supports various bounds-checked memory operations.

Author:
Mark Lindner

Constructor & Destructor Documentation

MemoryBlock ( byte_t base = NULL,
size_t  size = 0 
) throw () [inline]

Construct a new MemoryBlock.

Parameters:
base The pointer to the beginning of the memory block.
size The size of the memory block, in bytes.
virtual ~MemoryBlock (  )  throw () [inline, virtual]

Destructor.


Member Function Documentation

bool copyFrom ( const MemoryBlock other  )  throw ()

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.

Parameters:
other The block to copy from.
Returns:
true if the copy succeeded, false if the blocks overlap.
void fill ( byte_t  value  )  throw ()

Fill the memory block with the given byte value.

const byte_t* getBase (  )  const throw () [inline]

Get a pointer to the beginning of the memory block.

byte_t* getBase (  )  throw () [inline]

Get a pointer to the beginning of the memory block.

size_t getSize (  )  const throw () [inline]

Get the size of the memory block.

int indexOf ( byte_t  val,
uint_t  startIndex = 0 
) const throw ()

Find the first occurrence of a given byte value in the memory block, starting at a given index.

Parameters:
val The value to search for.
startIndex The index to begin searching at.
Returns:
The index of the first matching value, or -1 if not found.
void moveFrom ( MemoryBlock other  )  throw ()

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.

Parameters:
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.
bool operator! (  )  const throw () [inline]

Test if the base of the block is NULL.

bool operator!= ( const MemoryBlock other  )  const throw () [inline]

Inequality operator.

bool operator== ( const MemoryBlock other  )  const throw ()

Equality operator.

byte_t & operator[] ( int  index  )  throw (OutOfBoundsException)

Bounds-checked access.

byte_t operator[] ( int  index  )  const throw (OutOfBoundsException)

Bounds-checked access.

virtual void setBase ( byte_t base  )  throw () [inline, virtual]

Set the pointer to the beginning of the memory block.

Reimplemented in SharedMemoryBlock.

void setSize ( size_t  size  )  throw () [inline]

Set the size of the memory block.

Reimplemented in SharedMemoryBlock.

void zero (  )  throw () [inline]

Zero the memory block.


Member Data Documentation

byte_t* _base [protected]

A pointer to the beginning of the memory block.

size_t _size [protected]

The size of the memory block, in bytes.


The documentation for this class was generated from the following files:
Generated on Sat Nov 26 16:49:09 2011 for libcommonc++ by  doxygen 1.6.3