FastLED 3.9.15
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;
14 static int registry_count = 0;
15} // anonymous namespace
16
17void* singleton_registry_get(const char* key) {
18 for (int i = 0; i < registry_count; i++) {
19 if (fl::strcmp(registry[i].key, key) == 0) {
20 return registry[i].value;
21 }
22 }
23 return nullptr;
24}
25
26void singleton_registry_set(const char* key, void* value) {
27 // Check if already registered (update)
28 for (int i = 0; i < registry_count; i++) {
29 if (fl::strcmp(registry[i].key, key) == 0) {
30 registry[i].value = value;
31 return;
32 }
33 }
34 // Add new entry
35 if (registry_count < REGISTRY_MAX) {
36 registry[registry_count++] = {key, value};
37 }
38}
39
40} // namespace detail
41} // namespace fl
static RegistryEntry registry[REGISTRY_MAX]
void * singleton_registry_get(const char *key)
void singleton_registry_set(const char *key, void *value)
Compile-time linker keep-alive hook for a single fl::Bus.
Definition bus_traits.h:48
constexpr int type_rank< T >::value
int strcmp(const char *s1, const char *s2) FL_NOEXCEPT
Base definition for an LED controller.
Definition crgb.hpp:179