ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
esphome::Callback< void(Ts...)> Struct Template Reference

#include <helpers.h>

Data Structures

struct  Box
 Heap home of a callable stored by create_boxed(); the header knows how to free it. More...
 

Public Member Functions

void call (Ts... args) const
 Invoke the callback. Only valid on Callbacks created via create(), never on default-constructed instances.
 
void free_boxed () const
 Free the callable of a Callback made by create_boxed(); the Callback must not be called afterwards.
 

Static Public Member Functions

template<typename F >
static constexpr bool fits_inline ()
 Whether create() stores F inline in the ctx pointer.
 
template<typename F >
static Callback create (F &&callable)
 Create from any callable.
 
template<typename F >
static Callback create_boxed (F &&callable)
 Store any callable on the heap with a deleter, for an owner that can later free_boxed() it.
 

Data Fields

void(* fn_ )(void *, Ts...)
 
void * ctx_ {nullptr}
 

Detailed Description

template<typename... Ts>
struct esphome::Callback< void(Ts...)>

Definition at line 1808 of file helpers.h.

Member Function Documentation

◆ call()

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

Invoke the callback. Only valid on Callbacks created via create(), never on default-constructed instances.

Definition at line 1818 of file helpers.h.

◆ create()

template<typename... Ts>
template<typename F >
static Callback esphome::Callback< void(Ts...)>::create ( F && callable)
inlinestatic

Create from any callable.

Small trivially-copyable callables (like [this] lambdas) are stored inline in the ctx pointer without heap allocation.

Definition at line 1830 of file helpers.h.

◆ create_boxed()

template<typename... Ts>
template<typename F >
static Callback esphome::Callback< void(Ts...)>::create_boxed ( F && callable)
inlinestatic

Store any callable on the heap with a deleter, for an owner that can later free_boxed() it.

Definition at line 1862 of file helpers.h.

◆ fits_inline()

template<typename... Ts>
template<typename F >
static constexpr bool esphome::Callback< void(Ts...)>::fits_inline ( )
inlinestaticconstexpr

Whether create() stores F inline in the ctx pointer.

The inline path invokes a copy, so a callable that mutates its captures (a mutable lambda) is kept whole on the heap instead.

Definition at line 1822 of file helpers.h.

◆ free_boxed()

template<typename... Ts>
void esphome::Callback< void(Ts...)>::free_boxed ( ) const
inline

Free the callable of a Callback made by create_boxed(); the Callback must not be called afterwards.

Definition at line 1873 of file helpers.h.

Field Documentation

◆ ctx_

template<typename... Ts>
void* esphome::Callback< void(Ts...)>::ctx_ {nullptr}

Definition at line 1815 of file helpers.h.

◆ fn_

template<typename... Ts>
void(* esphome::Callback< void(Ts...)>::fn_) (void *, Ts...)
inline

Definition at line 1814 of file helpers.h.


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