- Corrected get_front() issues.

- Widget tests are now working properly.



git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@990 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
matrevis 2006-09-02 01:56:00 +00:00
parent 4b3cce6bea
commit 47d4fe65b4
10 changed files with 49 additions and 30 deletions

View file

@ -122,7 +122,7 @@ ConcreteHistory::get_last_environment() const
{
// Should always be true:
assert(_snapshots.size() > 0);
return *_snapshots.back();
return get_environment_at(get_front());
}
@ -487,6 +487,16 @@ ConcreteHistory::edit_subrequest(SubRequest& subrequest,
reset(true);
}
void
ConcreteHistory::step_front(position p)
{
_front = p;
if (p > _snapshots.size())
_front = _snapshots.size();
notify_change();
}
void
ConcreteHistory::reset(bool notify)
{
@ -496,6 +506,7 @@ ConcreteHistory::reset(bool notify)
for_each(it, _snapshots.end(), deletor<ConcreteEnvironment>());
_snapshots.resize(1); // Truncate to keep only our "model"
_front = 0;
if (notify)
notify_change();

View file

@ -110,6 +110,7 @@ namespace sgpem
time_t duration);
virtual void step_front(position p);
virtual void reset(bool notify = true);

View file

@ -65,7 +65,6 @@ ConcreteSimulation::jump_to(History::position p) throw(UserInterruptException, N
break;
case state_stopped:
_history.reset(true);
_front = 0;
break;
default:
break;
@ -81,12 +80,15 @@ ConcreteSimulation::jump_to(History::position p) throw(UserInterruptException, N
_history.set_notify_enabled(false);
bool yet_to_finish = true;
while (yet_to_finish && p > _front)
History::position increment = 0;
while (yet_to_finish && p > _history.get_front() + increment)
{
yet_to_finish = step();
increment++;
}
get_history().step_front(p);
if (!yet_to_finish)
stop();
_front = std::min(p, _front);
// Reenables updates to registered observers.
// Calls _history.notify_change() on reactivation.
@ -125,7 +127,6 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException, Mal
{
case state_stopped:
_history.reset(true);
_front = 0;
break;
default:
break;
@ -135,6 +136,7 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException, Mal
//step forward
bool yet_to_finish = step();
get_history().step_front(get_history().get_front() + 1);
if (yet_to_finish)
{
if(_mode == mode_step_by_step)
@ -173,9 +175,8 @@ ConcreteSimulation::step()
{
//step forward
bool yet_to_finish = true;
if (_front == get_history().get_size() - 1)
if (get_history().get_front() == get_history().get_size() - 1)
yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy(), *get_resource_policy());
_front++;
return yet_to_finish;
}
catch (const CPUPolicyException& e)

View file

@ -30,7 +30,7 @@ using namespace std;
History::History()
: _notify(true)
: _front(0), _notify(true)
{}
@ -65,6 +65,11 @@ History::notify_change()
}
unsigned int History::get_front() const
{
return _front;
}
bool
History::set_notify_enabled(bool enabled)
{

View file

@ -128,6 +128,7 @@ namespace sgpem
resource_key_t resource_key,
time_t duration) = 0;
virtual position get_front() const;
virtual void attach(HistoryObserver& observer);
virtual void detach(const HistoryObserver& observer);
@ -148,7 +149,11 @@ namespace sgpem
virtual void notify_change();
position _front;
private:
bool _notify;
}

View file

@ -36,7 +36,7 @@ using namespace sgpem;
template class SG_DLLEXPORT Singleton<ConcreteSimulation>;
Simulation::Simulation()
: _notify(true), _front(0)
: _notify(true)
{
}
@ -65,11 +65,6 @@ Simulation::detach(const SimulationObserver& observer)
&observer));
}
unsigned int Simulation::get_front() const
{
return _front;
}
void
Simulation::notify_change()
{

View file

@ -159,8 +159,6 @@ namespace sgpem
virtual const History& get_history() const = 0;
virtual unsigned int get_front() const;
/**
* Small kludge to avoid the need for declaration of ConcreteSimulation
* by the calling code of Simulation::get_instance()
@ -186,9 +184,6 @@ namespace sgpem
typedef std::vector<SimulationObserver*> RegisteredObservers;
RegisteredObservers _observers;
// since no constructor is available, these fields must be defined in concrete subclasses.
History::position _front;
Simulation(); // Constructor
virtual void notify_change();