00001 /****************************************************************************/ 00007 // A wrapper for a Command function 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright 2001-2010 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 WrappingCommand_h 00020 #define WrappingCommand_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 // =========================================================================== 00057 template< class T > 00058 class WrappingCommand : public Command { 00059 public: 00061 typedef SUMOTime(T::* Operation)(SUMOTime); 00062 00063 00064 public: 00071 WrappingCommand(T* receiver, Operation operation) throw() 00072 : myReceiver(receiver), myOperation(operation), 00073 myAmDescheduledByParent(false) {} 00074 00075 00077 ~WrappingCommand() throw() {} 00078 00079 00085 void deschedule() { 00086 myAmDescheduledByParent = true; 00087 } 00088 00089 00090 00093 00103 SUMOTime execute(SUMOTime currentTime) throw(ProcessError) { 00104 // do not execute if the command was descheduled 00105 if (myAmDescheduledByParent) { 00106 return 0; 00107 } 00108 // execute if stil valid 00109 return (myReceiver->*myOperation)(currentTime); 00110 } 00112 00113 00114 private: 00116 T* myReceiver; 00117 00119 Operation myOperation; 00120 00122 bool myAmDescheduledByParent; 00123 00124 00125 }; 00126 00127 00128 #endif 00129 00130 /****************************************************************************/ 00131
1.5.6