comparison base/ById.cpp @ 1768:4fec4527e50e

Remove debug output (by default)
author Chris Cannam
date Thu, 18 Jul 2019 13:28:14 +0100
parents ee7fd2c01d87
children c7e9e63c7bae
comparison
equal deleted inserted replaced
1767:aa0b56d72f27 1768:4fec4527e50e
14 14
15 #include "ById.h" 15 #include "ById.h"
16 16
17 #include <unordered_map> 17 #include <unordered_map>
18 #include <typeinfo> 18 #include <typeinfo>
19
20 //#define DEBUG_BY_ID 1
19 21
20 int IdAlloc::getNextId() 22 int IdAlloc::getNextId()
21 { 23 {
22 static int nextId = 0; 24 static int nextId = 0;
23 static QMutex mutex; 25 static QMutex mutex;
68 int add(std::shared_ptr<WithId> item) { 70 int add(std::shared_ptr<WithId> item) {
69 int id = item->getUntypedId(); 71 int id = item->getUntypedId();
70 if (id == IdAlloc::NO_ID) { 72 if (id == IdAlloc::NO_ID) {
71 throw std::logic_error("item id should never be NO_ID"); 73 throw std::logic_error("item id should never be NO_ID");
72 } 74 }
75 #ifdef DEBUG_BY_ID
73 SVCERR << "ById::add(#" << id << ") of type " 76 SVCERR << "ById::add(#" << id << ") of type "
74 << typeid(*item.get()).name() << endl; 77 << typeid(*item.get()).name() << endl;
78 #endif
75 QMutexLocker locker(&m_mutex); 79 QMutexLocker locker(&m_mutex);
76 if (m_items.find(id) != m_items.end()) { 80 if (m_items.find(id) != m_items.end()) {
77 SVCERR << "ById::add: item with id " << id 81 SVCERR << "ById::add: item with id " << id
78 << " is already recorded (existing item type is " 82 << " is already recorded (existing item type is "
79 << typeid(*m_items.find(id)->second.get()).name() 83 << typeid(*m_items.find(id)->second.get()).name()
87 91
88 void release(int id) { 92 void release(int id) {
89 if (id == IdAlloc::NO_ID) { 93 if (id == IdAlloc::NO_ID) {
90 return; 94 return;
91 } 95 }
96 #ifdef DEBUG_BY_ID
92 SVCERR << "ById::release(#" << id << ")" << endl; 97 SVCERR << "ById::release(#" << id << ")" << endl;
98 #endif
93 QMutexLocker locker(&m_mutex); 99 QMutexLocker locker(&m_mutex);
94 if (m_items.find(id) == m_items.end()) { 100 if (m_items.find(id) == m_items.end()) {
95 SVCERR << "ById::release: unknown item id " << id << endl; 101 SVCERR << "ById::release: unknown item id " << id << endl;
96 throw std::logic_error("unknown item id in release"); 102 throw std::logic_error("unknown item id in release");
97 } 103 }