- 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 "config.h"
#include "concrete_history.hh"
#include "dynamic_process.hh" #include "dynamic_process.hh"
#include "dynamic_thread.hh" #include "dynamic_thread.hh"
#include "dynamic_resource.hh" #include "dynamic_resource.hh"
@ -34,6 +32,9 @@
#include "static_request.hh" #include "static_request.hh"
#include "static_sub_request.hh" #include "static_sub_request.hh"
#include "history_observer.hh"
#include "concrete_history.hh"
#include "smartp.tcc" #include "smartp.tcc"
#include <algorithm> #include <algorithm>
@ -145,30 +146,35 @@ ConcreteHistory::remove(resource_key_t resource_key)
delete found->second; delete found->second;
resources.erase(found); 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"... // Listening to "The Thing That Should Not Be"...
// all hail the cyclomatic complexity! // all hail the cyclomatic complexity!
ConcreteEnvironment::Processes& processes = initial.get_processes(); ConcreteEnvironment::Processes& processes = initial.get_processes();
typedef ConcreteEnvironment::Processes::iterator ProcIt; typedef ConcreteEnvironment::Processes::iterator ProcIt;
for(ProcIt it1 = processes.begin(); it1 != processes.end(); it1++) for(ProcIt it1 = processes.begin(); it1 != processes.end(); it1++)
{ {
typedef std::vector<DynamicThread*> Threads;
Threads& threads = dynamic_cast<DynamicProcess&>(**it1).get_dynamic_threads(); Threads& threads = dynamic_cast<DynamicProcess&>(**it1).get_dynamic_threads();
for(Threads::iterator it2 = threads.begin(); it2 != threads.end(); it2++) for(Threads::iterator it2 = threads.begin(); it2 != threads.end(); it2++)
{ {
typedef std::vector<DynamicRequest*> Requests;
Requests& reqs = (*it2)->get_dynamic_requests(); Requests& reqs = (*it2)->get_dynamic_requests();
for(Requests::iterator it3 = reqs.begin(); it3 != reqs.end(); it3++) for(Requests::iterator it3 = reqs.begin(); it3 != reqs.end(); it3++)
{ {
typedef std::vector<DynamicSubRequest*> SubRequests;
SubRequests& subr = (*it3)->get_dynamic_subrequests(); SubRequests& subr = (*it3)->get_dynamic_subrequests();
for(SubRequests::iterator it4 = subr.begin(); it4 != subr.end(); it4++) SubRequests::iterator it4 = subr.begin();
{ while(it4 != subr.end())
if((*it4)->get_resource_key() == resource_key) if((*it4)->get_resource_key() == resource_key)
{ {
delete *it4; delete *it4;
subr.erase(it4); it4 = subr.erase(it4);
}
} }
else
it4++;
} }
} }
} //~ end monstrous construct, "The Thing That Should Not Be" } //~ end monstrous construct, "The Thing That Should Not Be"
@ -395,5 +401,7 @@ ConcreteHistory::reset(bool notify)
void void
ConcreteHistory::notify_change() 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? // library utilities?
ActiveIterator act_it = _active_policies.begin(); ActiveIterator act_it = _active_policies.begin();
for(; act_it != _active_policies.end(); ++act_it) while(act_it != _active_policies.end())
{ {
if(act_it->second == *avail_it) if(act_it->second == *avail_it)
{ {
act_it->second->deactivate(); act_it->second->deactivate();
_active_policies.erase(act_it); act_it = _active_policies.erase(act_it);
}
} }
else
act_it++;
} }
} //~ for(avail_it)
} }