Quantum 3 3.0.13

Public Member Functions | Public Attributes | Properties | List of all members
Quantum.Core.RingBuffer< T > Class Template Reference

Ring buffer collection implementation. Stores Capacity number of values and will overwrite the oldest value when full. More...

Public Member Functions

 RingBuffer (Int32 capacity)
 Create a new RingBuffer with a given capacity. More...
 
void Clear ()
 Clear the buffer and reset the start and end positions. More...
 
PeekBack (Int32 offset=0)
 Look at the last element in the buffer without removing it. More...
 
PeekFront (Int32 offset=0)
 Look at the first element in the buffer without removing it. More...
 
PopBack ()
 Remove and return the last value in the buffer. More...
 
PopFront ()
 Remove and return the first value in the buffer. More...
 
void PushBack (T item)
 Add a value in the back of the buffer. More...
 
void PushFront (T item)
 Add a value in the front of the buffer. More...
 

Public Attributes

bool IsEmpty => Size == 0
 Check if the buffer is empty. More...
 
bool IsFull => Size == Capacity
 Check if the buffer is full. More...
 
T[] ToArray => array
 Return the underlying array. More...
 

Properties

int Capacity [get]
 The maximum size of the buffer. More...
 
int Size [get]
 The current used size of the buffer. More...
 

Detailed Description

Ring buffer collection implementation. Stores Capacity number of values and will overwrite the oldest value when full.

Template Parameters
TType of data that the collection stores

Constructor & Destructor Documentation

◆ RingBuffer()

Quantum.Core.RingBuffer< T >.RingBuffer ( Int32  capacity)
inline

Create a new RingBuffer with a given capacity.

Parameters
capacityInitial capacity
Exceptions
ArgumentExceptionIs raised the the capacity is invalid.

Member Function Documentation

◆ Clear()

void Quantum.Core.RingBuffer< T >.Clear ( )
inline

Clear the buffer and reset the start and end positions.

◆ PushBack()

void Quantum.Core.RingBuffer< T >.PushBack ( item)
inline

Add a value in the back of the buffer.

Parameters
itemThe value to add to the collection

◆ PushFront()

void Quantum.Core.RingBuffer< T >.PushFront ( item)
inline

Add a value in the front of the buffer.

Parameters
itemThe value to add to the collection

◆ PopBack()

T Quantum.Core.RingBuffer< T >.PopBack ( )
inline

Remove and return the last value in the buffer.

Returns
The youngest value of the buffer
Exceptions
InvalidOperationExceptionIs raised when the buffer is empty.

◆ PopFront()

T Quantum.Core.RingBuffer< T >.PopFront ( )
inline

Remove and return the first value in the buffer.

Returns
The oldest value in the buffer
Exceptions
InvalidOperationExceptionIs raised when the buffer is empty.

◆ PeekBack()

T Quantum.Core.RingBuffer< T >.PeekBack ( Int32  offset = 0)
inline

Look at the last element in the buffer without removing it.

Parameters
offsetOptional offset to apply
Returns
The youngest element
Exceptions
InvalidOperationExceptionIs raised when the buffer is empty.
IndexOutOfRangeExceptionIs raised when the offset is invalid

◆ PeekFront()

T Quantum.Core.RingBuffer< T >.PeekFront ( Int32  offset = 0)
inline

Look at the first element in the buffer without removing it.

Parameters
offsetOptional offset to apply
Returns
The olders element
Exceptions
InvalidOperationExceptionIs raised when the buffer is empty.
IndexOutOfRangeExceptionIs raised when the offset is invalid

Member Data Documentation

◆ ToArray

T [] Quantum.Core.RingBuffer< T >.ToArray => array

Return the underlying array.

◆ IsFull

bool Quantum.Core.RingBuffer< T >.IsFull => Size == Capacity

Check if the buffer is full.

◆ IsEmpty

bool Quantum.Core.RingBuffer< T >.IsEmpty => Size == 0

Check if the buffer is empty.

Property Documentation

◆ Capacity

int Quantum.Core.RingBuffer< T >.Capacity
get

The maximum size of the buffer.

◆ Size

int Quantum.Core.RingBuffer< T >.Size
get

The current used size of the buffer.