ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
CxxUtils::Ring< T > Class Template Reference

A very simple ring buffer. More...

#include <Ring.h>

Collaboration diagram for CxxUtils::Ring< T >:

Public Member Functions

void reset (size_t size)
 Clear the buffer and set its size. More...
 
void push (const T &x)
 Add a new item to the buffer. More...
 
std::vector< T > getKeysDedup () const
 Return a copy of keys in the buffer. More...
 

Private Attributes

std::vector< T > m_data
 
size_t m_pos = 0
 

Detailed Description

template<class T>
class CxxUtils::Ring< T >

A very simple ring buffer.

The payload class T must support comparison and default construction. Default-constructed T's are used to indicate unfilled slots in the buffer.

Start by calling reset to set the size of the buffer. Then push will add new elements to the ring.

The only operation to retrieve values at this point is getKeysDedup. More could be added if needed.

Definition at line 39 of file Ring.h.

Member Function Documentation

◆ getKeysDedup()

template<class T >
std::vector<T> CxxUtils::Ring< T >::getKeysDedup ( ) const

Return a copy of keys in the buffer.

Immediately adjacent duplicates and unfilled entries will be removed, so the result may be smaller than the size of the buffer.

◆ push()

template<class T >
void CxxUtils::Ring< T >::push ( const T &  x)

Add a new item to the buffer.

Parameters
xItem to add.

◆ reset()

template<class T >
void CxxUtils::Ring< T >::reset ( size_t  size)

Clear the buffer and set its size.

Parameters
sizeNew size of the buffer.

Member Data Documentation

◆ m_data

template<class T >
std::vector<T> CxxUtils::Ring< T >::m_data
private

Definition at line 66 of file Ring.h.

◆ m_pos

template<class T >
size_t CxxUtils::Ring< T >::m_pos = 0
private

Definition at line 67 of file Ring.h.


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