libcommonc++  0.7
MemoryBlock Class Reference

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

#include <MemoryBlock.h++>

Inheritance diagram for MemoryBlock:

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_tgetBase ()
 Get a pointer to the beginning of the memory block. More...
 
const byte_tgetBase () 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_toperator[] (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...
 

Detailed Description

An encapsulation of a block of memory.

The class supports various bounds-checked memory operations.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ MemoryBlock()

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

Construct a new MemoryBlock.

Parameters
baseThe pointer to the beginning of the memory block.
sizeThe size of the memory block, in bytes.

◆ ~MemoryBlock()

virtual ~MemoryBlock ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ copyFrom()

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.

Parameters
otherThe block to copy from.
Returns
true if the copy succeeded, false if the blocks overlap.

◆ fill()

void fill ( byte_t  value)

Fill the memory block with the given byte value.

◆ getBase() [1/2]

byte_t* getBase ( )
inline

Get a pointer to the beginning of the memory block.

◆ getBase() [2/2]

const byte_t* getBase ( ) const
inline

Get a pointer to the beginning of the memory block.

◆ getSize()

size_t getSize ( ) const
inline

Get the size of the memory block.

◆ indexOf()

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.

Parameters
valThe value to search for.
startIndexThe index to begin searching at.
Returns
The index of the first matching value, or -1 if not found.

◆ moveFrom()

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.

Parameters
otherThe block to copy from. Note that the copy may result in both blocks being modified, if the source area overlaps the target area.

◆ operator!()

bool operator! ( ) const
inline

Test if the base of the block is NULL.

◆ operator!=()

bool operator!= ( const MemoryBlock other) const
inline

Inequality operator.

◆ operator==()

bool operator== ( const MemoryBlock other) const

Equality operator.

◆ operator[]() [1/2]

byte_t operator[] ( int  index) const

Bounds-checked access.

Exceptions
OutOfBoundsExceptionIf the index is out of bounds.

◆ operator[]() [2/2]

byte_t & operator[] ( int  index)

Bounds-checked access.

Exceptions
OutOfBoundsExceptionIf the index is out of bounds.

◆ setBase()

virtual void setBase ( byte_t base)
inlinevirtual

Set the pointer to the beginning of the memory block.

Reimplemented in SharedMemoryBlock.

◆ setSize()

void setSize ( size_t  size)
inline

Set the size of the memory block.

◆ zero()

void zero ( )
inline

Zero the memory block.

Member Data Documentation

◆ _base

byte_t* _base
protected

A pointer to the beginning of the memory block.

◆ _size

size_t _size
protected

The size of the memory block, in bytes.


The documentation for this class was generated from the following files: