EpcTools
An event based multi-threaded C++ development framework.
Public Member Functions | List of all members
ECircularBuffer Class Reference

Implements a circular buffer. More...

#include <ecbuf.h>

Public Member Functions

 ECircularBuffer (Int capacity)
 Class constructor. More...
 
 ~ECircularBuffer ()
 Class destructor. More...
 
Void initialize ()
 Initializes the circular buffer. More...
 
Bool isEmpty ()
 True - the buffer is empty, False - there is data in the buffer. More...
 
Int capacity ()
 Returns the maximum capacity of the circular buffer. More...
 
Int used ()
 Returns the number of bytes in use in the buffer. More...
 
Int free ()
 Returns the number of bytes that are free in the buffer. More...
 
Int peekData (pUChar dest, Int offset, Int length)
 Reads data from the buffer without removing it from the buffer. More...
 
Int readData (pUChar dest, Int offset, Int length)
 Reads and removes data from the buffer. More...
 
void writeData (pUChar src, Int offset, Int length, Bool nolock=False)
 Writes data to the circular buffer. More...
 
void modifyData (pUChar src, Int offset, Int length, Bool nolock=False)
 Modifies data within the buffer. More...
 
EMutexPrivategetMutex ()
 Retrieves the mutex;. More...
 

Detailed Description

Implements a circular buffer.

Constructor & Destructor Documentation

◆ ECircularBuffer()

ECircularBuffer::ECircularBuffer ( Int  capacity)

Class constructor.

Parameters
capacityThe maximum number of bytes in the buffer.

◆ ~ECircularBuffer()

ECircularBuffer::~ECircularBuffer ( )

Class destructor.

Member Function Documentation

◆ capacity()

Int ECircularBuffer::capacity ( )
inline

Returns the maximum capacity of the circular buffer.

◆ free()

Int ECircularBuffer::free ( )
inline

Returns the number of bytes that are free in the buffer.

◆ getMutex()

EMutexPrivate& ECircularBuffer::getMutex ( )
inline

Retrieves the mutex;.

Returns
the mutex.

◆ initialize()

Void ECircularBuffer::initialize ( )

Initializes the circular buffer.

◆ isEmpty()

Bool ECircularBuffer::isEmpty ( )
inline

True - the buffer is empty, False - there is data in the buffer.

◆ modifyData()

void ECircularBuffer::modifyData ( pUChar  src,
Int  offset,
Int  length,
Bool  nolock = False 
)

Modifies data within the buffer.

Parameters
srcA pointer to the data that will be written to the buffer.
offsetThe offset within the buffer to start writing.
lengthThe number of bytes to write to the buffer.
nolockTrue bypasses the lock, otherwise the object is locked.
Exceptions
ECircularBufferError_AttemptToModifyDataOutsideBoundsOfCurrentBuffer

Generally speaking, data is written to the head and read from the tail. modifyData updates data starting at the tail, the next data to read. This method was added to support partial socket writes where the message length, the first 4 bytes, needed to updated to reflect the remaining bytes to be written. **** USE WITH EXTREME CAUTION ***

◆ peekData()

Int ECircularBuffer::peekData ( pUChar  dest,
Int  offset,
Int  length 
)
inline

Reads data from the buffer without removing it from the buffer.

Parameters
destA pointer to a buffer where the data will be written.
offsetThe offset in the buffer where to start reading from.
lengthThe number of bytes to read.
Exceptions
ECircularBufferError_HeadAndTailOutOfSync
ECircularBufferError_UsedLessThanZero
ECircularBufferError_TailExceededCapacity

◆ readData()

Int ECircularBuffer::readData ( pUChar  dest,
Int  offset,
Int  length 
)
inline

Reads and removes data from the buffer.

Parameters
destA pointer to a buffer where the data will be written.
offsetThe offset in the buffer where to start reading from.
lengthThe number of bytes to read.

◆ used()

Int ECircularBuffer::used ( )
inline

Returns the number of bytes in use in the buffer.

◆ writeData()

void ECircularBuffer::writeData ( pUChar  src,
Int  offset,
Int  length,
Bool  nolock = False 
)

Writes data to the circular buffer.

Parameters
srcA pointer to the data that will be written to the buffer.
offset*** NOT USED ***
lengthThe number of bytes to write to the buffer.
nolockTrue bypasses the lock, otherwise the object is locked.
Exceptions
ECircularBufferError_AttemptToExceedCapacity
ECircularBufferError_BufferSizeHasBeenExceeded
ECircularBufferError_HeadHasExceededCapacity

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