SUMO - Simulation of Urban MObility
MSEventControl.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // Stores time-dependant events and executes them at the proper time
21 /****************************************************************************/
22 #ifndef MSEventControl_h
23 #define MSEventControl_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <utility>
36 #include <queue>
37 #include <vector>
38 #include <map>
39 #include <utils/common/SUMOTime.h>
41 
42 
43 // ===========================================================================
44 // class declarations
45 // ===========================================================================
46 class Command;
47 
48 
49 // ===========================================================================
50 // class definitions
51 // ===========================================================================
57 public:
59  typedef std::pair< Command*, SUMOTime > Event;
60 
61 
62 public:
65 
66 
68  virtual ~MSEventControl();
69 
70 
77  virtual void addEvent(Command* operation, SUMOTime execTimeStep = -1);
78 
79 
97  virtual void execute(SUMOTime time);
98 
99 
104  bool isEmpty();
105 
106 
113  void setCurrentTimeStep(SUMOTime time);
114 
115 
116 protected:
122  public:
124  bool operator()(const Event& e1, const Event& e2) const {
125  return e1.second > e2.second;
126  }
127  };
128 
129 
130 private:
132  typedef std::priority_queue< Event, std::vector< Event >, EventSortCrit > EventCont;
133 
136 
138  EventCont myEvents;
139 
142 
143 
144 private:
147 
150 
151 
152 };
153 
154 
155 #endif
156 
157 /****************************************************************************/
158 
Sort-criterion for events.
MSEventControl()
Default constructor.
virtual void execute(SUMOTime time)
Executes time-dependant commands.
Base (microsim) event class.
Definition: Command.h:60
bool operator()(const Event &e1, const Event &e2) const
compares two events
SUMOTime currentTimeStep
The current TimeStep.
void setCurrentTimeStep(SUMOTime time)
Set the current Time.
std::pair< Command *, SUMOTime > Event
Combination of an event and the time it shall be executed at.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
EventCont myEvents
Event-container, holds executable events.
SUMOTime getCurrentTimeStep()
get the Current TimeStep used in addEvent.
MSEventControl & operator=(const MSEventControl &)
invalid assignment operator.
virtual ~MSEventControl()
Destructor.
bool isEmpty()
Returns whether events are in the que.
std::priority_queue< Event, std::vector< Event >, EventSortCrit > EventCont
Container for time-dependant events, e.g. traffic-light-change.
long long int SUMOTime
Definition: TraCIDefs.h:51
Stores time-dependant events and executes them at the proper time.