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/hash_map.h"
4#include "fl/mutex.h"
5#include "fl/namespace.h"
6
7namespace fl {
8
30class IdTracker {
31public:
35 IdTracker() = default;
36
44 int getOrCreateId(void* ptr);
45
54 bool getId(void* ptr, int* outId);
55
63 bool removeId(void* ptr);
64
71 size_t size();
72
77 void clear();
78
79 // Non-copyable and non-movable for thread safety
80 // (Each instance should have its own independent state)
81 IdTracker(const IdTracker&) = delete;
82 IdTracker& operator=(const IdTracker&) = delete;
83 IdTracker(IdTracker&&) = delete;
85
86private:
87
88 // Thread synchronization
90
91 // ID mapping and counter
93 int mNextId = 0; // Start IDs at 0 to match StripIdMap behavior
94};
95
96} // namespace fl
IdTracker(IdTracker &&)=delete
IdTracker & operator=(const IdTracker &)=delete
bool getId(void *ptr, int *outId)
Get existing ID for pointer without creating a new one.
bool removeId(void *ptr)
Remove tracking for a pointer.
IdTracker(const IdTracker &)=delete
IdTracker()=default
Default constructor - creates a new ID tracker instance.
fl::hash_map< void *, int > mPointerToId
Definition id_tracker.h:92
size_t size()
Get the current number of tracked pointers.
fl::mutex mMutex
Definition id_tracker.h:89
int getOrCreateId(void *ptr)
Get existing ID for pointer, or create a new one if not found.
Definition id_tracker.cpp:5
IdTracker & operator=(IdTracker &&)=delete
void clear()
Clear all tracked pointers and reset ID counter.
Implements the FastLED namespace macros.
MutexFake< void > mutex
Definition mutex.h:18
HashMap< Key, T, Hash, KeyEqual > hash_map
Definition hash_map.h:716
IMPORTANT!
Definition crgb.h:20