SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SUMORouteLoader.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // A class that performs the loading of routes
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
33 #include <utils/xml/XMLSubSys.h>
34 #include "SUMORouteLoader.h"
35 
36 #ifdef CHECK_MEMORY_LEAKS
37 #include <foreign/nvwa/debug_new.h>
38 #endif // CHECK_MEMORY_LEAKS
39 
40 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
45  : myParser(0), myMoreAvailable(true), myHandler(handler) {
48  throw ProcessError("Can not read XML-file '" + myHandler->getFileName() + "'.");
49  }
50 }
51 
52 
54  delete myParser;
55  delete myHandler;
56 }
57 
58 
61  SUMOTime firstDepart = SUMOTime_MAX;
62  // read only when further data is available, no error occured
63  // and vehicles may be found in the between the departure time of
64  // the last read vehicle and the time to read until
65  if (!myMoreAvailable || time <= myHandler->getLastDepart()) {
66  return firstDepart;
67  }
68 
69  // read vehicles until specified time or the period to read vehicles
70  // until is reached
71  while (myParser->parseNext()) {
72  if (firstDepart == SUMOTime_MAX && myHandler->getLastDepart() >= 0) {
73  firstDepart = myHandler->getLastDepart();
74  }
75  // return when the last read vehicle is beyond the period
76  if (time <= myHandler->getLastDepart()) {
77  return firstDepart;
78  }
79  }
80 
81  // no data available anymore
82  myMoreAvailable = false;
83  return firstDepart;
84 }
85 
86 
87 bool
89  return myMoreAvailable;
90 }
91 
92 
93 /****************************************************************************/
bool myMoreAvailable
information whether more vehicles should be available
~SUMORouteLoader()
destructor
const std::string & getFileName() const
returns the current file name
SUMOTime loadUntil(SUMOTime time)
bool moreAvailable() const
returns the information whether new data is available
static SUMOSAXReader * getSAXReader(SUMOSAXHandler &handler)
Builds a reader and assigns the handler to it.
Definition: XMLSubSys.cpp:84
SUMORouteHandler * myHandler
the used Handler
Parser for routes during their loading.
bool parseFirst(std::string systemID)
#define SUMOTime_MAX
Definition: SUMOTime.h:44
int SUMOTime
Definition: SUMOTime.h:43
SUMOSAXReader * myParser
the used SAXReader
SUMOTime getLastDepart() const
Returns the last loaded depart time.
SUMORouteLoader(SUMORouteHandler *handler)
constructor