Eclipse 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-2019 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 /****************************************************************************/
17 // Stores time-dependant events and executes them at the proper time
18 /****************************************************************************/
19 #ifndef MSEventControl_h
20 #define MSEventControl_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <utility>
29 #include <queue>
30 #include <vector>
31 #include <map>
32 #include <utils/common/SUMOTime.h>
34 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 class Command;
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
50 public:
52  typedef std::pair< Command*, SUMOTime > Event;
53 
54 
55 public:
58 
59 
61  virtual ~MSEventControl();
62 
63 
70  virtual void addEvent(Command* operation, SUMOTime execTimeStep = -1);
71 
72 
90  virtual void execute(SUMOTime time);
91 
92 
97  bool isEmpty();
98 
99 
106  void setCurrentTimeStep(SUMOTime time);
107 
108 
109 protected:
115  public:
117  bool operator()(const Event& e1, const Event& e2) const {
118  return e1.second > e2.second;
119  }
120  };
121 
122 
123 private:
125  typedef std::priority_queue< Event, std::vector< Event >, EventSortCrit > EventCont;
126 
129 
132 
135 
136 
137 private:
140 
143 
144 
145 };
146 
147 
148 #endif
149 
150 /****************************************************************************/
151 
MSEventControl
Stores time-dependant events and executes them at the proper time.
Definition: MSEventControl.h:49
MSEventControl::EventCont
std::priority_queue< Event, std::vector< Event >, EventSortCrit > EventCont
Container for time-dependant events, e.g. traffic-light-change.
Definition: MSEventControl.h:125
MSEventControl::addEvent
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
Definition: MSEventControl.cpp:52
SUMOTime.h
MSEventControl::setCurrentTimeStep
void setCurrentTimeStep(SUMOTime time)
Set the current Time.
Definition: MSEventControl.cpp:100
MSEventControl::myEvents
EventCont myEvents
Event-container, holds executable events.
Definition: MSEventControl.h:131
MSEventControl::Event
std::pair< Command *, SUMOTime > Event
Combination of an event and the time it shall be executed at.
Definition: MSEventControl.h:52
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSEventControl::~MSEventControl
virtual ~MSEventControl()
Destructor.
Definition: MSEventControl.cpp:41
MSEventControl::EventSortCrit
Sort-criterion for events.
Definition: MSEventControl.h:114
MSEventControl::operator=
MSEventControl & operator=(const MSEventControl &)
invalid assignment operator.
UtilExceptions.h
MSEventControl::MSEventControl
MSEventControl(const MSEventControl &)
invalid copy constructor.
MSEventControl::currentTimeStep
SUMOTime currentTimeStep
The current TimeStep.
Definition: MSEventControl.h:128
MSEventControl::isEmpty
bool isEmpty()
Returns whether events are in the que.
Definition: MSEventControl.cpp:95
Command
Base (microsim) event class.
Definition: Command.h:52
MSEventControl::MSEventControl
MSEventControl()
Default constructor.
Definition: MSEventControl.cpp:37
MSEventControl::EventSortCrit::operator()
bool operator()(const Event &e1, const Event &e2) const
compares two events
Definition: MSEventControl.h:117
MSEventControl::execute
virtual void execute(SUMOTime time)
Executes time-dependant commands.
Definition: MSEventControl.cpp:58
config.h
MSEventControl::getCurrentTimeStep
SUMOTime getCurrentTimeStep()
get the Current TimeStep used in addEvent.
Definition: MSEventControl.cpp:105