ESPHome 2026.5.2
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
 
FixedRingBufferoperator= (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 390 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 427 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 495 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 497 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 485 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 489 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 484 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 496 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 498 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 481 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 482 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 486 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 440 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 474 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 452 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 462 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 483 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 505 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 504 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 501 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 502 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 503 of file helpers.h.


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