FastLED 3.10.8
Loading...
Searching...
No Matches
singleton.cpp.hpp
Go to the documentation of this file.
1#include "fl/stl/singleton.h"
2#include "fl/stl/cstring.h"
3
4namespace fl {
5namespace detail {
6
7namespace {
8 struct RegistryEntry {
9 const char* key;
10 void* value;
11 };
12 static constexpr int REGISTRY_MAX = 128;
13 // FL_LINT_ALLOW_GLOBAL(singleton registry backing — cannot itself live inside a Singleton<T>, which would be self-referential)
15 // FL_LINT_ALLOW_GLOBAL(singleton registry backing — see above)
16 static int registry_count = 0;
17} // anonymous namespace
18
19void* singleton_registry_get(const char* key) FL_NO_EXCEPT {
20 for (int i = 0; i < registry_count; i++) {
21 if (fl::strcmp(registry[i].key, key) == 0) {
22 return registry[i].value;
23 }
24 }
25 return nullptr;
26}
27
28void singleton_registry_set(const char* key, void* value) FL_NO_EXCEPT {
29 // Check if already registered (update)
30 for (int i = 0; i < registry_count; i++) {
31 if (fl::strcmp(registry[i].key, key) == 0) {
32 registry[i].value = value;
33 return;
34 }
35 }
36 // Add new entry
37 if (registry_count < REGISTRY_MAX) {
38 registry[registry_count++] = {key, value};
39 }
40}
41
42} // namespace detail
43} // namespace fl
static RegistryEntry registry[REGISTRY_MAX]
void * singleton_registry_get(const char *key) FL_NO_EXCEPT
void singleton_registry_set(const char *key, void *value) FL_NO_EXCEPT
Compile-time linker keep-alive hook for a single fl::Bus.
Definition bus_info.h:57
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
constexpr int type_rank< T >::value
FASTLED_FORCE_INLINE int strcmp(const char *s1, const char *s2) FL_NO_EXCEPT
Definition cstring.h:60
Base definition for an LED controller.
Definition crgb.hpp:179