SUMO - Simulation of Urban MObility

MSRouteLoader.cpp

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