adevs
adevs_abstract_simulator.h
1 
31 #ifndef __adevs_abstract_simulator_h_
32 #define __adevs_abstract_simulator_h_
33 #include "adevs_models.h"
34 #include "adevs_event_listener.h"
35 #include "adevs_bag.h"
36 
37 namespace adevs
38 {
39 
45 template <class X, class T = double> class AbstractSimulator
46 {
47  public:
54  {
55  listeners.insert(l);
56  }
59  {
60  listeners.erase(l);
61  }
63  virtual T nextEventTime() = 0;
65  virtual void execUntil(T tend) = 0;
67  virtual ~AbstractSimulator(){}
69  void notify_output_listeners(Devs<X,T>* model, const X& value, T t);
71  void notify_state_listeners(Atomic<X,T>* model, T t);
72  private:
74  Bag<EventListener<X,T>*> listeners;
75 
76 };
77 
78 template <class X, class T>
80 {
81  Event<X,T> event(model,value);
82  typename Bag<EventListener<X,T>*>::iterator iter;
83  for (iter = listeners.begin(); iter != listeners.end(); iter++)
84  {
85  (*iter)->outputEvent(event,t);
86  }
87 }
88 
89 template <class X, class T>
91 {
92  typename Bag<EventListener<X,T>*>::iterator iter;
93  for (iter = listeners.begin(); iter != listeners.end(); iter++)
94  {
95  (*iter)->stateChange(model,t);
96  }
97 }
98 
99 } // end of namespace
100 
101 #endif
Definition: adevs_event_listener.h:43
Definition: adevs_abstract_simulator.h:45
void notify_output_listeners(Devs< X, T > *model, const X &value, T t)
Notify listeners of an output event.
Definition: adevs_abstract_simulator.h:79
iterator begin() const
Get an iterator pointing to the first element in the bag.
Definition: adevs_bag.h:128
virtual void execUntil(T tend)=0
Execute the simulator until the next event time is greater than tend.
iterator end() const
Get an iterator to the end of the bag (i.e., just after the last element)
Definition: adevs_bag.h:130
Definition: adevs_models.h:63
virtual ~AbstractSimulator()
Destructor leaves the model intact.
Definition: adevs_abstract_simulator.h:67
void addEventListener(EventListener< X, T > *l)
Definition: adevs_abstract_simulator.h:53
Definition: adevs_models.h:142
Definition: adevs_models.h:47
virtual T nextEventTime()=0
Get the model's next event time.
void notify_state_listeners(Atomic< X, T > *model, T t)
Notify listeners of a state change.
Definition: adevs_abstract_simulator.h:90
void removeEventListener(EventListener< X, T > *l)
Remove an event listener.
Definition: adevs_abstract_simulator.h:58
Definition: adevs_bag.h:45