- Fix a leak in HoltWidget

- Add a for_each_in() template in sequences.tcc


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1029 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-09-06 18:31:32 +00:00
parent 8e20f5499f
commit 93fefe49e0
2 changed files with 27 additions and 3 deletions

View File

@ -28,8 +28,10 @@
#include "backend/thread.hh" #include "backend/thread.hh"
#include "holt_widget.hh" #include "holt_widget.hh"
#include "deletor.tcc"
#include "sequences.tcc"
#include <math.h> #include <math.h>
#include <iostream>
#include <cassert> #include <cassert>
@ -44,7 +46,6 @@ using namespace std;
HoltNode::HoltNode(Vec2 pt) HoltNode::HoltNode(Vec2 pt)
: _radius(20) : _radius(20)
{ {
@ -520,9 +521,18 @@ void
HoltWidget::acquire() HoltWidget::acquire()
{ {
std::cout << "HoltWidget::acquire" << endl; std::cout << "HoltWidget::acquire" << endl;
const HoltResources& const_holt_resources = _holt_resources;
for(Iseq<HoltResources::const_iterator> it = iseq(const_holt_resources); it; ++it)
delete it->second;
_holt_resources.clear(); _holt_resources.clear();
for_each_in(_holt_schedulables, memory::deletor<HoltSchedulable>());
_holt_schedulables.clear(); _holt_schedulables.clear();
for_each_in(_holt_requests, memory::deletor<HoltRequest>());
_holt_requests.clear(); _holt_requests.clear();
_n_res = _n_proc = 0; _n_res = _n_proc = 0;
const History& hist = _simulation->get_history(); const History& hist = _simulation->get_history();

View File

@ -95,3 +95,17 @@ riseq(Container& c)
{ {
return Iseq<typename Container::reverse_iterator>(c.rbegin(), c.rend()); return Iseq<typename Container::reverse_iterator>(c.rbegin(), c.rend());
} }
template<class Container, class Functor>
Functor
for_each_in(const Container& c, Functor functor)
{
Iseq<typename Container::const_iterator> seq = iseq(c);
while(seq)
{
functor(*seq);
++seq;
}
return functor;
}