geopm
3.1.1.dev296+g5916b956
GEOPM - Global Extensible Open Power Manager
|
Templated container for a circular buffer implementation. The CircularBuffer container implements a fixed size buffer. Once at capacity, any new insertions cause the oldest entry to be dropped. More...
#include <CircularBuffer.hpp>
Public Member Functions | |
CircularBuffer () | |
CircularBuffer (unsigned int size) | |
Constructor for the CircularBuffer template. More... | |
virtual | ~CircularBuffer () |
CircularBuffer destructor, virtual. More... | |
void | set_capacity (const unsigned int size) |
Re-size the circular buffer. More... | |
void | clear (void) |
Clears all entries from the buffer. More... | |
int | size (void) const |
Size of the buffer contents. More... | |
int | capacity (void) const |
Capacity of the buffer. More... | |
void | insert (const type value) |
Insert a value into the buffer. More... | |
const type & | value (const int index) const |
Returns a constant reference to the value from the buffer. More... | |
std::vector< type > | make_vector (void) const |
Create a vector from the entire circular buffer contents. More... | |
std::vector< type > | make_vector (const unsigned int start, const unsigned int end) const |
Create a vector slice from the circular buffer contents. More... | |
Templated container for a circular buffer implementation. The CircularBuffer container implements a fixed size buffer. Once at capacity, any new insertions cause the oldest entry to be dropped.
geopm::CircularBuffer< type >::CircularBuffer |
geopm::CircularBuffer< type >::CircularBuffer | ( | unsigned int | size | ) |
Constructor for the CircularBuffer template.
Creates an empty circular buffer with a set capacity.
[in] | size | Requested capacity for the buffer. |
|
virtual |
CircularBuffer destructor, virtual.
int geopm::CircularBuffer< type >::capacity | ( | void | ) | const |
Capacity of the buffer.
Returns the current size of the circular buffer at the time of the call.
void geopm::CircularBuffer< type >::clear | ( | void | ) |
Clears all entries from the buffer.
The size becomes 0, but the capacity is unchanged.
void geopm::CircularBuffer< type >::insert | ( | const type | value | ) |
Insert a value into the buffer.
If the buffer is not full, the new value is simply added to the buffer. It the buffer is at capacity, The head of the buffer is dropped and moved to the next oldest entry and the new value is then inserted at the end of the buffer.
[in] | value | The value to be inserted. |
std::vector< type > geopm::CircularBuffer< type >::make_vector | ( | const unsigned int | start, |
const unsigned int | end | ||
) | const |
Create a vector slice from the circular buffer contents.
[in] | start | Start index (inclusive). |
[in] | end | End index (exclusive). |
geopm::Exception | if start or end index is out of bounds or if end index is smaller than start index |
std::vector< type > geopm::CircularBuffer< type >::make_vector | ( | void | ) | const |
Create a vector from the entire circular buffer contents.
void geopm::CircularBuffer< type >::set_capacity | ( | const unsigned int | size | ) |
Re-size the circular buffer.
Grows or shrinks the capacity of the circular buffer. If the new capacity is greater than the size, then the current contents will not be modified. If the new capacity is smaller than the size, then only the newest elements of the difference will be retained.
[in] | size | Requested new capacity for the buffer. |
int geopm::CircularBuffer< type >::size | ( | void | ) | const |
Size of the buffer contents.
Returns the number of items in the buffer. This value will be less than or equal to the current capacity of the buffer.
const type & geopm::CircularBuffer< type >::value | ( | const int | index | ) | const |
Returns a constant reference to the value from the buffer.
Accesses the contents of the circular buffer at a particular index. Valid positive indices range from 0 to [size-1]. Valid negative indices range from -1 to -size. Negative indices work just like python indices, to represent nth-most-recent insertions. For example, -1 is the last element, -2 is the second to last element, and so on. Where size is the number of valid entries in the buffer. An out of bounds index is > [size-1] OR < [-size]. An attempt to retrieve a value for an out of bound index will throw a geopm::Exception with an error_value() of GEOPM_ERROR_INVALID.
[in] | index | Buffer index to retrieve. |