Mercurial > hg > svcore
diff base/ById.h @ 1734:bffccc8de3c1 by-id
Warn for already-existing id
author | Chris Cannam |
---|---|
date | Mon, 24 Jun 2019 18:42:28 +0100 |
parents | 601851995f4b |
children | d9082ed16931 |
line wrap: on
line diff
--- a/base/ById.h Mon Jun 24 14:28:17 2019 +0100 +++ b/base/ById.h Mon Jun 24 18:42:28 2019 +0100 @@ -15,6 +15,8 @@ #ifndef SV_BY_ID_H #define SV_BY_ID_H +#include "Debug.h" + #include <memory> #include <map> #include <typeinfo> @@ -80,17 +82,23 @@ QMutexLocker locker(&m_mutex); for (const auto &p: m_items) { if (p.second && p.second.use_count() > 0) { - std::cerr << "WARNING: ById map destroyed with use count of " - << p.second.use_count() << " for item with type " - << typeid(*p.second.get()).name() - << " and id " << p.first.id << std::endl; + SVCERR << "WARNING: ById map destroyed with use count of " + << p.second.use_count() << " for item with type " + << typeid(*p.second.get()).name() + << " and id " << p.first.id << endl; } } } void add(std::shared_ptr<Item> item) { QMutexLocker locker(&m_mutex); - m_items[item->getId()] = item; + auto id = item->getId(); + if (m_items.find(id) != m_items.end()) { + SVCERR << "WARNING: ById::add: item with id " << id + << " is already recorded, replacing it (item type is " + << typeid(*item.get()).name() << ")" << endl; + } + m_items[id] = item; } void