Eclipse SUMO - Simulation of Urban MObility
WrappingCommand< T > Class Template Reference

A wrapper for a Command function. More...

#include <WrappingCommand.h>

Inheritance diagram for WrappingCommand< T >:
[legend]
Collaboration diagram for WrappingCommand< T >:
[legend]

Public Types

typedef SUMOTime(T::* Operation) (SUMOTime)
 Type of the function to execute. More...
 

Public Member Functions

void deschedule ()
 Marks this Command as being descheduled. More...
 
bool isDescheduled ()
 whether this command has been descheduled More...
 
virtual SUMOTime shiftTime (SUMOTime, SUMOTime, SUMOTime)
 Reschedule or deschedule the command when quick-loading state. More...
 
 WrappingCommand (T *receiver, Operation operation)
 Constructor. More...
 
 ~WrappingCommand ()
 Destructor. More...
 
Derived from Command
SUMOTime execute (SUMOTime currentTime)
 Executes the command. More...
 

Private Attributes

bool myAmDescheduledByParent
 Whether this command was descheduled (is invalid) and shall not be executed. More...
 
Operation myOperation
 The object's operation to perform. More...
 
T * myReceiver
 The object the action is directed to. More...
 

Detailed Description

template<class T>
class WrappingCommand< T >

A wrapper for a Command function.

In order to ease life, this class may encapsulate a method of a class which in order to be used as a Command. This allows to use a member methods of a class to be called as Commands are, avoiding that the instance itself is destroyed by the EventHandler.

Because in some cases, the Command may live longer than the instance class, a boolean value indicates that the Command is "descheduled". It should be set via "deschedule" as soon as the class instance of which a method is encapsulated is destroyed and forces that the command (calling of this instace's method) is not executed.

See also
Design Patterns, Gamma et al.
Command
MSEventControl

Definition at line 48 of file WrappingCommand.h.

Member Typedef Documentation

◆ Operation

template<class T >
typedef SUMOTime(T::* WrappingCommand< T >::Operation) (SUMOTime)

Type of the function to execute.

Definition at line 51 of file WrappingCommand.h.

Constructor & Destructor Documentation

◆ WrappingCommand()

template<class T >
WrappingCommand< T >::WrappingCommand ( T *  receiver,
Operation  operation 
)
inline

Constructor.

Parameters
[in]receiverPointer to object of type T that will receive a call to one of it's methods.
[in]operationThe objects' method that will be called on execute()

Definition at line 61 of file WrappingCommand.h.

◆ ~WrappingCommand()

template<class T >
WrappingCommand< T >::~WrappingCommand ( )
inline

Destructor.

Definition at line 67 of file WrappingCommand.h.

Member Function Documentation

◆ deschedule()

template<class T >
void WrappingCommand< T >::deschedule ( )
inline

Marks this Command as being descheduled.

A simple boolean marker ("myAmDescheduledByParent") is set which prevents this command from being executed.

Definition at line 75 of file WrappingCommand.h.

References WrappingCommand< T >::myAmDescheduledByParent.

Referenced by MSDevice_ToC::awarenessRecoveryStep(), MSDevice_ToC::descheduleMRM(), MSDevice_ToC::descheduleRecovery(), MSDevice_ToC::descheduleToC(), MSDevice_ToC::descheduleToCPreparation(), MSDevice_Routing::notifyEnter(), MSTransportableDevice_Routing::setParameter(), MSDevice_Routing::~MSDevice_Routing(), MSDevice_ToC::~MSDevice_ToC(), and MSTransportableDevice_Routing::~MSTransportableDevice_Routing().

Here is the caller graph for this function:

◆ execute()

template<class T >
SUMOTime WrappingCommand< T >::execute ( SUMOTime  currentTime)
inlinevirtual

Executes the command.

If the command is not descheduled, the stored method of the stored instance is called.

Parameters
[in]currentTimeThe current simulation time
Returns
The time after which the command shall be executed again, 0 if this command shall be descheduled.
Exceptions
ProcessErrorDerived actions may throw this exception

Implements Command.

Definition at line 97 of file WrappingCommand.h.

References WrappingCommand< T >::myAmDescheduledByParent, WrappingCommand< T >::myOperation, and WrappingCommand< T >::myReceiver.

◆ isDescheduled()

template<class T >
bool WrappingCommand< T >::isDescheduled ( )
inline

whether this command has been descheduled

Definition at line 80 of file WrappingCommand.h.

References WrappingCommand< T >::myAmDescheduledByParent.

◆ shiftTime()

virtual SUMOTime Command::shiftTime ( SUMOTime  ,
SUMOTime  ,
SUMOTime   
)
inlinevirtualinherited

Reschedule or deschedule the command when quick-loading state.

The implementations should return -1 if the command shall not be re-scheduled, or a value >= 0 that describe the new time at which the command shall be executed again.

Parameters
[in]currentTimeThe current simulation time
[in]execTimeThe time at which the command would have been executed
[in]newTimeThe simulation time at which the simulation is restarted
Returns
The time at which the command shall be executed again

Reimplemented in MSTrafficLightLogic::SwitchCommand.

Definition at line 82 of file Command.h.

Field Documentation

◆ myAmDescheduledByParent

template<class T >
bool WrappingCommand< T >::myAmDescheduledByParent
private

Whether this command was descheduled (is invalid) and shall not be executed.

Definition at line 116 of file WrappingCommand.h.

Referenced by WrappingCommand< T >::deschedule(), WrappingCommand< T >::execute(), and WrappingCommand< T >::isDescheduled().

◆ myOperation

template<class T >
Operation WrappingCommand< T >::myOperation
private

The object's operation to perform.

Definition at line 113 of file WrappingCommand.h.

Referenced by WrappingCommand< T >::execute().

◆ myReceiver

template<class T >
T* WrappingCommand< T >::myReceiver
private

The object the action is directed to.

Definition at line 110 of file WrappingCommand.h.

Referenced by WrappingCommand< T >::execute().


The documentation for this class was generated from the following file: