|
wavelength 1.0.0
|
A byte ring buffer that the writer fills and the reader drains one contiguous block at a time. More...
#include <ringbuffer.h>

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 |
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.
|
explicit |
Allocate and clear a buffer of size bytes, rounded down to whole words, with both pointers at its start.
| size | Buffer size in bytes. |
|
virtual |
Free the buffer.
|
virtual |
Record the end-of-stream flag and append bytes, wrapping at mEnd.
The routine does not check the free space.
| data | Bytes to append, or null to record only the flag. |
| size | Byte count, or zero to record only the flag. |
| endOfStream | Whether the writer has no more data. |
Reimplemented in StreamBuffer.
|
pure virtual |
Report the free space to the writer when it has changed.
Implemented in StreamBuffer.
|
virtual |
Discard every byte by moving both pointers to the start of the buffer.
| bool RingBuffer::IsFinished | ( | ) | const |
Report whether the stream has ended and every byte has been read.
| unsigned int RingBuffer::ContiguousFree | ( | ) | const |
Report the space the writer can fill without wrapping, less the reserve.
| bool RingBuffer::IsFull | ( | ) | const |
Report whether ContiguousFree() is zero.
The routine has no caller.
| bool RingBuffer::IsEmpty | ( | ) | const |
Report whether every written byte has been 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.
| maxSize | Largest block wanted. |
| size | Receives the block size. |
| void RingBuffer::Release | ( | void ** | block | ) |
Consume the block Read() returned and notify the writer.
| block | The variable that holds the block. It is cleared. Nothing happens when it is already null. |
| unsigned int RingBuffer::FreeSpace | ( | ) | const |
Report the free space, less the reserve.
| unsigned int RingBuffer::Used | ( | bool * | endOfStream | ) | const |
Report the bytes written and not yet read.
| endOfStream | Receives the end-of-stream flag. |
| void RingBuffer::ClearEndOfStream | ( | ) |
Clear the end-of-stream flag.
The routine has no caller.
| bool RingBuffer::EndOfStream | ( | ) | const |
Report the end-of-stream flag.
The routine has no caller.
|
protected |
Buffer size in bytes.
|
protected |
Start of the buffer.
|
protected |
Next byte to read.
|
protected |
Next byte to write.
|
protected |
End of the buffer.
|
protected |
End of the block Read() returned, or null.
|
protected |
The writer has no more data.
|
protected |
Bytes the space reports hold back.