wavelength 1.0.0
Loading...
Searching...
No Matches
RingBuffer Class Referenceabstract

A byte ring buffer that the writer fills and the reader drains one contiguous block at a time. More...

#include <ringbuffer.h>

Inheritance diagram for RingBuffer:

Public Member Functions

 RingBuffer (unsigned int size)
 Allocate and clear a buffer of size bytes, rounded down to whole words, with both pointers at its start.
virtual ~RingBuffer ()
 Free the buffer.
virtual void Write (const void *data, unsigned int size, bool endOfStream)
 Record the end-of-stream flag and append bytes, wrapping at mEnd.
virtual void Notify ()=0
 Report the free space to the writer when it has changed.
virtual void Reset ()
 Discard every byte by moving both pointers to the start of the buffer.
bool IsFinished () const
 Report whether the stream has ended and every byte has been read.
unsigned int ContiguousFree () const
 Report the space the writer can fill without wrapping, less the reserve.
bool IsFull () const
 Report whether ContiguousFree() is zero.
bool IsEmpty () const
 Report whether every written byte has been read.
void * Read (unsigned int maxSize, unsigned int *size)
 Notify the writer, then return the next contiguous block of at most maxSize bytes.
void Release (void **block)
 Consume the block Read() returned and notify the writer.
unsigned int FreeSpace () const
 Report the free space, less the reserve.
unsigned int Used (bool *endOfStream) const
 Report the bytes written and not yet read.
void ClearEndOfStream ()
 Clear the end-of-stream flag.
bool EndOfStream () const
 Report the end-of-stream flag.

Protected Attributes

unsigned int mSize
char * mBuffer
char * mRead
char * mWrite
char * mEnd
char * mPendingRead
bool mEndOfStream
unsigned int mReserve

Detailed Description

A byte ring buffer that the writer fills and the reader drains one contiguous block at a time.

The module was built without RTTI. The name is inferred from the class's routines.

Bytes are written at mWrite and read at mRead, and both wrap from mEnd to mBuffer. Read() returns a block and records its end in mPendingRead, and Release() moves mRead there. The space report holds mReserve bytes back from the writer.

Constructor & Destructor Documentation

◆ RingBuffer()

RingBuffer::RingBuffer ( unsigned int size)
explicit

Allocate and clear a buffer of size bytes, rounded down to whole words, with both pointers at its start.

Parameters
sizeBuffer size in bytes.
Ghidra address:
NTSC-U/C: 0x00002d70
Ghidra address:
PAL: 0x00002d70

◆ ~RingBuffer()

virtual RingBuffer::~RingBuffer ( )
virtual

Free the buffer.

Ghidra address:
NTSC-U/C: 0x00002e00
Ghidra address:
PAL: 0x00002e00

Member Function Documentation

◆ Write()

virtual void RingBuffer::Write ( const void * data,
unsigned int size,
bool endOfStream )
virtual

Record the end-of-stream flag and append bytes, wrapping at mEnd.

The routine does not check the free space.

Parameters
dataBytes to append, or null to record only the flag.
sizeByte count, or zero to record only the flag.
endOfStreamWhether the writer has no more data.
Ghidra address:
NTSC-U/C: 0x000030b0
Ghidra address:
PAL: 0x000030b0

Reimplemented in StreamBuffer.

◆ Notify()

virtual void RingBuffer::Notify ( )
pure virtual

Report the free space to the writer when it has changed.

Implemented in StreamBuffer.

◆ Reset()

virtual void RingBuffer::Reset ( )
virtual

Discard every byte by moving both pointers to the start of the buffer.

Ghidra address:
NTSC-U/C: 0x00003248
Ghidra address:
PAL: 0x00003248

◆ IsFinished()

bool RingBuffer::IsFinished ( ) const

Report whether the stream has ended and every byte has been read.

Returns
True when the write pointer is at mEnd, or when the buffer is empty and the stream has ended.
Ghidra address:
NTSC-U/C: 0x00002e68
Ghidra address:
PAL: 0x00002e68

◆ ContiguousFree()

unsigned int RingBuffer::ContiguousFree ( ) const

Report the space the writer can fill without wrapping, less the reserve.

Returns
Free bytes.
Ghidra address:
NTSC-U/C: 0x00002ebc
Ghidra address:
PAL: 0x00002ebc

◆ IsFull()

bool RingBuffer::IsFull ( ) const

Report whether ContiguousFree() is zero.

The routine has no caller.

Returns
True when the writer cannot add a byte without wrapping.
Ghidra address:
NTSC-U/C: 0x00002f28
Ghidra address:
PAL: 0x00002f28

◆ IsEmpty()

bool RingBuffer::IsEmpty ( ) const

Report whether every written byte has been read.

Returns
True when the read and write pointers are equal.
Ghidra address:
NTSC-U/C: 0x00002f4c
Ghidra address:
PAL: 0x00002f4c

◆ Read()

void * RingBuffer::Read ( unsigned int maxSize,
unsigned int * size )

Notify the writer, then return the next contiguous block of at most maxSize bytes.

The read pointer moves when Release() runs.

Parameters
maxSizeLargest block wanted.
sizeReceives the block size.
Returns
The block, or null when the buffer is empty or finished.
Ghidra address:
NTSC-U/C: 0x00002f64
Ghidra address:
PAL: 0x00002f64

◆ Release()

void RingBuffer::Release ( void ** block)

Consume the block Read() returned and notify the writer.

Parameters
blockThe variable that holds the block. It is cleared. Nothing happens when it is already null.
Ghidra address:
NTSC-U/C: 0x00003038
Ghidra address:
PAL: 0x00003038

◆ FreeSpace()

unsigned int RingBuffer::FreeSpace ( ) const

Report the free space, less the reserve.

Returns
Free bytes.
Ghidra address:
NTSC-U/C: 0x000031d0
Ghidra address:
PAL: 0x000031d0

◆ Used()

unsigned int RingBuffer::Used ( bool * endOfStream) const

Report the bytes written and not yet read.

Parameters
endOfStreamReceives the end-of-stream flag.
Returns
Used bytes.
Ghidra address:
NTSC-U/C: 0x00003210
Ghidra address:
PAL: 0x00003210

◆ ClearEndOfStream()

void RingBuffer::ClearEndOfStream ( )

Clear the end-of-stream flag.

The routine has no caller.

Ghidra address:
NTSC-U/C: 0x0000325c
Ghidra address:
PAL: 0x0000325c

◆ EndOfStream()

bool RingBuffer::EndOfStream ( ) const

Report the end-of-stream flag.

The routine has no caller.

Returns
The flag.
Ghidra address:
NTSC-U/C: 0x00003264
Ghidra address:
PAL: 0x00003264

Member Data Documentation

◆ mSize

unsigned int RingBuffer::mSize
protected

Buffer size in bytes.

◆ mBuffer

char* RingBuffer::mBuffer
protected

Start of the buffer.

◆ mRead

char* RingBuffer::mRead
protected

Next byte to read.

◆ mWrite

char* RingBuffer::mWrite
protected

Next byte to write.

◆ mEnd

char* RingBuffer::mEnd
protected

End of the buffer.

◆ mPendingRead

char* RingBuffer::mPendingRead
protected

End of the block Read() returned, or null.

◆ mEndOfStream

bool RingBuffer::mEndOfStream
protected

The writer has no more data.

◆ mReserve

unsigned int RingBuffer::mReserve
protected

Bytes the space reports hold back.


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