uLib
User mode C/C++ extended API library for Win32 programmers.
|
#include <uLib/RingBuffer.h>
RingBuffer is a circular buffer that supports heterogenous content.
(This is a beefed up version of one I originally wrote for Arduino.)
RingBuffer supports both preallocated and dynamic buffers.
The RingBuffer::Attach() method also allows You to assign arbitrary backing buffers.
The RingBuffer::GetBlock() and RingBuffer::PutBlock() methods implement burst mode split transfers.
Definition at line 34 of file RingBuffer.h.
Public Data | |
PVOID | UserData |
Public Functions | |
RingBuffer (PBYTE Array, UINT Size) | |
RingBuffer (UINT Size) | |
~RingBuffer () | |
void | Attach (PBYTE Array, UINT Size) |
void | Clear () |
void | Discard (UINT nBytes) |
UINT | Used () |
UINT | Unused () |
bool | Empty () |
bool | Full () |
UINT | Size () |
bool | Get (BYTE *Data) |
bool | Put (BYTE Data) |
bool | GetBlock (BYTE *Data, UINT nBytes) |
bool | PutBlock (BYTE *Data, UINT nBytes) |
bool | GetWord (WORD *Data) |
bool | GetDWord (DWORD *Data) |
bool | GetQWord (UINT64 *Data) |
bool | PutWord (WORD Data) |
bool | PutDWord (DWORD Data) |
bool | PutQWord (UINT64 Data) |
bool | GetStr (ASTR Buf, UINT BufLen) |
bool | PutStr (ACSTR Str, UINT Len=0) |
BYTE & | operator[] (UINT Index) |
RingBuffer::RingBuffer | ( | PBYTE | Array, |
UINT | Size | ||
) |
Use existing buffer.
Definition at line 15 of file RingBuffer.cpp.
RingBuffer::RingBuffer | ( | UINT | Size | ) |
Allocate a heap buffer.
Definition at line 22 of file RingBuffer.cpp.
RingBuffer::~RingBuffer | ( | ) |
Free the buffer if it was allocated by this.
Definition at line 31 of file RingBuffer.cpp.
void RingBuffer::Attach | ( | PBYTE | Array, |
UINT | Size | ||
) |
Use Array as the backing buffer.
Note: Any preexisting data in the array is discarded.
Definition at line 36 of file RingBuffer.cpp.
void RingBuffer::Clear | ( | ) |
Discard all buffer data.
Definition at line 183 of file RingBuffer.cpp.
void RingBuffer::Discard | ( | UINT | nBytes | ) |
Discard partial buffer data.
Definition at line 189 of file RingBuffer.cpp.
UINT RingBuffer::Used | ( | ) |
Nr of bytes stored in buffer.
Definition at line 204 of file RingBuffer.cpp.
UINT RingBuffer::Unused | ( | ) |
Nr of bytes unused buffer space.
Definition at line 212 of file RingBuffer.cpp.
bool RingBuffer::Empty | ( | ) |
Return true if the buffer is empty.
Definition at line 217 of file RingBuffer.cpp.
|
inline |
Return true if the buffer is full.
Definition at line 53 of file RingBuffer.h.
|
inline |
Return the buffer size.
Definition at line 54 of file RingBuffer.h.
bool RingBuffer::Get | ( | BYTE * | Data | ) |
Get next byte. Return false on failure.
Definition at line 44 of file RingBuffer.cpp.
bool RingBuffer::Put | ( | BYTE | Data | ) |
Put a byte in. Return false on failure.
Definition at line 56 of file RingBuffer.cpp.
bool RingBuffer::GetBlock | ( | BYTE * | Data, |
UINT | nBytes | ||
) |
Return false if Count > Used().
Definition at line 118 of file RingBuffer.cpp.
bool RingBuffer::PutBlock | ( | BYTE * | Data, |
UINT | nBytes | ||
) |
Return false if Count > Unused().
Definition at line 91 of file RingBuffer.cpp.
|
inline |
Definition at line 64 of file RingBuffer.h.
|
inline |
Definition at line 65 of file RingBuffer.h.
|
inline |
Definition at line 66 of file RingBuffer.h.
|
inline |
Definition at line 68 of file RingBuffer.h.
|
inline |
Definition at line 69 of file RingBuffer.h.
|
inline |
Definition at line 70 of file RingBuffer.h.
bool RingBuffer::GetStr | ( | ASTR | Buf, |
UINT | BufLen | ||
) |
Get a string from the buffer.
Buf is a buffer that recieves the text, and BufLen it's size (incl null).
If Buf is too small for the string, only BufLen chars are retrieved, and the remainder of the string is discarded.
See also GetBlock(), PutStr().
Definition at line 145 of file RingBuffer.cpp.
bool RingBuffer::PutStr | ( | ACSTR | Str, |
UINT | Len = 0 |
||
) |
Put a string into the buffer.
If Len == 0, the whole string is inserted, else Len chars.
If there's insufficient buffer space, the function returns false.
See also PutBlock(), GetStr().
Definition at line 169 of file RingBuffer.cpp.
BYTE & RingBuffer::operator[] | ( | UINT | Index | ) |
[PRELIMINARY]
The subscript operator enables you to index the circular buffer as a linear array.
The current read position has index == 0, and the last == Used()-1.
Note: This is a peek operation (it doesn't update the tail or head).
You may read or write at the single byte address You recieve, but bear in mind
You can not just memcpy() from the address, since You can't know where the
buffer wraps, and You would most likely address irrelevant data or raise a GPF.
On indexing error, operator[] raises EXCEPTION_RINGBUFFER_INVALID_INDEX.
Definition at line 222 of file RingBuffer.cpp.
PVOID RingBuffer::UserData |
Arbitrary data associated with this instance.
Definition at line 36 of file RingBuffer.h.