Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of esp8266-driver by
MyBuffer< T > Class Template Reference
A templated software ring buffer. More...
#include <MyBuffer.h>
Public Member Functions | |
| MyBuffer (uint32_t size=0x100) | |
| Create a Buffer and allocate memory for it. | |
| uint32_t | getSize () |
| Get the size of the ring buffer. | |
| ~MyBuffer () | |
| 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. | |
| MyBuffer & | 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 MyBuffer< T >
A templated software ring buffer.
Example:
#include "mbed.h" #include "MyBuffer.h" MyBuffer <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 MyBuffer.h.
Constructor & Destructor Documentation
| MyBuffer | ( | 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 MyBuffer.cpp.
| ~MyBuffer | ( | ) |
Destry a Buffer and release it's allocated memory.
Definition at line 37 of file MyBuffer.cpp.
Member Function Documentation
| uint32_t available | ( | void | ) |
Determine if anything is readable in the buffer.
- Returns:
- 1 if something can be read, 0 otherwise
Definition at line 157 of file MyBuffer.h.
| void clear | ( | void | ) |
Reset the buffer to 0.
Useful if using head() to parse packeted data
Definition at line 51 of file MyBuffer.cpp.
| T get | ( | void | ) |
Remove a data element from the buffer.
- Returns:
- Pull the oldest element from the buffer
Definition at line 140 of file MyBuffer.h.
| uint32_t getSize | ( | ) |
Get the size of the ring buffer.
- Returns:
- the size of the ring buffer
Definition at line 45 of file MyBuffer.cpp.
| T * head | ( | void | ) |
Get the address to the head of the buffer.
- Returns:
- The address of element 0 in the buffer
Definition at line 149 of file MyBuffer.h.
| operator int | ( | void | ) |
Overloaded operator for reading from the buffer.
- Returns:
- Pull the oldest element from the buffer
Definition at line 121 of file MyBuffer.h.
| MyBuffer& operator= | ( | T | data ) |
Overloaded operator for writing to the buffer.
- Parameters:
-
data Something to put in the buffer
- Returns:
Definition at line 112 of file MyBuffer.h.
| void put | ( | T | data ) |
Add a data element into the buffer.
- Parameters:
-
data Something to add to the buffer
Definition at line 131 of file MyBuffer.h.
Generated on Wed Jul 13 2022 08:30:02 by
1.7.2
