FastLED 3.9.15
Loading...
Searching...
No Matches
fl::IdTracker Class Reference

Detailed Description

Thread-safe ID tracker that maps void* pointers to unique integer IDs.

Features:

  • Auto-incrementing ID counter for new entries
  • Thread-safe operations with mutex protection
  • Instantiable class - create as many trackers as needed
  • Support for removal of tracked pointers

Usage: IdTracker tracker; // Create instance int id = tracker.getOrCreateId(ptr); bool found = tracker.getId(ptr, &id); tracker.removeId(ptr);

For singleton behavior, wrap in your own singleton: static IdTracker& getGlobalTracker() { static IdTracker instance; return instance; }

Definition at line 30 of file id_tracker.h.

#include <id_tracker.h>

+ Collaboration diagram for fl::IdTracker:

Public Member Functions

 IdTracker ()=default
 Default constructor - creates a new ID tracker instance.
 
 IdTracker (const IdTracker &)=delete
 
 IdTracker (IdTracker &&)=delete
 
void clear ()
 Clear all tracked pointers and reset ID counter.
 
bool getId (void *ptr, int *outId)
 Get existing ID for pointer without creating a new one.
 
int getOrCreateId (void *ptr)
 Get existing ID for pointer, or create a new one if not found.
 
IdTrackeroperator= (const IdTracker &)=delete
 
IdTrackeroperator= (IdTracker &&)=delete
 
bool removeId (void *ptr)
 Remove tracking for a pointer.
 
size_t size ()
 Get the current number of tracked pointers.
 

Private Attributes

fl::mutex mMutex
 
int mNextId = 0
 
fl::hash_map< void *, int > mPointerToId
 

The documentation for this class was generated from the following files: