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 "ROAbstractRouteDefLoader.h"
00040 #include "ROTypedXMLRoutesLoader.h"
00041 #include "RONet.h"
00042 
00043 #ifdef CHECK_MEMORY_LEAKS
00044 #include <foreign/nvwa/debug_new.h>
00045 #endif // CHECK_MEMORY_LEAKS
00046 
00047 
00048 // ===========================================================================
00049 // method definitions
00050 // ===========================================================================
00051 ROTypedXMLRoutesLoader::ROTypedXMLRoutesLoader(RONet& net,
00052         SUMOTime begin,
00053         SUMOTime end,
00054         const std::string& file)
00055     : ROAbstractRouteDefLoader(net, begin, end),
00056       SUMOSAXHandler(file),
00057       myParser(0), myToken(), myEnded(false) {
00058     try {
00059         myParser = XMLSubSys::getSAXReader(*this);
00060         myParser->parseFirst(getFileName().c_str(), myToken);
00061     } catch (...) {
00062         throw ProcessError();
00063     }
00064 }
00065 
00066 
00067 ROTypedXMLRoutesLoader::~ROTypedXMLRoutesLoader() {
00068     delete myParser;
00069 }
00070 
00071 
00072 bool
00073 ROTypedXMLRoutesLoader::readRoutesAtLeastUntil(SUMOTime time, bool skipping) {
00074     UNUSED_PARAMETER(skipping);
00075     while (getLastReadTimeStep() < time && !ended()) {
00076         beginNextRoute();
00077         while (!nextRouteRead() && !ended()) {
00078             myParser->parseNext(myToken);
00079         }
00080     }
00081     return true;
00082 }
00083 
00084 
00085 void
00086 ROTypedXMLRoutesLoader::endDocument() {
00087     myEnded = true;
00088 }
00089 
00090 
00091 
00092 
00093 /****************************************************************************/
00094 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines