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 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 <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, MSEmitControl* into) {
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+DELTA_T < myHandler->getLastDepart()) {
00073         return;
00074     }
00075 
00076     // if a vehicle was read before the call but was not yet added,
00077     //  add it now
00078     myHandler->retrieveLastReadVehicle(into);
00079     // read vehicles until specified time or the period to read vehicles
00080     //  until is reached
00081     while (myParser->parseNext(myToken)) {
00082         // return when the last read vehicle is beyond the period
00083         if (myHandler->getLastDepart()>=time) {
00084             return;
00085         }
00086         // otherwise add the last vehicle read (if any)
00087         myHandler->retrieveLastReadVehicle(into);
00088     }
00089 
00090     // no data are available anymore
00091     myMoreAvailable = false;
00092     return;
00093 }
00094 
00095 
00096 bool
00097 MSRouteLoader::moreAvailable() const {
00098     return myMoreAvailable;
00099 }
00100 
00101 
00102 
00103 /****************************************************************************/
00104 

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