SUMO - Simulation of Urban MObility

ROTypedXMLRoutesLoader.cpp

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