Eclipse SUMO - Simulation of Urban MObility
ParametrisedWrappingCommand.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 /****************************************************************************/
14 // A wrapper for a Command function with parameter
15 /****************************************************************************/
16 
17 #ifndef UTILS_COMMON_PARAMETRISEDWRAPPINGCOMMAND_H_
18 #define UTILS_COMMON_PARAMETRISEDWRAPPINGCOMMAND_H_
19 
20 #include "Command.h"
21 
22 
23 // ===========================================================================
24 // class definition
25 // ===========================================================================
31 template< class T, class S >
33 public:
34 
36  typedef SUMOTime(T::* Operation)(SUMOTime, S);
37 
38 public:
39 
47  ParametrisedWrappingCommand(T* receiver, const S& param, Operation operation)
48  : myReceiver(receiver), myParameter(param), myOperation(operation),
49  myAmDescheduledByParent(false) {}
50 
51 
54 
55 
61  void deschedule() {
63  }
64 
66  bool isDescheduled() {
68  }
69 
70 
73 
83  SUMOTime execute(SUMOTime currentTime) {
84  // do not execute if the command was descheduled
86  return 0;
87  }
88  // execute if stil valid
89  return (myReceiver->*myOperation)(currentTime, myParameter);
90  }
92 
93 
94 private:
97 
100 
103 
106 
107 };
108 
109 #endif /* UTILS_COMMON_PARAMETRISEDWRAPPINGCOMMAND_H_ */
ParametrisedWrappingCommand::myParameter
S myParameter
The parameter.
Definition: ParametrisedWrappingCommand.h:99
ParametrisedWrappingCommand::Operation
SUMOTime(T::* Operation)(SUMOTime, S)
Type of the function to execute. (with parameter)
Definition: ParametrisedWrappingCommand.h:36
ParametrisedWrappingCommand::execute
SUMOTime execute(SUMOTime currentTime)
Executes the command.
Definition: ParametrisedWrappingCommand.h:83
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
ParametrisedWrappingCommand::isDescheduled
bool isDescheduled()
whether this command has been descheduled
Definition: ParametrisedWrappingCommand.h:66
ParametrisedWrappingCommand::ParametrisedWrappingCommand
ParametrisedWrappingCommand(T *receiver, const S &param, Operation operation)
Constructor.
Definition: ParametrisedWrappingCommand.h:47
ParametrisedWrappingCommand::myReceiver
T * myReceiver
The object the action is directed to.
Definition: ParametrisedWrappingCommand.h:96
ParametrisedWrappingCommand::deschedule
void deschedule()
Marks this Command as being descheduled.
Definition: ParametrisedWrappingCommand.h:61
ParametrisedWrappingCommand::~ParametrisedWrappingCommand
~ParametrisedWrappingCommand()
Destructor.
Definition: ParametrisedWrappingCommand.h:53
Command
Base (microsim) event class.
Definition: Command.h:52
ParametrisedWrappingCommand
A wrapper for a Command function with parameter.
Definition: ParametrisedWrappingCommand.h:32
ParametrisedWrappingCommand::myAmDescheduledByParent
bool myAmDescheduledByParent
Whether this command was descheduled (is invalid) and shall not be executed.
Definition: ParametrisedWrappingCommand.h:105
ParametrisedWrappingCommand::myOperation
Operation myOperation
The object's operation to perform.
Definition: ParametrisedWrappingCommand.h:102
Command.h