SUMO - Simulation of Urban MObility
StaticCommand.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 StaticCommand_h
00022 #define StaticCommand_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 // ===========================================================================
00048 template< class T  >
00049 class StaticCommand : public Command {
00050 public:
00052     typedef SUMOTime(*Operation)(SUMOTime);
00053 
00054 
00055 public:
00062     StaticCommand(Operation operation)
00063         : myOperation(operation), myAmDescheduledByParent(false) {}
00064 
00065 
00067     ~StaticCommand() {}
00068 
00069 
00075     void deschedule() {
00076         myAmDescheduledByParent = true;
00077     }
00078 
00079 
00080 
00083 
00093     SUMOTime execute(SUMOTime currentTime) {
00094         // do not execute if the command was descheduled
00095         if (myAmDescheduledByParent) {
00096             return 0;
00097         }
00098         // execute if stil valid
00099         return (*myOperation)(currentTime);
00100     }
00102 
00103 
00104 private:
00106     Operation myOperation;
00107 
00109     bool myAmDescheduledByParent;
00110 
00111 
00112 };
00113 
00114 
00115 #endif
00116 
00117 /****************************************************************************/
00118 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines