MSTriggeredReader.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // The basic class for classes that read triggers
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 
00020 // ===========================================================================
00021 // included modules
00022 // ===========================================================================
00023 #ifdef _MSC_VER
00024 #include <windows_config.h>
00025 #else
00026 #include <config.h>
00027 #endif
00028 
00029 #include <string>
00030 #include <microsim/MSNet.h>
00031 #include "MSTriggeredReader.h"
00032 
00033 #ifdef CHECK_MEMORY_LEAKS
00034 #include <foreign/nvwa/debug_new.h>
00035 #endif // CHECK_MEMORY_LEAKS
00036 
00037 
00038 // ===========================================================================
00039 // method definitions
00040 // ===========================================================================
00041 MSTriggeredReader::MSTriggeredReader(MSNet &)
00042         : myOffset(0), myWasInitialised(false) {}
00043 
00044 
00045 MSTriggeredReader::~MSTriggeredReader() {}
00046 
00047 
00048 void
00049 MSTriggeredReader::init() {
00050     myInit();
00051     myWasInitialised = true;
00052 }
00053 
00054 
00055 bool
00056 MSTriggeredReader::isInitialised() const {
00057     return myWasInitialised;
00058 }
00059 
00060 
00061 SUMOTime
00062 MSTriggeredReader::wrappedExecute(SUMOTime current) throw(ProcessError) {
00063     if (!isInitialised()) {
00064         init();
00065     }
00066     SUMOTime next = current;
00067     // loop until the next action lies in the future
00068     while (current==next) {
00069         // run the next action
00070         //  if it could be accomplished...
00071         if (processNextEntryReaderTriggered()) {
00072             // read the next one
00073             if (readNextTriggered()) {
00074                 // set the time for comparison if a next one exists
00075                 next = myOffset;
00076             } else {
00077                 // leave if no further exists
00078                 return 0;
00079             }
00080         } else {
00081             // action could not been accomplished; try next time step
00082             return DELTA_T;
00083         }
00084     }
00085     // come back if the next action shall be executed
00086     if (myOffset - current<=0) {
00087         // current is delayed;
00088         return DELTA_T;
00089     }
00090     return myOffset - current;
00091 }
00092 
00093 
00094 
00095 /****************************************************************************/
00096 

Generated on Wed May 5 00:06:32 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6