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 /****************************************************************************/
15 // A wrapper for a Command function with parameter
16 /****************************************************************************/
17 
18 #ifndef UTILS_COMMON_PARAMETRISEDWRAPPINGCOMMAND_H_
19 #define UTILS_COMMON_PARAMETRISEDWRAPPINGCOMMAND_H_
20 
21 #include "Command.h"
22 
23 
24 // ===========================================================================
25 // class definition
26 // ===========================================================================
32 template< class T, class S >
34 public:
35 
37  typedef SUMOTime(T::* Operation)(SUMOTime, S);
38 
39 public:
40 
48  ParametrisedWrappingCommand(T* receiver, const S& param, Operation operation)
49  : myReceiver(receiver), myParameter(param), myOperation(operation),
50  myAmDescheduledByParent(false) {}
51 
52 
55 
56 
62  void deschedule() {
64  }
65 
67  bool isDescheduled() {
69  }
70 
71 
74 
84  SUMOTime execute(SUMOTime currentTime) {
85  // do not execute if the command was descheduled
87  return 0;
88  }
89  // execute if stil valid
90  return (myReceiver->*myOperation)(currentTime, myParameter);
91  }
93 
94 
95 private:
98 
101 
104 
107 
108 };
109 
110 #endif /* UTILS_COMMON_PARAMETRISEDWRAPPINGCOMMAND_H_ */
long long int SUMOTime
Definition: SUMOTime.h:35
bool isDescheduled()
whether this command has been descheduled
T * myReceiver
The object the action is directed to.
Base (microsim) event class.
Definition: Command.h:53
ParametrisedWrappingCommand(T *receiver, const S &param, Operation operation)
Constructor.
Operation myOperation
The object&#39;s operation to perform.
A wrapper for a Command function with parameter.
bool myAmDescheduledByParent
Whether this command was descheduled (is invalid) and shall not be executed.
void deschedule()
Marks this Command as being descheduled.
SUMOTime(T::* Operation)(SUMOTime, S)
Type of the function to execute. (with parameter)
SUMOTime execute(SUMOTime currentTime)
Executes the command.