SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00008 // A class that performs the loading of routes 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 <utils/common/MsgHandler.h> 00033 #include <utils/common/UtilExceptions.h> 00034 #include <utils/xml/XMLSubSys.h> 00035 #include "MSNet.h" 00036 #include "MSRouteHandler.h" 00037 #include "MSRouteLoader.h" 00038 00039 #ifdef CHECK_MEMORY_LEAKS 00040 #include <foreign/nvwa/debug_new.h> 00041 #endif // CHECK_MEMORY_LEAKS 00042 00043 00044 // =========================================================================== 00045 // method definitions 00046 // =========================================================================== 00047 MSRouteLoader::MSRouteLoader(MSNet&, 00048 MSRouteHandler* handler) 00049 : myParser(0), myMoreAvailable(true), myHandler(handler) { 00050 myParser = XMLSubSys::getSAXReader(*myHandler); 00051 } 00052 00053 00054 MSRouteLoader::~MSRouteLoader() { 00055 delete myParser; 00056 delete myHandler; 00057 } 00058 00059 00060 void 00061 MSRouteLoader::init() { 00062 myMoreAvailable = true; 00063 if (!myParser->parseFirst(myHandler->getFileName().c_str(), myToken)) { 00064 throw ProcessError("Can not read XML-file '" + myHandler->getFileName() + "'."); 00065 } 00066 } 00067 00068 00069 void 00070 MSRouteLoader::loadUntil(SUMOTime time) { 00071 // read only when further data is available, no error occured 00072 // and vehicles may be found in the between the departure time of 00073 // the last read vehicle and the time to read until 00074 if (!myMoreAvailable || time <= myHandler->getLastDepart()) { 00075 return; 00076 } 00077 00078 // read vehicles until specified time or the period to read vehicles 00079 // until is reached 00080 while (myParser->parseNext(myToken)) { 00081 // return when the last read vehicle is beyond the period 00082 if (time <= myHandler->getLastDepart()) { 00083 return; 00084 } 00085 } 00086 00087 // no data are available anymore 00088 myMoreAvailable = false; 00089 return; 00090 } 00091 00092 00093 bool 00094 MSRouteLoader::moreAvailable() const { 00095 return myMoreAvailable; 00096 } 00097 00098 00099 00100 /****************************************************************************/ 00101