FastLED 3.9.15
Loading...
Searching...
No Matches
id_tracker.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/flat_map.h"
4#include "fl/stl/mutex.h"
5#include "fl/stl/noexcept.h"
6namespace fl {
7
29class IdTracker {
30public:
35
43 int getOrCreateId(void* ptr) FL_NOEXCEPT;
44
53 bool getId(void* ptr, int* outId) FL_NOEXCEPT;
54
62 bool removeId(void* ptr) FL_NOEXCEPT;
63
70 size_t size() FL_NOEXCEPT;
71
76 void clear() FL_NOEXCEPT;
77
78 // Non-copyable and non-movable for thread safety
79 // (Each instance should have its own independent state)
81 IdTracker& operator=(const IdTracker&) FL_NOEXCEPT = delete;
83 IdTracker& operator=(IdTracker&&) FL_NOEXCEPT = delete;
84
85private:
86
87 // Thread synchronization
88 mutable fl::mutex mMutex;
89
90 // ID mapping and counter
91 fl::flat_map<void*, int> mPointerToId;
92 int mNextId = 0; // Start IDs at 0 to match StripIdMap behavior
93};
94
95} // namespace fl
void clear() FL_NOEXCEPT
Clear all tracked pointers and reset ID counter.
int getOrCreateId(void *ptr) FL_NOEXCEPT
Get existing ID for pointer, or create a new one if not found.
bool removeId(void *ptr) FL_NOEXCEPT
Remove tracking for a pointer.
fl::flat_map< void *, int > mPointerToId
Definition id_tracker.h:91
bool getId(void *ptr, int *outId) FL_NOEXCEPT
Get existing ID for pointer without creating a new one.
size_t size() FL_NOEXCEPT
Get the current number of tracked pointers.
fl::mutex mMutex
Definition id_tracker.h:88
IdTracker() FL_NOEXCEPT=default
Default constructor - creates a new ID tracker instance.
Platform-independent mutex interface.
fl::platforms::mutex mutex
Definition mutex.h:20
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT