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