#include <Buffer.h>
Public Member Functions | |
uint32_t | available (void) |
Buffer (uint32_t size=0x100) | |
void | clear (void) |
T | get (void) |
uint32_t | getSize () |
T * | head (void) |
operator int (void) | |
Buffer & | operator= (T data) |
uint32_t | peek (char c) |
void | put (T data) |
~Buffer () | |
Private Attributes | |
T * | _buf |
volatile uint32_t | _rloc |
uint32_t | _size |
volatile uint32_t | _wloc |
A templated software ring buffer
Example:
#include "mbed.h" #include "Buffer.h" Buffer <char> buf; int main() { buf = 'a'; buf.put('b'); char *head = buf.head(); puts(head); char whats_in_there[2] = {0}; int pos = 0; while(buf.available()) { whats_in_there[pos++] = buf; } printf("%c %c\n", whats_in_there[0], whats_in_there[1]); buf.clear(); error("done\n\n\n"); }
Create a Buffer and allocate memory for it
size | The size of the buffer |
Definition at line 27 of file Buffer.cpp.
Destry a Buffer and release it's allocated memory
Definition at line 37 of file Buffer.cpp.
Reset the buffer to 0. Useful if using head() to parse packeted data
Definition at line 51 of file Buffer.cpp.
Get the size of the ring buffer
Definition at line 45 of file Buffer.cpp.
Definition at line 61 of file Buffer.cpp.