Skip to content
Snippets Groups Projects
Commit 537cb911 authored by Alexander Gavriliuk's avatar Alexander Gavriliuk Committed by Guru
Browse files

SL-20163 Rework add/remove observers in LLAvatarPropertiesProcessor

parent 735da0eb
No related branches found
No related tags found
No related merge requests found
...@@ -52,24 +52,23 @@ LLAvatarPropertiesProcessor::~LLAvatarPropertiesProcessor() ...@@ -52,24 +52,23 @@ LLAvatarPropertiesProcessor::~LLAvatarPropertiesProcessor()
void LLAvatarPropertiesProcessor::addObserver(const LLUUID& avatar_id, LLAvatarPropertiesObserver* observer) void LLAvatarPropertiesProcessor::addObserver(const LLUUID& avatar_id, LLAvatarPropertiesObserver* observer)
{ {
if (!observer)
return;
// Check if that observer is already in mObservers for that avatar_id // Check if that observer is already in mObservers for that avatar_id
observer_multimap_t::iterator it; using pair = std::pair<LLUUID, LLAvatarPropertiesObserver*>;
observer_multimap_t::iterator begin = mObservers.begin();
observer_multimap_t::iterator end = mObservers.end();
observer_multimap_t::iterator it = std::find_if(begin, end, [&](const pair& p)
{
return p.first == avatar_id && p.second == observer;
});
// IAN BUG this should update the observer's UUID if this is a dupe - sent to PE // IAN BUG this should update the observer's UUID if this is a dupe - sent to PE
it = mObservers.find(avatar_id); if (it == end)
while (it != mObservers.end())
{ {
if (it->second == observer) mObservers.insert(pair(avatar_id, observer));
{
return;
}
else
{
++it;
}
} }
mObservers.insert(std::pair<LLUUID, LLAvatarPropertiesObserver*>(avatar_id, observer));
} }
void LLAvatarPropertiesProcessor::removeObserver(const LLUUID& avatar_id, LLAvatarPropertiesObserver* observer) void LLAvatarPropertiesProcessor::removeObserver(const LLUUID& avatar_id, LLAvatarPropertiesObserver* observer)
...@@ -79,19 +78,18 @@ void LLAvatarPropertiesProcessor::removeObserver(const LLUUID& avatar_id, LLAvat ...@@ -79,19 +78,18 @@ void LLAvatarPropertiesProcessor::removeObserver(const LLUUID& avatar_id, LLAvat
return; return;
} }
observer_multimap_t::iterator it; // Check if that observer is in mObservers for that avatar_id
it = mObservers.find(avatar_id); using pair = std::pair<LLUUID, LLAvatarPropertiesObserver*>;
while (it != mObservers.end()) observer_multimap_t::iterator begin = mObservers.begin();
{ observer_multimap_t::iterator end = mObservers.end();
if (it->second == observer) observer_multimap_t::iterator it = std::find_if(begin, end, [&](const pair& p)
{
mObservers.erase(it);
break;
}
else
{ {
++it; return p.first == avatar_id && p.second == observer;
} });
if (it != end)
{
mObservers.erase(it);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment