ESPHome 2026.10.0
Loading...
Searching...
No Matches
esphome::FixedRingBuffer< T, MAX_CAPACITY > Class Template Reference

Fixed-capacity circular buffer - allocates once at runtime, never reallocates. More...

#include <helpers.h>

Data Structures

class  ConstIterator
 
class  Iterator
 

Public Member Functions

 FixedRingBuffer ()=default
 
 ~FixedRingBuffer ()
 
 FixedRingBuffer (const FixedRingBuffer &)=delete
 
FixedRingBuffer & operator= (const FixedRingBuffer &)=delete
 
void init (index_type capacity)
 Allocate capacity - can only be called once.
 
bool push (const T &value)
 Push a value. Returns false if full.
 
void push_overwrite (const T &value)
 Push a value, overwriting the oldest if full.
 
void pop ()
 Remove the oldest element.
 
T & front ()
 
const T & front () const
 
index_type size () const
 
bool empty () const
 
index_type capacity () const
 
bool full () const
 
void clear ()
 Clear all elements (reset to empty, keep capacity)
 
Iterator begin ()
 
Iterator end ()
 
ConstIterator begin () const
 
ConstIterator end () const
 

Protected Attributes

T * data_ {nullptr}
 
index_type head_ {0}
 
index_type tail_ {0}
 
index_type count_ {0}
 
index_type capacity_ {0}
 

Detailed Description

template<typename T, size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
class esphome::FixedRingBuffer< T, MAX_CAPACITY >

Fixed-capacity circular buffer - allocates once at runtime, never reallocates.

Runtime-sized equivalent of StaticRingBuffer - use when capacity is only known at initialization. Supports FIFO push/pop and iteration over queued elements. Not thread-safe.

Definition at line 474 of file helpers.h.

Constructor & Destructor Documentation

◆ FixedRingBuffer() [1/2]

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
esphome::FixedRingBuffer< T, MAX_CAPACITY >::FixedRingBuffer ( )
default

◆ ~FixedRingBuffer()

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
esphome::FixedRingBuffer< T, MAX_CAPACITY >::~FixedRingBuffer ( )
inline

Definition at line 511 of file helpers.h.

◆ FixedRingBuffer() [2/2]

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
esphome::FixedRingBuffer< T, MAX_CAPACITY >::FixedRingBuffer ( const FixedRingBuffer< T, MAX_CAPACITY > & )
delete

Member Function Documentation

◆ begin() [1/2]

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
Iterator esphome::FixedRingBuffer< T, MAX_CAPACITY >::begin ( )
inline

Definition at line 579 of file helpers.h.

◆ begin() [2/2]

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
ConstIterator esphome::FixedRingBuffer< T, MAX_CAPACITY >::begin ( ) const
inline

Definition at line 581 of file helpers.h.

◆ capacity()

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
index_type esphome::FixedRingBuffer< T, MAX_CAPACITY >::capacity ( ) const
inline

Definition at line 569 of file helpers.h.

◆ clear()

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
void esphome::FixedRingBuffer< T, MAX_CAPACITY >::clear ( )
inline

Clear all elements (reset to empty, keep capacity)

Definition at line 573 of file helpers.h.

◆ empty()

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
bool esphome::FixedRingBuffer< T, MAX_CAPACITY >::empty ( ) const
inline

Definition at line 568 of file helpers.h.

◆ end() [1/2]

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
Iterator esphome::FixedRingBuffer< T, MAX_CAPACITY >::end ( )
inline

Definition at line 580 of file helpers.h.

◆ end() [2/2]

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
ConstIterator esphome::FixedRingBuffer< T, MAX_CAPACITY >::end ( ) const
inline

Definition at line 582 of file helpers.h.

◆ front() [1/2]

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
T & esphome::FixedRingBuffer< T, MAX_CAPACITY >::front ( )
inline

Definition at line 565 of file helpers.h.

◆ front() [2/2]

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
const T & esphome::FixedRingBuffer< T, MAX_CAPACITY >::front ( ) const
inline

Definition at line 566 of file helpers.h.

◆ full()

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
bool esphome::FixedRingBuffer< T, MAX_CAPACITY >::full ( ) const
inline

Definition at line 570 of file helpers.h.

◆ init()

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
void esphome::FixedRingBuffer< T, MAX_CAPACITY >::init ( index_type capacity)
inline

Allocate capacity - can only be called once.

Definition at line 524 of file helpers.h.

◆ operator=()

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
FixedRingBuffer & esphome::FixedRingBuffer< T, MAX_CAPACITY >::operator= ( const FixedRingBuffer< T, MAX_CAPACITY > & )
delete

◆ pop()

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
void esphome::FixedRingBuffer< T, MAX_CAPACITY >::pop ( )
inline

Remove the oldest element.

Definition at line 558 of file helpers.h.

◆ push()

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
bool esphome::FixedRingBuffer< T, MAX_CAPACITY >::push ( const T & value)
inline

Push a value. Returns false if full.

Definition at line 536 of file helpers.h.

◆ push_overwrite()

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
void esphome::FixedRingBuffer< T, MAX_CAPACITY >::push_overwrite ( const T & value)
inline

Push a value, overwriting the oldest if full.

Definition at line 546 of file helpers.h.

◆ size()

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
index_type esphome::FixedRingBuffer< T, MAX_CAPACITY >::size ( ) const
inline

Definition at line 567 of file helpers.h.

Field Documentation

◆ capacity_

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
index_type esphome::FixedRingBuffer< T, MAX_CAPACITY >::capacity_ {0}
protected

Definition at line 589 of file helpers.h.

◆ count_

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
index_type esphome::FixedRingBuffer< T, MAX_CAPACITY >::count_ {0}
protected

Definition at line 588 of file helpers.h.

◆ data_

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
T* esphome::FixedRingBuffer< T, MAX_CAPACITY >::data_ {nullptr}
protected

Definition at line 585 of file helpers.h.

◆ head_

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
index_type esphome::FixedRingBuffer< T, MAX_CAPACITY >::head_ {0}
protected

Definition at line 586 of file helpers.h.

◆ tail_

template<typename T , size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
index_type esphome::FixedRingBuffer< T, MAX_CAPACITY >::tail_ {0}
protected

Definition at line 587 of file helpers.h.


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