SUMO - Simulation of Urban MObility
WrappingCommand.h
Go to the documentation of this file.
00001 /****************************************************************************/
00008 // A wrapper for a Command function
00009 /****************************************************************************/
00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00012 /****************************************************************************/
00013 //
00014 //   This file is part of SUMO.
00015 //   SUMO is free software: you can redistribute it and/or modify
00016 //   it under the terms of the GNU General Public License as published by
00017 //   the Free Software Foundation, either version 3 of the License, or
00018 //   (at your option) any later version.
00019 //
00020 /****************************************************************************/
00021 #ifndef WrappingCommand_h
00022 #define WrappingCommand_h
00023 
00024 
00025 // ===========================================================================
00026 // included modules
00027 // ===========================================================================
00028 #ifdef _MSC_VER
00029 #include <windows_config.h>
00030 #else
00031 #include <config.h>
00032 #endif
00033 
00034 #include "Command.h"
00035 
00036 
00037 // ===========================================================================
00038 // class definition
00039 // ===========================================================================
00059 template< class T  >
00060 class WrappingCommand : public Command {
00061 public:
00063     typedef SUMOTime(T::* Operation)(SUMOTime);
00064 
00065 
00066 public:
00073     WrappingCommand(T* receiver, Operation operation)
00074         : myReceiver(receiver), myOperation(operation),
00075           myAmDescheduledByParent(false) {}
00076 
00077 
00079     ~WrappingCommand() {}
00080 
00081 
00087     void deschedule() {
00088         myAmDescheduledByParent = true;
00089     }
00090 
00091 
00092 
00095 
00105     SUMOTime execute(SUMOTime currentTime) {
00106         // do not execute if the command was descheduled
00107         if (myAmDescheduledByParent) {
00108             return 0;
00109         }
00110         // execute if stil valid
00111         return (myReceiver->*myOperation)(currentTime);
00112     }
00114 
00115 
00116 private:
00118     T* myReceiver;
00119 
00121     Operation myOperation;
00122 
00124     bool myAmDescheduledByParent;
00125 
00126 
00127 };
00128 
00129 
00130 #endif
00131 
00132 /****************************************************************************/
00133 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines