ESPHome 2026.3.2
Loading...
Searching...
No Matches
esphome::LazyCallbackManager< void(Ts...)> Class Template Reference

Lazy-allocating callback manager that only allocates memory when callbacks are registered. More...

#include <helpers.h>

Public Member Functions

 LazyCallbackManager ()=default
 
 ~LazyCallbackManager ()
 Destructor - clean up allocated CallbackManager if any.
 
 LazyCallbackManager (const LazyCallbackManager &)=delete
 
LazyCallbackManageroperator= (const LazyCallbackManager &)=delete
 
 LazyCallbackManager (LazyCallbackManager &&)=delete
 
LazyCallbackManageroperator= (LazyCallbackManager &&)=delete
 
void add (std::function< void(Ts...)> &&callback)
 Add a callback to the list. Allocates the underlying CallbackManager on first use.
 
void call (Ts... args)
 Call all callbacks in this manager. No-op if no callbacks registered.
 
size_t size () const
 Return the number of registered callbacks.
 
bool empty () const
 Check if any callbacks are registered.
 
void operator() (Ts... args)
 Call all callbacks in this manager.
 

Protected Attributes

CallbackManager< void(Ts...)> * callbacks_ {nullptr}
 

Detailed Description

template<typename... Ts>
class esphome::LazyCallbackManager< void(Ts...)>

Lazy-allocating callback manager that only allocates memory when callbacks are registered.

This is a drop-in replacement for CallbackManager that saves memory when no callbacks are registered (common case after the Controller Registry eliminated per-entity callbacks from API and web_server components).

Memory overhead comparison (32-bit systems):

Uses plain pointer instead of unique_ptr to avoid template instantiation overhead. The class is explicitly non-copyable/non-movable for Rule of Five compliance.

Template Parameters
TsThe arguments for the callbacks, wrapped in void().

Definition at line 1645 of file helpers.h.

Constructor & Destructor Documentation

◆ LazyCallbackManager() [1/3]

template<typename... Ts>
esphome::LazyCallbackManager< void(Ts...)>::LazyCallbackManager ( )
default

◆ ~LazyCallbackManager()

template<typename... Ts>
esphome::LazyCallbackManager< void(Ts...)>::~LazyCallbackManager ( )
inline

Destructor - clean up allocated CallbackManager if any.

In practice this never runs (entities live for device lifetime) but included for correctness.

Definition at line 1650 of file helpers.h.

◆ LazyCallbackManager() [2/3]

template<typename... Ts>
esphome::LazyCallbackManager< void(Ts...)>::LazyCallbackManager ( const LazyCallbackManager< void(Ts...)> & )
delete

◆ LazyCallbackManager() [3/3]

template<typename... Ts>
esphome::LazyCallbackManager< void(Ts...)>::LazyCallbackManager ( LazyCallbackManager< void(Ts...)> && )
delete

Member Function Documentation

◆ add()

template<typename... Ts>
void esphome::LazyCallbackManager< void(Ts...)>::add ( std::function< void(Ts...)> && callback)
inline

Add a callback to the list. Allocates the underlying CallbackManager on first use.

Definition at line 1659 of file helpers.h.

◆ call()

template<typename... Ts>
void esphome::LazyCallbackManager< void(Ts...)>::call ( Ts... args)
inline

Call all callbacks in this manager. No-op if no callbacks registered.

Definition at line 1667 of file helpers.h.

◆ empty()

template<typename... Ts>
bool esphome::LazyCallbackManager< void(Ts...)>::empty ( ) const
inline

Check if any callbacks are registered.

Definition at line 1677 of file helpers.h.

◆ operator()()

template<typename... Ts>
void esphome::LazyCallbackManager< void(Ts...)>::operator() ( Ts... args)
inline

Call all callbacks in this manager.

Definition at line 1680 of file helpers.h.

◆ operator=() [1/2]

template<typename... Ts>
LazyCallbackManager & esphome::LazyCallbackManager< void(Ts...)>::operator= ( const LazyCallbackManager< void(Ts...)> & )
delete

◆ operator=() [2/2]

template<typename... Ts>
LazyCallbackManager & esphome::LazyCallbackManager< void(Ts...)>::operator= ( LazyCallbackManager< void(Ts...)> && )
delete

◆ size()

template<typename... Ts>
size_t esphome::LazyCallbackManager< void(Ts...)>::size ( ) const
inline

Return the number of registered callbacks.

Definition at line 1674 of file helpers.h.

Field Documentation

◆ callbacks_

template<typename... Ts>
CallbackManager<void(Ts...)>* esphome::LazyCallbackManager< void(Ts...)>::callbacks_ {nullptr}
protected

Definition at line 1683 of file helpers.h.


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