/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file MSEventControl.h14/// @author Christian Roessel15/// @author Daniel Krajzewicz16/// @author Michael Behrisch17/// @author Matthias Heppner18/// @date Mon, 12 Mar 200119///20// Stores time-dependant events and executes them at the proper time21/****************************************************************************/22#pragma once23#include <config.h>2425#include <utility>26#include <queue>27#include <vector>28#include <map>29#include <utils/common/SUMOTime.h>30#include <utils/common/UtilExceptions.h>313233// ===========================================================================34// class declarations35// ===========================================================================36class Command;373839// ===========================================================================40// class definitions41// ===========================================================================42/**43* @class MSEventControl44* @brief Stores time-dependant events and executes them at the proper time45*/46class MSEventControl {47public:48/// @brief Combination of an event and the time it shall be executed at49typedef std::pair< Command*, SUMOTime > Event;505152public:53/// @brief Default constructor.54MSEventControl();555657/// @brief Destructor.58virtual ~MSEventControl();596061/** @brief Adds an Event.62*63* @param[in] operation The event to add64* @param[in] execTimeStep The time the event shall be executed at (-1 means at sim start)65* @see Command66*/67virtual void addEvent(Command* operation, SUMOTime execTimeStep = -1);686970/** @brief Executes time-dependant commands71*72* Loops over all stored events, continuing until the first event which73* execution time lies beyond the given time + deltaT. If the event74* had to be executed before the given time, a warning is generated and75* the event deleted. Otherwise (the event is valid), the event is executed.76*77* Each executed event must return the time that has to pass until it shall78* be executed again. If the returned time is 0, the event is deleted.79* Otherwise it is readded, after the new execution time (returned + current)80* is computed.81*82* ProcessErrors thrown by executed commands are rethrown.83*84* @param[in] time The current simulation time85* @exception ProcessError From an executed Command86*/87virtual void execute(SUMOTime time);888990/** @brief Returns whether events are in the que.91*92* @return whether events are in the que93*/94bool isEmpty();9596/** @brief Remove all events before quick-loading state */97void clearState(SUMOTime currentTime, SUMOTime newTime);9899/** @brief get the next scheduled event time for the given command, -2 if it is not scheduled */100SUMOTime getEventTime(Command* cmd) const;101102protected:103/// @brief compares two events104static bool eventCompare(const Event& e1, const Event& e2);105106107private:108/// @brief Event-container, holds executable events.109std::vector<Event> myEvents;110111112private:113/// @brief invalid copy constructor.114MSEventControl(const MSEventControl&);115116/// @brief invalid assignment operator.117MSEventControl& operator=(const MSEventControl&);118119120};121122123