ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
light_effect_names.h
Go to the documentation of this file.
1#pragma once
2
5#include "light_effect.h"
6
7namespace esphome::light {
8
13 public:
14 explicit LightEffectNames(const ConstVector<LightEffect *> &effects) : effects_(effects) {}
15
16 class Iterator {
17 public:
18 ESPHOME_ALWAYS_INLINE Iterator(const ConstVector<LightEffect *> &effects, size_t index)
19 : effects_(effects), index_(index) {}
20 ESPHOME_ALWAYS_INLINE StringRef operator*() const {
21 return this->index_ == 0 ? EFFECT_NONE_REF : this->effects_[this->index_ - 1]->get_name();
22 }
23 ESPHOME_ALWAYS_INLINE Iterator &operator++() {
24 ++this->index_;
25 return *this;
26 }
27 ESPHOME_ALWAYS_INLINE bool operator!=(const Iterator &other) const { return this->index_ != other.index_; }
28
29 protected:
31 size_t index_;
32 };
33
34 ESPHOME_ALWAYS_INLINE Iterator begin() const { return {this->effects_, 0}; }
35 ESPHOME_ALWAYS_INLINE Iterator end() const {
36 return {this->effects_, this->effects_.empty() ? 0 : this->effects_.size() + 1};
37 }
38 ESPHOME_ALWAYS_INLINE bool empty() const { return this->effects_.empty(); }
39
40 protected:
42};
43
44} // namespace esphome::light
Lightweight read-only view over a const array stored in RODATA (will typically be in flash memory).
Definition helpers.h:130
StringRef is a reference to a string owned by something else.
Definition string_ref.h:31
ESPHOME_ALWAYS_INLINE StringRef operator*() const
ESPHOME_ALWAYS_INLINE Iterator(const ConstVector< LightEffect * > &effects, size_t index)
const ConstVector< LightEffect * > & effects_
ESPHOME_ALWAYS_INLINE bool operator!=(const Iterator &other) const
ESPHOME_ALWAYS_INLINE Iterator & operator++()
Effect names as the native API lists them: "None" first, then each effect; empty without effects.
const ConstVector< LightEffect * > & effects_
ESPHOME_ALWAYS_INLINE Iterator end() const
LightEffectNames(const ConstVector< LightEffect * > &effects)
ESPHOME_ALWAYS_INLINE Iterator begin() const
ESPHOME_ALWAYS_INLINE bool empty() const
constexpr StringRef EFFECT_NONE_REF
Definition light_effect.h:8