CircularBuffer< TYPE > Class Template Reference
#include <circular_buffer.hpp>
Data Structures | |
| class | const_iterator |
| class | iterator |
Public Types | |
| typedef int | size_type |
Public Member Functions | |
| CircularBuffer (uint32_t capacity) | |
| Constructor with initial capacity as buffer size. More... | |
| CircularBuffer (const CircularBuffer ©) | |
| Copy Constructor. More... | |
| CircularBuffer & | operator= (const CircularBuffer ©) |
| = Operator to copy the buffer More... | |
| ~CircularBuffer () | |
| Destructor of the buffer. More... | |
| bool | push_back (const TYPE data, bool forceWrite=false) |
| TYPE | pop_front (void) |
| bool | pop_front (TYPE *dataPtr) |
| TYPE | peek_front (void) |
| bool | peek_front (TYPE *dataPtr) |
| uint32_t | size (void) const |
| uint32_t | capacity (void) const |
| void | clear (void) |
| Clears the contents of the buffer. More... | |
| void | operator+= (TYPE item) |
| += Operator which is same as push_back() of an item More... | |
| TYPE & | operator[] (uint32_t index) const |
| iterator | begin () |
| iterator | end () |
| const_iterator | begin () const |
| const_iterator | end () const |
Friends | |
| class | iterator |
| Iterator is our friend... More... | |
Detailed Description
template<typename TYPE>
class CircularBuffer< TYPE >
Circular buffer class
Usage:
CircularBuffer <int> b(3);
b.push_back(1);
b.push_back(2);
b.push_back(3);
b.push_back(0); // Will fail since buffer is full
b.push_back(4, true); // Overwrite oldest data
// Read the elements without popping the data, access them using index operator
// Should be "2 3 4" since we previously over-wrote "1" with "4"
printf("\nContents using index operator: ");
for (uint32_t i = 0; i < b.size(); i++) {
printf("%i ", b[i]);
}
// Use the iterator to read data without popping the data off the buffer
// Should be "2 3 4"; same as using the index operator.
printf("\nContents using iterator: ");
for(CircularBuffer<int>::iterator cb = b.begin(); cb != b.end(); ++cb)
{
printf("%i ", *(cb));
}
// Pop the data from the buffer, should pop "2 3 4"
int i = 0;
while (b.pop_front(&i)) {
printf("\nPopped %i", i);
}
Member Typedef Documentation
template<typename TYPE>
| typedef int CircularBuffer< TYPE >::size_type |
Constructor & Destructor Documentation
template<typename TYPE >
| CircularBuffer< TYPE >::CircularBuffer | ( | uint32_t | capacity | ) |
Constructor with initial capacity as buffer size.
template<typename TYPE >
| CircularBuffer< TYPE >::CircularBuffer | ( | const CircularBuffer< TYPE > & | copy | ) |
Copy Constructor.
template<typename TYPE >
| CircularBuffer< TYPE >::~CircularBuffer | ( | ) |
Destructor of the buffer.
Member Function Documentation
template<typename TYPE>
|
inline |
Get iterators
template<typename TYPE>
|
inline |
template<typename TYPE>
|
inline |
- Returns
- the capacity of the circular buffer
template<typename TYPE>
|
inline |
Clears the contents of the buffer.
template<typename TYPE>
|
inline |
template<typename TYPE>
|
inline |
template<typename TYPE>
|
inline |
+= Operator which is same as push_back() of an item
template<typename TYPE >
| CircularBuffer< TYPE > & CircularBuffer< TYPE >::operator= | ( | const CircularBuffer< TYPE > & | copy | ) |
= Operator to copy the buffer
template<typename TYPE>
|
inline |
Index operator. This will always return in the FIFO order, so index 0 represents the OLDEST data. The max index value should not go beyond [getCapacity() - 1]
template<typename TYPE >
| TYPE CircularBuffer< TYPE >::peek_front | ( | void | ) |
- Returns
- the oldest element, but doesn't remove it from the buffer
template<typename TYPE >
| bool CircularBuffer< TYPE >::peek_front | ( | TYPE * | dataPtr | ) |
- Returns
- true if an element is available, and is read into dataPtr
template<typename TYPE >
| TYPE CircularBuffer< TYPE >::pop_front | ( | void | ) |
- Returns
- the oldest element
template<typename TYPE >
| bool CircularBuffer< TYPE >::pop_front | ( | TYPE * | dataPtr | ) |
- Returns
- true if an element is available to be read, and is read to dataPtr
template<typename TYPE >
| bool CircularBuffer< TYPE >::push_back | ( | const TYPE | data, |
| bool | forceWrite = false |
||
| ) |
Write to end of buffer.
- Parameters
-
data The data to write. forceWrite Optional parameter, if true, and the buffer is full, will force a write, discarding oldest data.
- Returns
- true if successful or false if no capacity
If we don't have the capacity, then perform a read() to pop the oldest element, and then cap the count.
template<typename TYPE>
|
inline |
- Returns
- the number of elements in the array
Friends And Related Function Documentation
template<typename TYPE>
|
friend |
Iterator is our friend...
The documentation for this class was generated from the following file:
- /var/www/html/SJSU-DEV-Linux/firmware/default/lib/L3_Utils/circular_buffer.hpp

1.8.11