- Pay attention to iterators invalidated by Container.erase(it) methods.

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@782 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-07-19 15:50:57 +00:00
parent 95ef5eba53
commit e3d2381212
2 changed files with 34 additions and 24 deletions

View File

@ -20,8 +20,6 @@
#include "config.h"
#include "concrete_history.hh"
#include "dynamic_process.hh"
#include "dynamic_thread.hh"
#include "dynamic_resource.hh"
@ -34,6 +32,9 @@
#include "static_request.hh"
#include "static_sub_request.hh"
#include "history_observer.hh"
#include "concrete_history.hh"
#include "smartp.tcc"
#include <algorithm>
@ -145,32 +146,37 @@ ConcreteHistory::remove(resource_key_t resource_key)
delete found->second;
resources.erase(found);
// Now search and erase subrequest that had a ref to the
// removed resource
typedef std::vector<DynamicThread*> Threads;
typedef std::vector<DynamicRequest*> Requests;
typedef std::vector<DynamicSubRequest*> SubRequests;
// Listening to "The Thing That Should Not Be"...
// all hail the cyclomatic complexity!
ConcreteEnvironment::Processes& processes = initial.get_processes();
typedef ConcreteEnvironment::Processes::iterator ProcIt;
for(ProcIt it1 = processes.begin(); it1 != processes.end(); it1++)
{
typedef std::vector<DynamicThread*> Threads;
Threads& threads = dynamic_cast<DynamicProcess&>(**it1).get_dynamic_threads();
for(Threads::iterator it2 = threads.begin(); it2 != threads.end(); it2++)
{
typedef std::vector<DynamicRequest*> Requests;
Requests& reqs = (*it2)->get_dynamic_requests();
for(Requests::iterator it3 = reqs.begin(); it3 != reqs.end(); it3++)
{
typedef std::vector<DynamicSubRequest*> SubRequests;
SubRequests& subr = (*it3)->get_dynamic_subrequests();
for(SubRequests::iterator it4 = subr.begin(); it4 != subr.end(); it4++)
{
if((*it4)->get_resource_key() == resource_key)
{
delete *it4;
subr.erase(it4);
}
}
SubRequests::iterator it4 = subr.begin();
while(it4 != subr.end())
if((*it4)->get_resource_key() == resource_key)
{
delete *it4;
it4 = subr.erase(it4);
}
else
it4++;
}
}
}
} //~ end monstrous construct, "The Thing That Should Not Be"
// Chtulhu ftaghn. There are worse things in life. Mother-in-laws,
// for example. Or hangovers. Or being read poetry by a Vogon.
@ -395,5 +401,7 @@ ConcreteHistory::reset(bool notify)
void
ConcreteHistory::notify_change()
{
// FIXME write code for this method. won't link without this stub
History::RegisteredObservers::iterator it;
for(it =_observers.begin(); it != _observers.end(); it++)
(*it)->update(*this);
}

View File

@ -125,14 +125,16 @@ PoliciesGatekeeper::deactivate_policies(PolicyManager* manager)
// library utilities?
ActiveIterator act_it = _active_policies.begin();
for(; act_it != _active_policies.end(); ++act_it)
{
if(act_it->second == *avail_it)
{
act_it->second->deactivate();
_active_policies.erase(act_it);
}
}
}
while(act_it != _active_policies.end())
{
if(act_it->second == *avail_it)
{
act_it->second->deactivate();
act_it = _active_policies.erase(act_it);
}
else
act_it++;
}
} //~ for(avail_it)
}