SUMO - Simulation of Urban MObility
ROTypedXMLRoutesLoader.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00008 // Base class for loading routes from XML-files
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 // included modules
00023 // ===========================================================================
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029 
00030 #include <string>
00031 #include <xercesc/parsers/SAXParser.hpp>
00032 #include <xercesc/util/PlatformUtils.hpp>
00033 #include <xercesc/util/TransService.hpp>
00034 #include <xercesc/sax2/SAX2XMLReader.hpp>
00035 #include <utils/common/UtilExceptions.h>
00036 #include <utils/common/MsgHandler.h>
00037 #include <utils/xml/XMLSubSys.h>
00038 #include <utils/common/StdDefs.h>
00039 #include "ROTypedXMLRoutesLoader.h"
00040 #include "RONet.h"
00041 
00042 #ifdef CHECK_MEMORY_LEAKS
00043 #include <foreign/nvwa/debug_new.h>
00044 #endif // CHECK_MEMORY_LEAKS
00045 
00046 
00047 // ===========================================================================
00048 // method definitions
00049 // ===========================================================================
00050 ROTypedXMLRoutesLoader::ROTypedXMLRoutesLoader(RONet& net,
00051         SUMOTime begin,
00052         SUMOTime end,
00053         const std::string& file)
00054     : myNet(net), myBegin(begin), myEnd(end), SUMOSAXHandler(file),
00055       myParser(0), myToken(), myEnded(false), myCurrentDepart(-1), myNextRouteRead(false) {
00056     try {
00057         myParser = XMLSubSys::getSAXReader(*this);
00058         myParser->parseFirst(getFileName().c_str(), myToken);
00059     } catch (...) {
00060         throw ProcessError();
00061     }
00062 }
00063 
00064 
00065 ROTypedXMLRoutesLoader::~ROTypedXMLRoutesLoader() {
00066     delete myParser;
00067 }
00068 
00069 
00070 bool
00071 ROTypedXMLRoutesLoader::readRoutesAtLeastUntil(SUMOTime time) {
00072     while (getLastReadTimeStep() < time && !ended()) {
00073         myNextRouteRead = false;
00074         while (!myNextRouteRead && !ended()) {
00075             myParser->parseNext(myToken);
00076         }
00077     }
00078     return true;
00079 }
00080 
00081 
00082 void
00083 ROTypedXMLRoutesLoader::endDocument() {
00084     myEnded = true;
00085 }
00086 
00087 
00088 
00089 
00090 /****************************************************************************/
00091 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines