- Use a NotifyLock instead of (History|Simulation)::set_notify_enabled() method, which is more elegant and also exception-safe

- Delete set_notify_enabled() method from ConcreteHistory; it was both wrong and useless, and caused impredictable behaviour!
- Don't make some methods of History and Simulation virtual if we don't want the user to override them
- Loading from file and jumping to an instant of the simulation should be much quickier now

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1170 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-09-15 09:34:12 +00:00
parent 737324f250
commit 83b655496f
11 changed files with 94 additions and 73 deletions

View file

@ -73,8 +73,8 @@ ConcreteSimulation::jump_to(History::position p) throw(UserInterruptException, N
// Disable momentarily updates for registered observers on
// sgpem::Simulation and sgpem::History.
bool his_enabled = _history.set_notify_enabled(false);
bool sim_enabled = set_notify_enabled(false);
History::LockNotify h_lock(_history);
Simulation::LockNotify s_lock(*this);
pause();
@ -82,30 +82,12 @@ ConcreteSimulation::jump_to(History::position p) throw(UserInterruptException, N
History::position increment = 0;
while (yet_to_finish && p > _history.get_front() + increment)
{
try
{
yet_to_finish = step();
increment++;
}
catch(const CPUPolicyException&)
{
// Lookout that notifications have to be re-enabled.
_history.set_notify_enabled(his_enabled);
set_notify_enabled(sim_enabled);
throw;
}
yet_to_finish = step();
increment++;
}
get_history().set_front(std::min(p, _history.get_size()));
if (!yet_to_finish)
stop();
// Reenables updates to registered observers.
// Calls _history.notify_change() on reactivation.
_history.set_notify_enabled(his_enabled);
// Do the same for notifications on the state
// of Simulation
set_notify_enabled(sim_enabled);
}