Mercurial > hg > svcore
comparison base/ById.h @ 1736:d9082ed16931 by-id
Merge
author | Chris Cannam |
---|---|
date | Tue, 25 Jun 2019 15:29:45 +0100 |
parents | d91ff235e69d bffccc8de3c1 |
children | 4abc0f08adf9 |
comparison
equal
deleted
inserted
replaced
1735:d91ff235e69d | 1736:d9082ed16931 |
---|---|
12 COPYING included with this distribution for more information. | 12 COPYING included with this distribution for more information. |
13 */ | 13 */ |
14 | 14 |
15 #ifndef SV_BY_ID_H | 15 #ifndef SV_BY_ID_H |
16 #define SV_BY_ID_H | 16 #define SV_BY_ID_H |
17 | |
18 #include "Debug.h" | |
17 | 19 |
18 #include <memory> | 20 #include <memory> |
19 #include <map> | 21 #include <map> |
20 #include <typeinfo> | 22 #include <typeinfo> |
21 #include <iostream> | 23 #include <iostream> |
96 public: | 98 public: |
97 ~ById() { | 99 ~ById() { |
98 QMutexLocker locker(&m_mutex); | 100 QMutexLocker locker(&m_mutex); |
99 for (const auto &p: m_items) { | 101 for (const auto &p: m_items) { |
100 if (p.second && p.second.use_count() > 0) { | 102 if (p.second && p.second.use_count() > 0) { |
101 std::cerr << "WARNING: ById map destroyed with use count of " | 103 SVCERR << "WARNING: ById map destroyed with use count of " |
102 << p.second.use_count() << " for item with type " | 104 << p.second.use_count() << " for item with type " |
103 << typeid(*p.second.get()).name() | 105 << typeid(*p.second.get()).name() |
104 << " and id " << p.first.id << std::endl; | 106 << " and id " << p.first.id << endl; |
105 } | 107 } |
106 } | 108 } |
107 } | 109 } |
108 | 110 |
109 void add(std::shared_ptr<Item> item) { | 111 void add(std::shared_ptr<Item> item) { |
110 QMutexLocker locker(&m_mutex); | 112 QMutexLocker locker(&m_mutex); |
111 m_items[item->getId()] = item; | 113 auto id = item->getId(); |
114 if (m_items.find(id) != m_items.end()) { | |
115 SVCERR << "WARNING: ById::add: item with id " << id | |
116 << " is already recorded, replacing it (item type is " | |
117 << typeid(*item.get()).name() << ")" << endl; | |
118 } | |
119 m_items[id] = item; | |
112 } | 120 } |
113 | 121 |
114 void | 122 void |
115 release(Id id) { | 123 release(Id id) { |
116 QMutexLocker locker(&m_mutex); | 124 QMutexLocker locker(&m_mutex); |