|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A wrapper for a Command function 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 #ifndef StaticCommand_h 00020 #define StaticCommand_h 00021 00022 00023 // =========================================================================== 00024 // included modules 00025 // =========================================================================== 00026 #ifdef _MSC_VER 00027 #include <windows_config.h> 00028 #else 00029 #include <config.h> 00030 #endif 00031 00032 #include "Command.h" 00033 00034 00035 // =========================================================================== 00036 // class definition 00037 // =========================================================================== 00046 template< class T > 00047 class StaticCommand : public Command { 00048 public: 00050 typedef SUMOTime(*Operation)(SUMOTime); 00051 00052 00053 public: 00060 StaticCommand(Operation operation) 00061 : myOperation(operation), myAmDescheduledByParent(false) {} 00062 00063 00065 ~StaticCommand() {} 00066 00067 00073 void deschedule() { 00074 myAmDescheduledByParent = true; 00075 } 00076 00077 00078 00081 00091 SUMOTime execute(SUMOTime currentTime) { 00092 // do not execute if the command was descheduled 00093 if (myAmDescheduledByParent) { 00094 return 0; 00095 } 00096 // execute if stil valid 00097 return (*myOperation)(currentTime); 00098 } 00100 00101 00102 private: 00104 Operation myOperation; 00105 00107 bool myAmDescheduledByParent; 00108 00109 00110 }; 00111 00112 00113 #endif 00114 00115 /****************************************************************************/ 00116