SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00010 // Stores time-dependant events and executes them at the proper time 00011 /****************************************************************************/ 00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00014 /****************************************************************************/ 00015 // 00016 // This file is part of SUMO. 00017 // SUMO is free software: you can redistribute it and/or modify 00018 // it under the terms of the GNU General Public License as published by 00019 // the Free Software Foundation, either version 3 of the License, or 00020 // (at your option) any later version. 00021 // 00022 /****************************************************************************/ 00023 #ifndef MSEventControl_h 00024 #define MSEventControl_h 00025 00026 00027 // =========================================================================== 00028 // included modules 00029 // =========================================================================== 00030 #ifdef _MSC_VER 00031 #include <windows_config.h> 00032 #else 00033 #include <config.h> 00034 #endif 00035 00036 #include <utility> 00037 #include <queue> 00038 #include <vector> 00039 #include <map> 00040 #include <utils/common/SUMOTime.h> 00041 #include <utils/common/UtilExceptions.h> 00042 00043 00044 // =========================================================================== 00045 // class declarations 00046 // =========================================================================== 00047 class Command; 00048 00049 00050 // =========================================================================== 00051 // class definitions 00052 // =========================================================================== 00057 class MSEventControl { 00058 public: 00060 typedef std::pair< Command*, SUMOTime > Event; 00061 00062 00067 enum AdaptType { 00069 ADAPT_AFTER_EXECUTION = 1, 00071 NO_CHANGE = 2 00072 }; 00073 00074 00075 public: 00077 MSEventControl(); 00078 00079 00081 virtual ~MSEventControl(); 00082 00083 00098 virtual SUMOTime addEvent(Command* operation, SUMOTime execTimeStep, 00099 AdaptType type); 00100 00101 00119 virtual void execute(SUMOTime time); 00120 00121 00126 bool isEmpty(); 00127 00128 00135 void setCurrentTimeStep(SUMOTime time); 00136 00137 00138 protected: 00143 class EventSortCrit { 00144 public: 00146 bool operator()(const Event& e1, const Event& e2) const { 00147 return e1.second > e2.second; 00148 } 00149 }; 00150 00151 00152 private: 00154 typedef std::priority_queue< Event, std::vector< Event >, EventSortCrit > EventCont; 00155 00157 SUMOTime currentTimeStep; 00158 00160 EventCont myEvents; 00161 00163 SUMOTime getCurrentTimeStep(); 00164 00165 00166 private: 00168 MSEventControl(const MSEventControl&); 00169 00171 MSEventControl& operator=(const MSEventControl&); 00172 00173 00174 }; 00175 00176 00177 #endif 00178 00179 /****************************************************************************/ 00180