Eclipse SUMO - Simulation of Urban MObility
SUMORouteLoader.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // A class that performs the loading of routes
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
24 #include <utils/xml/XMLSubSys.h>
25 #include "SUMORouteHandler.h"
26 #include "SUMORouteLoader.h"
27 
28 
29 // ===========================================================================
30 // method definitions
31 // ===========================================================================
33  : myParser(nullptr), myMoreAvailable(true), myHandler(handler) {
36  throw ProcessError("Can not read XML-file '" + myHandler->getFileName() + "'.");
37  }
38 }
39 
40 
42  delete myParser;
43  delete myHandler;
44 }
45 
46 
49  // read only when further data is available, no error occurred
50  // and vehicles may be found in the between the departure time of
51  // the last read vehicle and the time to read until
52  if (!myMoreAvailable) {
53  return SUMOTime_MAX;
54  }
55  // read vehicles until specified time or the period to read vehicles
56  // until is reached
57  while (myHandler->getLastDepart() <= time) {
58  if (!myParser->parseNext()) {
59  // no data available anymore
60  myMoreAvailable = false;
61  return SUMOTime_MAX;
62  }
63  }
64  return myHandler->getLastDepart();
65 }
66 
67 
68 bool
70  return myMoreAvailable;
71 }
72 
73 
76  return myHandler->getFirstDepart();
77 }
78 
79 
80 /****************************************************************************/
SUMORouteLoader::getFirstDepart
SUMOTime getFirstDepart() const
returns the first departure time that was ever read
Definition: SUMORouteLoader.cpp:75
SUMORouteLoader::myHandler
SUMORouteHandler * myHandler
the used Handler
Definition: SUMORouteLoader.h:67
SUMORouteLoader::myParser
SUMOSAXReader * myParser
the used SAXReader
Definition: SUMORouteLoader.h:61
SUMOSAXReader::parseNext
bool parseNext()
Definition: SUMOSAXReader.cpp:175
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
SUMORouteLoader::~SUMORouteLoader
~SUMORouteLoader()
destructor
Definition: SUMORouteLoader.cpp:41
SUMORouteLoader::myMoreAvailable
bool myMoreAvailable
flag with information whether more vehicles should be available
Definition: SUMORouteLoader.h:64
SUMORouteLoader::loadUntil
SUMOTime loadUntil(SUMOTime time)
loads vehicles until a vehicle is read that starts after the specified time
Definition: SUMORouteLoader.cpp:48
ProcessError
Definition: UtilExceptions.h:39
SUMOSAXReader::parseFirst
bool parseFirst(std::string systemID)
Definition: SUMOSAXReader.cpp:127
GenericSAXHandler::getFileName
const std::string & getFileName() const
returns the current file name
Definition: GenericSAXHandler.cpp:74
SUMORouteHandler.h
SUMORouteLoader::moreAvailable
bool moreAvailable() const
returns the information whether new data is available
Definition: SUMORouteLoader.cpp:69
SUMORouteHandler
Parser for routes during their loading.
Definition: SUMORouteHandler.h:50
config.h
SUMOSAXReader.h
SUMORouteLoader::SUMORouteLoader
SUMORouteLoader(SUMORouteHandler *handler)
constructor
Definition: SUMORouteLoader.cpp:32
SUMOTime_MAX
#define SUMOTime_MAX
Definition: SUMOTime.h:35
XMLSubSys::getSAXReader
static SUMOSAXReader * getSAXReader(SUMOSAXHandler &handler)
Builds a reader and assigns the handler to it.
Definition: XMLSubSys.cpp:100
SUMORouteHandler::getFirstDepart
SUMOTime getFirstDepart() const
returns the first departure time that was ever read
Definition: SUMORouteHandler.cpp:330
SUMORouteLoader.h
XMLSubSys.h
SUMORouteHandler::getLastDepart
SUMOTime getLastDepart() const
Returns the last loaded depart time.
Definition: SUMORouteHandler.cpp:336