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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
18 // Stores time-dependant events and executes them at the proper time
19 /****************************************************************************/
20 #ifndef MSEventControl_h
21 #define MSEventControl_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <utility>
30 #include <queue>
31 #include <vector>
32 #include <map>
33 #include <utils/common/SUMOTime.h>
35 
36 
37 // ===========================================================================
38 // class declarations
39 // ===========================================================================
40 class Command;
41 
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
51 public:
53  typedef std::pair< Command*, SUMOTime > Event;
54 
55 
56 public:
59 
60 
62  virtual ~MSEventControl();
63 
64 
71  virtual void addEvent(Command* operation, SUMOTime execTimeStep = -1);
72 
73 
91  virtual void execute(SUMOTime time);
92 
93 
98  bool isEmpty();
99 
100 
107  void setCurrentTimeStep(SUMOTime time);
108 
109 
110 protected:
116  public:
118  bool operator()(const Event& e1, const Event& e2) const {
119  return e1.second > e2.second;
120  }
121  };
122 
123 
124 private:
126  typedef std::priority_queue< Event, std::vector< Event >, EventSortCrit > EventCont;
127 
130 
132  EventCont myEvents;
133 
136 
137 
138 private:
141 
144 
145 
146 };
147 
148 
149 #endif
150 
151 /****************************************************************************/
152 
Sort-criterion for events.
long long int SUMOTime
Definition: SUMOTime.h:36
MSEventControl()
Default constructor.
virtual void execute(SUMOTime time)
Executes time-dependant commands.
Base (microsim) event class.
Definition: Command.h:54
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.
Stores time-dependant events and executes them at the proper time.