geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
Public Member Functions | List of all members
geopm::CircularBuffer< type > Class Template Reference

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...
 

Detailed Description

template<class type>
class geopm::CircularBuffer< type >

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.

Constructor & Destructor Documentation

◆ CircularBuffer() [1/2]

template<class type >
geopm::CircularBuffer< type >::CircularBuffer

◆ CircularBuffer() [2/2]

template<class type >
geopm::CircularBuffer< type >::CircularBuffer ( unsigned int  size)

Constructor for the CircularBuffer template.

Creates an empty circular buffer with a set capacity.

Parameters
[in]sizeRequested capacity for the buffer.

◆ ~CircularBuffer()

template<class type >
geopm::CircularBuffer< type >::~CircularBuffer
virtual

CircularBuffer destructor, virtual.

Member Function Documentation

◆ capacity()

template<class type >
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.

Returns
Capacity of the buffer.

◆ clear()

template<class type >
void geopm::CircularBuffer< type >::clear ( void  )

Clears all entries from the buffer.

The size becomes 0, but the capacity is unchanged.

◆ insert()

template<class type >
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.

Parameters
[in]valueThe value to be inserted.

◆ make_vector() [1/2]

template<class type >
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.

Parameters
[in]startStart index (inclusive).
[in]endEnd index (exclusive).
Returns
Vector containing the circular buffer contents at [start, end).
Exceptions
geopm::Exceptionif start or end index is out of bounds or if end index is smaller than start index

◆ make_vector() [2/2]

template<class type >
std::vector< type > geopm::CircularBuffer< type >::make_vector ( void  ) const

Create a vector from the entire circular buffer contents.

Returns
Vector containing the circular buffer contents.

◆ set_capacity()

template<class type >
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.

Parameters
[in]sizeRequested new capacity for the buffer.

◆ size()

template<class type >
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.

Returns
Size of the buffer contents.

◆ value()

template<class type >
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.

Parameters
[in]indexBuffer index to retrieve.
Returns
Value from the specified buffer index.

The documentation for this class was generated from the following file: