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 /****************************************************************************/ 10 /// @file Command.h 11 /// @author Christian Roessel 12 /// @author Daniel Krajzewicz 13 /// @date Thu, 20 Dec 2001 14 /// @version $Id$ 15 /// 16 // Base (microsim) event class 17 /****************************************************************************/ 18 #ifndef Command_h 19 #define Command_h 20 21 22 // =========================================================================== 23 // included modules 24 // =========================================================================== 25 26 #include <utils/common/SUMOTime.h> 27 #include <utils/common/UtilExceptions.h> 28 29 30 // =========================================================================== 31 // class definitions 32 // =========================================================================== 33 /** 34 * @class Command 35 * @brief Base (microsim) event class 36 * 37 * Classes derived from Command may be added to MSEventControl instances in 38 * order to be executed at a certain time step. 39 * 40 * As soon as the simulation reaches the desired time step, the command (event) 41 * is executed by calling "execute" with the current time step. The method must 42 * return either 0, if the event shall not be executed again or a positive value 43 * (in simulation seconds) that described when it shall be executed again. The method 44 * must not return a value below zero, the behaviour is undefined in this case. 45 * 46 * @warning The EventControl the Command is added to gets responsible for 47 * this command's deletion. 48 * 49 * @see Design Patterns, Gamma et al. 50 * @see WrappingCommand 51 * @see MSEventControl 52 */ 53 class Command { 54 public: 55 /// @brief Constructor Command()56 Command() { } 57 58 59 /// @brief Destructor. ~Command()60 virtual ~Command() { } 61 62 63 /** @brief Executes the command. 64 * 65 * The implementations should return 0 if the command shall not be repeated, 66 * or a value larger than 0 that describe the time after which the command 67 * shall be executed again. Values below 0 must not be returned. 68 * 69 * @param[in] currentTime The current simulation time 70 * @return The time after which the command shall be executed again, 0 if this command shall be descheduled. 71 * @exception ProcessError Derived actions may throw this exception 72 */ 73 virtual SUMOTime execute(SUMOTime currentTime) = 0; 74 75 76 }; 77 78 79 #endif 80 81 /****************************************************************************/ 82 83