diff base/ById.cpp @ 1744:b92bdcd4954b by-id

Update FFT model to ById
author Chris Cannam
date Tue, 02 Jul 2019 11:49:28 +0100
parents 52705a328b34
children 6d09d68165a4
line wrap: on
line diff
--- a/base/ById.cpp	Mon Jul 01 14:16:12 2019 +0100
+++ b/base/ById.cpp	Tue Jul 02 11:49:28 2019 +0100
@@ -60,6 +60,9 @@
     }
         
     void add(int id, std::shared_ptr<WithId> item) {
+        if (id == IdAlloc::NO_ID) {
+            throw std::logic_error("cannot add item with id of NO_ID");
+        }
         QMutexLocker locker(&m_mutex);
         if (m_items.find(id) != m_items.end()) {
             SVCERR << "ById::add: item with id " << id
@@ -73,6 +76,9 @@
     }
 
     void release(int id) {
+        if (id == IdAlloc::NO_ID) {
+            return;
+        }
         QMutexLocker locker(&m_mutex);
         if (m_items.find(id) == m_items.end()) {
             SVCERR << "ById::release: unknown item id " << id << endl;
@@ -82,6 +88,9 @@
     }
     
     std::shared_ptr<WithId> get(int id) const {
+        if (id == IdAlloc::NO_ID) {
+            return {}; // this id cannot be added: avoid locking
+        }
         QMutexLocker locker(&m_mutex);
         const auto &itr = m_items.find(id);
         if (itr != m_items.end()) {