Commit 56ba5a57 authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud

Modify algorithm to remove object from object manager.

parent e72d1263
......@@ -14,6 +14,8 @@
#include "dtkObjectManager.h"
#include <algorithm>
class dtkObjectManagerPrivate
{
public:
......@@ -57,15 +59,19 @@ QStringList dtkObjectManager::keys(void) const
bool dtkObjectManager::remove(const QVariant& v)
{
QVariantMap::const_iterator i = d->instances.begin();
while (i != d->instances.end()) {
if (i.value() == v) {
d->instances.remove(i.key());
return true;
QList<QString> keys;
for (auto it = d->instances.begin(), end = d->instances.end(); it != end; ++it) {
if (*it == v) {
keys << it.key();
}
++i;
}
return false;
for (auto&& k : keys) {
d->instances.remove(k);
}
return (keys.size());
}
dtkObjectManager::dtkObjectManager(void)
......
......@@ -82,7 +82,7 @@ void dtkObjectManagerTestCase::testDel(void)
QCOMPARE(dtkObjectManager::instance()->remove(v), false);
v.setValue(d->comm_1);
QCOMPARE(dtkObjectManager::instance()->remove(v), true);
QCOMPARE(dtkObjectManager::instance()->count() , 1);
QCOMPARE(dtkObjectManager::instance()->count(), 1);
v = dtkObjectManager::instance()->value(QString("dtkDistributedCommunicator* 1"));
dtkDistributedCommunicator * comm = v.value<dtkDistributedCommunicator*>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment