ESPHome 2026.8.2
Loading...
Searching...
No Matches
esphome::TemplatableValue< std::string, X... > Class Template Reference

Specialization for std::string: supports VALUE, STATIC_STRING, FLASH_STRING, stateless lambdas, and stateful lambdas (std::function). More...

#include <automation.h>

Inheritance diagram for esphome::TemplatableValue< std::string, X... >:
esphome::api::TemplatableStringValue< Ts... > esphome::api::TemplatableStringValue< X >

Public Member Functions

 TemplatableValue ()
 
 TemplatableValue (const char *str)
 
 TemplatableValue (const __FlashStringHelper *str)
 
template<typename F >
requires (!std::invocable<F, X...>)
 TemplatableValue (F value)
 
template<typename F >
requires std::invocable<F, X...> && std::convertible_to<F, std::string (*)(X...)>
 TemplatableValue (F f)
 
template<typename F >
requires std::invocable<F, X...> &&(!std::convertible_to<F, std::string (*)(X...)>)
 TemplatableValue (F f)
 
 TemplatableValue (const TemplatableValue &other)
 
 TemplatableValue (TemplatableValue &&other) noexcept
 
TemplatableValueoperator= (const TemplatableValue &other)
 
TemplatableValueoperator= (TemplatableValue &&other) noexcept
 
 ~TemplatableValue ()
 
bool has_value () const
 
std::string value (X... x) const
 
optional< std::string > optional_value (X... x) const
 
std::string value_or (X... x, std::string default_value) const
 
bool is_static_string () const
 Check if this holds a static string (const char* stored without allocation) The pointer is always directly readable (RAM or flash-mapped).
 
const char * get_static_string () const
 Get the static string pointer (only valid if is_static_string() returns true) The pointer is always directly readable — FLASH_STRING uses a separate type.
 
bool is_empty () const
 Check if the string value is empty without allocating.
 
StringRef ref_or_copy_to (char *lambda_buf, size_t lambda_buf_size) const
 Get a StringRef to the string value without heap allocation when possible.
 

Protected Types

enum  : uint8_t {
  NONE , VALUE , LAMBDA , STATELESS_LAMBDA ,
  STATIC_STRING , FLASH_STRING
}
 

Protected Attributes

enum esphome::TemplatableValue< std::string, X... >:: { ... }  type_
 
union esphome::TemplatableValue< std::string, X... >:: { ... }  
 

Detailed Description

template<typename... X>
class esphome::TemplatableValue< std::string, X... >

Specialization for std::string: supports VALUE, STATIC_STRING, FLASH_STRING, stateless lambdas, and stateful lambdas (std::function).

Definition at line 217 of file automation.h.

Member Enumeration Documentation

◆ anonymous enum

template<typename... X>
anonymous enum : uint8_t
protected
Enumerator
NONE 
VALUE 
LAMBDA 
STATELESS_LAMBDA 
STATIC_STRING 
FLASH_STRING 

Definition at line 418 of file automation.h.

Constructor & Destructor Documentation

◆ TemplatableValue() [1/8]

template<typename... X>
esphome::TemplatableValue< std::string, X... >::TemplatableValue ( )
inline

Definition at line 219 of file automation.h.

◆ TemplatableValue() [2/8]

template<typename... X>
esphome::TemplatableValue< std::string, X... >::TemplatableValue ( const char * str)
inline

Definition at line 223 of file automation.h.

◆ TemplatableValue() [3/8]

template<typename... X>
esphome::TemplatableValue< std::string, X... >::TemplatableValue ( const __FlashStringHelper * str)
inline

Definition at line 229 of file automation.h.

◆ TemplatableValue() [4/8]

template<typename... X>
template<typename F >
requires (!std::invocable<F, X...>)
esphome::TemplatableValue< std::string, X... >::TemplatableValue ( F value)
inline

Definition at line 234 of file automation.h.

◆ TemplatableValue() [5/8]

template<typename... X>
template<typename F >
requires std::invocable<F, X...> && std::convertible_to<F, std::string (*)(X...)>
esphome::TemplatableValue< std::string, X... >::TemplatableValue ( F f)
inline

Definition at line 240 of file automation.h.

◆ TemplatableValue() [6/8]

template<typename... X>
template<typename F >
requires std::invocable<F, X...> &&(!std::convertible_to<F, std::string (*)(X...)>)
esphome::TemplatableValue< std::string, X... >::TemplatableValue ( F f)
inline

Definition at line 247 of file automation.h.

◆ TemplatableValue() [7/8]

