Library for Bluetooth Low Energy Module ble 4.0 HM-11
Buffer< T > Class Template Reference
A templated software ring buffer. More...
#include <Buffer.h>
Public Member Functions | |
Buffer (uint32_t size=0x100) | |
Create a Buffer and allocate memory for it. | |
uint32_t | getSize () |
Get the size of the ring buffer. | |
~Buffer () | |
Destry a Buffer and release it's allocated memory. | |
void | put (T data) |
Add a data element into the buffer. | |
T | get (void) |
Remove a data element from the buffer. | |
T * | head (void) |
Get the address to the head of the buffer. | |
void | clear (void) |
Reset the buffer to 0. | |
uint32_t | available (void) |
Determine if anything is readable in the buffer. | |
Buffer & | operator= (T data) |
Overloaded operator for writing to the buffer. | |
operator int (void) | |
Overloaded operator for reading from the buffer. |
Detailed Description
template<typename T>
class Buffer< T >
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"); }
Definition at line 61 of file Buffer.h.
Constructor & Destructor Documentation
Buffer | ( | uint32_t | size = 0x100 ) |
Create a Buffer and allocate memory for it.
- Parameters:
-
size The size of the buffer
Definition at line 27 of file Buffer.cpp.
~Buffer | ( | ) |
Destry a Buffer and release it's allocated memory.
Definition at line 37 of file Buffer.cpp.
Member Function Documentation
uint32_t available | ( | void | ) |
void clear | ( | void | ) |
Reset the buffer to 0.
Useful if using head() to parse packeted data
Definition at line 51 of file Buffer.cpp.
T get | ( | void | ) |
uint32_t getSize | ( | ) |
Get the size of the ring buffer.
- Returns:
- the size of the ring buffer
Definition at line 45 of file Buffer.cpp.
T * head | ( | void | ) |
operator int | ( | void | ) |
Buffer& operator= | ( | T | data ) |
Generated on Tue Jul 12 2022 17:25:07 by 1.7.2