Im not sure how much use anyone will find this, but thought I might post it anyways.
I doubt that this is anywhere near top of line (if there is such a thing as a top of line circular buffer), but it should do the trick.
The implementation and header files are attached, just add the following couple of lines to a suitable spot in your code.
Code: Select all
// Required definitions for CircBuffer
typedef int data_block;
#define BUFFER_SIZE 200
You can modify the "typedef int data_block" to reflect whatever type of data you are going to be storing in the buffer. For example, if you are reading in bytes of data from a serial port you can change it to be "typedef wxByte data_block" (or whatever byte implementation you prefer to use).
BUFFER_SIZE can obviously be changed to be whatever size you want/need it to be.
There are only 3 functions in this class
Writes one "block" of data in to the buffer. Returns true on successful completion, false if the buffer overflows (no other action is taken in the event of a buffer overflow, it is up to the user to ensure the buffer is of sufficient size to prevent an overflow occurring).
Reads one "block" of data in to the passed variable. False is returned if the buffer is empty and the passed variable is set to NULL, true on successful completion.
Returns the current size of the buffer (the number of blocks that haven't been read yet).