| 4 | namespace fl { |
| 5 | |
| 6 | int IdTracker::getOrCreateId(void* ptr) FL_NOEXCEPT { |
| 7 | if (!ptr) { |
| 8 | return -1; // Invalid pointer gets invalid ID |
| 9 | } |
| 10 | |
| 11 | // Lock for thread safety |
| 12 | mMutex.lock(); |
| 13 | |
| 14 | // Check if ID already exists |
| 15 | auto it = mPointerToId.find(ptr); |
| 16 | if (it != mPointerToId.end()) { |
| 17 | int id = it->second; |
| 18 | mMutex.unlock(); |
| 19 | return id; |
| 20 | } |
| 21 | |
| 22 | // Create new ID |
| 23 | int newId = mNextId++; |
| 24 | mPointerToId[ptr] = newId; |
| 25 | |
| 26 | mMutex.unlock(); |
| 27 | return newId; |
| 28 | } |
| 29 | |
| 30 | bool IdTracker::getId(void* ptr, int* outId) FL_NOEXCEPT { |
| 31 | if (!ptr || !outId) { |
no test coverage detected