template<typename... X>
esphome::TemplatableValue< std::string, X... >::TemplatableValue ( const TemplatableValue< std::string, X... > & other)
inline

Definition at line 253 of file automation.h.

◆ TemplatableValue() [8/8]

template<typename... X>
esphome::TemplatableValue< std::string, X... >::TemplatableValue ( TemplatableValue< std::string, X... > && other)
inlinenoexcept

Definition at line 266 of file automation.h.

◆ ~TemplatableValue()

template<typename... X>
esphome::TemplatableValue< std::string, X... >::~TemplatableValue ( )
inline

Definition at line 298 of file automation.h.

Member Function Documentation

◆ get_static_string()

template<typename... X>
const char * esphome::TemplatableValue< std::string, X... >::get_static_string ( ) const
inline

Get the static string pointer (only valid if is_static_string() returns true) The pointer is always directly readable — FLASH_STRING uses a separate type.

Definition at line 353 of file automation.h.

◆ has_value()

template<typename... X>
bool esphome::TemplatableValue< std::string, X... >::has_value ( ) const
inline

Definition at line 307 of file automation.h.

◆ is_empty()

template<typename... X>
bool esphome::TemplatableValue< std::string, X... >::is_empty ( ) const
inline

Check if the string value is empty without allocating.

For NONE, returns true. For STATIC_STRING/VALUE, checks without allocation. For LAMBDA/STATELESS_LAMBDA, must call value() which may allocate.

Definition at line 358 of file automation.h.

◆ is_static_string()

template<typename... X>
bool esphome::TemplatableValue< std::string, X... >::is_static_string ( ) const
inline

Check if this holds a static string (const char* stored without allocation) The pointer is always directly readable (RAM or flash-mapped).

Returns false for FLASH_STRING (PROGMEM on ESP8266, requires _P functions).

Definition at line 349 of file automation.h.

◆ operator=() [1/2]

template<typename... X>
TemplatableValue & esphome::TemplatableValue< std::string, X... >::operator= ( const TemplatableValue< std::string, X... > & other)
inline

Definition at line 282 of file automation.h.

◆ operator=() [2/2]

template<typename... X>
TemplatableValue & esphome::TemplatableValue< std::string, X... >::operator= ( TemplatableValue< std::string, X... > && other)
inlinenoexcept

Definition at line 290 of file automation.h.

◆ optional_value()

template<typename... X>
optional< std::string > esphome::TemplatableValue< std::string, X... >::optional_value ( X... x) const
inline

Definition at line 334 of file automation.h.

◆ ref_or_copy_to()

template<typename... X>
StringRef esphome::TemplatableValue< std::string, X... >::ref_or_copy_to ( char * lambda_buf,
size_t lambda_buf_size ) const
inline

Get a StringRef to the string value without heap allocation when possible.

For STATIC_STRING/VALUE, returns reference to existing data (no allocation). For FLASH_STRING (ESP8266 PROGMEM), copies to provided buffer via _P functions. For LAMBDA/STATELESS_LAMBDA, calls value(), copies to provided buffer, returns ref to buffer.

Parameters
lambda_bufBuffer used only for copy cases (must remain valid while StringRef is used).
lambda_buf_sizeSize of the buffer.
Returns
StringRef pointing to the string data.

Definition at line 384 of file automation.h.

◆ value()

template<typename... X>
std::string esphome::TemplatableValue< std::string, X... >::value ( X... x) const
inline

Definition at line 309 of file automation.h.

◆ value_or()

template<typename... X>
std::string esphome::TemplatableValue< std::string, X... >::value_or ( X... x,
std::string default_value ) const
inline

Definition at line 340 of file automation.h.

Field Documentation

◆ []

union esphome::TemplatableValue< std::string, X... > { ... } esphome::TemplatableValue< std::string, X... >

◆ f_

template<typename... X>
std::function<std::string(X...)>* esphome::TemplatableValue< std::string, X... >::f_

Definition at line 428 of file automation.h.

◆ stateless_f_

template<typename... X>
std::string(* esphome::TemplatableValue< std::string, X... >::stateless_f_) (X...)

Definition at line 429 of file automation.h.

◆ static_str_

template<typename... X>
const char* esphome::TemplatableValue< std::string, X... >::static_str_

Definition at line 430 of file automation.h.

◆ []

enum esphome::TemplatableValue< std::string, X... > { ... } esphome::TemplatableValue< std::string, X... >::type_

◆ value_

template<typename... X>
std::string* esphome::TemplatableValue< std::string, X... >::value_

Definition at line 427 of file automation.h.


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