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 /****************************************************************************/
16 // A class that performs the loading of routes
17 /****************************************************************************/
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
25 #include <utils/xml/XMLSubSys.h>
26 #include "SUMORouteHandler.h"
27 #include "SUMORouteLoader.h"
28 
29 
30 // ===========================================================================
31 // method definitions
32 // ===========================================================================
34  : myParser(nullptr), myMoreAvailable(true), myHandler(handler) {
37  throw ProcessError("Can not read XML-file '" + myHandler->getFileName() + "'.");
38  }
39 }
40 
41 
43  delete myParser;
44  delete myHandler;
45 }
46 
47 
50  // read only when further data is available, no error occurred
51  // and vehicles may be found in the between the departure time of
52  // the last read vehicle and the time to read until
53  if (!myMoreAvailable) {
54  return SUMOTime_MAX;
55  }
56  // read vehicles until specified time or the period to read vehicles
57  // until is reached
58  while (myHandler->getLastDepart() <= time) {
59  if (!myParser->parseNext()) {
60  // no data available anymore
61  myMoreAvailable = false;
62  return SUMOTime_MAX;
63  }
64  }
65  return myHandler->getLastDepart();
66 }
67 
68 
69 bool
71  return myMoreAvailable;
72 }
73 
74 
77  return myHandler->getFirstDepart();
78 }
79 
80 
81 /****************************************************************************/
SUMORouteLoader::getFirstDepart
SUMOTime getFirstDepart() const
returns the first departure time that was ever read
Definition: SUMORouteLoader.cpp:76
SUMORouteLoader::myHandler
SUMORouteHandler * myHandler
the used Handler
Definition: SUMORouteLoader.h:68
SUMORouteLoader::myParser
SUMOSAXReader * myParser
the used SAXReader
Definition: SUMORouteLoader.h:62
SUMOSAXReader::parseNext
bool parseNext()
Definition: SUMOSAXReader.cpp:173
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
SUMORouteLoader::~SUMORouteLoader
~SUMORouteLoader()
destructor
Definition: SUMORouteLoader.cpp:42
SUMORouteLoader::myMoreAvailable
bool myMoreAvailable
flag with information whether more vehicles should be available
Definition: SUMORouteLoader.h:65
SUMORouteLoader::loadUntil
SUMOTime loadUntil(SUMOTime time)
loads vehicles until a vehicle is read that starts after the specified time
Definition: SUMORouteLoader.cpp:49
ProcessError
Definition: UtilExceptions.h:40
SUMOSAXReader::parseFirst
bool parseFirst(std::string systemID)
Definition: SUMOSAXReader.cpp:125
GenericSAXHandler::getFileName
const std::string & getFileName() const
returns the current file name
Definition: GenericSAXHandler.cpp:75
SUMORouteHandler.h
SUMORouteLoader::moreAvailable
bool moreAvailable() const
returns the information whether new data is available
Definition: SUMORouteLoader.cpp:70
SUMORouteHandler
Parser for routes during their loading.
Definition: SUMORouteHandler.h:51
config.h
SUMOSAXReader.h
SUMORouteLoader::SUMORouteLoader
SUMORouteLoader(SUMORouteHandler *handler)
constructor
Definition: SUMORouteLoader.cpp:33
SUMOTime_MAX
#define SUMOTime_MAX
Definition: SUMOTime.h:36
XMLSubSys::getSAXReader
static SUMOSAXReader * getSAXReader(SUMOSAXHandler &handler)
Builds a reader and assigns the handler to it.
Definition: XMLSubSys.cpp:101
SUMORouteHandler::getFirstDepart
SUMOTime getFirstDepart() const
returns the first departure time that was ever read
Definition: SUMORouteHandler.cpp:328
SUMORouteLoader.h
XMLSubSys.h
SUMORouteHandler::getLastDepart
SUMOTime getLastDepart() const
Returns the last loaded depart time.
Definition: SUMORouteHandler.cpp:334