bugfix: EventList::remove(event) must deal correctly with active events

before: active events were not properly deleted
        (in both cases, ev == 0 and ev != 0)
after: deficiencies repaired; simpler code
side-effect: doesn't return whether the event was found anymore
             (can be re-added at a later time)

git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1024 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
hsc
2012-04-03 14:05:28 +00:00
parent 643299c26e
commit 1466d24546
2 changed files with 19 additions and 20 deletions

View File

@ -16,27 +16,28 @@ EventId EventList::add(BaseEvent* ev, ExperimentFlow* pExp)
return (ev->getId()); return (ev->getId());
} }
bool EventList::remove(BaseEvent* ev) void EventList::remove(BaseEvent* ev)
{ {
if(ev != NULL) // possible cases:
{ // - ev == 0 -> remove all events
iterator it = std::find(m_BufferList.begin(), m_BufferList.end(), ev); // * clear m_BufferList
if(it != end()) // * copy m_FireList to m_DeleteList
{ if (ev == 0) {
m_BufferList.erase(it); m_BufferList.clear();
// all remaining active events must not fire anymore
m_DeleteList.insert(m_DeleteList.end(), m_FireList.begin(), m_FireList.end());
// - ev != 0 -> remove single event
// * find/remove ev in m_BufferList
// * if ev in m_FireList, copy to m_DeleteList
} else {
m_BufferList.remove(ev);
firelist_t::const_iterator it =
std::find(m_FireList.begin(), m_FireList.end(), ev);
if (it != m_FireList.end()) {
m_DeleteList.push_back(ev); m_DeleteList.push_back(ev);
return (true);
} }
} }
else
{
for(iterator it = m_BufferList.begin(); it != m_BufferList.end();
it++)
m_DeleteList.push_back(*it);
m_BufferList.clear();
return (true);
}
return (false);
} }
EventList::iterator EventList::remove(iterator it) EventList::iterator EventList::remove(iterator it)

View File

@ -82,10 +82,8 @@ class EventList
* @param ev the pointer of the event to be removed; if ev is set to * @param ev the pointer of the event to be removed; if ev is set to
* \c NULL, all events (for \a all experiments) will be * \c NULL, all events (for \a all experiments) will be
* removed * removed
* @return \c true if the object has been removed or \c false if the
* pointer could not be found
*/ */
bool remove(BaseEvent* ev); void remove(BaseEvent* ev);
/** /**
* Behaves like remove(BaseEvent) and additionally updates the provided * Behaves like remove(BaseEvent) and additionally updates the provided
* iteration. * iteration.