/****************************************************************************/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 StaticCommand.h14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @date Wed, 13.02.200817///18// A wrapper for a Command function19/****************************************************************************/20#pragma once21#include <config.h>22#include "Command.h"232425// ===========================================================================26// class definition27// ===========================================================================28/**29* @class StaticCommand30* @brief A wrapper for a Command function31*32* @see Design Patterns, Gamma et al.33* @see Command34* @see MSEventControl35*/36template< class T >37class StaticCommand : public Command {38public:39/// @brief Type of the function to execute.40typedef SUMOTime(*Operation)(SUMOTime);414243public:44/**45* @brief Constructor.46*47* @param[in] receiver Pointer to object of type T that will receive a call to one of its methods.48* @param[in] operation The objects' method that will be called on execute()49*/50StaticCommand(Operation operation)51: myOperation(operation), myAmDescheduledByParent(false) {}525354/// @brief Destructor55~StaticCommand() {}565758/** @brief Marks this Command as being descheduled59*60* A simple boolean marker ("myAmDescheduledByParent") is set which61* prevents this command from being executed.62*/63void deschedule() {64myAmDescheduledByParent = true;65}66676869/// @name Derived from Command70/// @{7172/** @brief Executes the command.73*74* If the command is not descheduled, the stored method of the stored instance75* is called.76*77* @param[in] currentTime The current simulation time78* @return The time after which the command shall be executed again, 0 if this command shall be descheduled.79* @exception ProcessError Derived actions may throw this exception80*/81SUMOTime execute(SUMOTime currentTime) {82// do not execute if the command was descheduled83if (myAmDescheduledByParent) {84return 0;85}86// execute if stil valid87return (*myOperation)(currentTime);88}89/// @}909192private:93/// @brief The object's operation to perform.94Operation myOperation;9596/// @brief Whether this command was descheduled (is invalid) and shall not be executed97bool myAmDescheduledByParent;9899100};101102103