SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RORDLoader_TripDefs.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // The basic class for loading trip definitions
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
37 #include <utils/common/ToString.h>
38 #include "RORouteDef.h"
39 #include "RONet.h"
40 #include "RORouteDef_OrigDest.h"
41 #include "RORDLoader_TripDefs.h"
42 #include "ROVehicle.h"
43 #include "RORouteDef_Complete.h"
45 
46 #ifdef CHECK_MEMORY_LEAKS
47 #include <foreign/nvwa/debug_new.h>
48 #endif // CHECK_MEMORY_LEAKS
49 
50 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
55  SUMOTime begin, SUMOTime end,
56  bool emptyDestinationsAllowed, bool withTaz,
57  const std::string& fileName)
58  : ROTypedXMLRoutesLoader(net, begin, end, fileName),
59  myEmptyDestinationsAllowed(emptyDestinationsAllowed),
60  myWithTaz(withTaz), myCurrentVehicleType(0),
61  myParameter(0), myHaveWarnedAboutDeprecatedTripDef(false) {}
62 
63 
65 
66 
67 void
69  const SUMOSAXAttributes& attrs) {
72  WRITE_WARNING("'" + toString(SUMO_TAG_TRIP__DEPRECATED) + "' is deprecated; please use '" + toString(SUMO_TAG_TRIP) + "'.");
73  }
74  // check whether a trip definition shall be parsed
75  if (element == SUMO_TAG_TRIP || element == SUMO_TAG_TRIP__DEPRECATED) {
76  bool ok = true;
77  // get the vehicle id, the edges, the speed and position and
78  // the departure time and other information
79  std::string id = getVehicleID(attrs);
80  myCurrentDepart = attrs.getSUMOTimeReporting(SUMO_ATTR_DEPART, id.c_str(), ok);
81  if (myWithTaz) {
82  myBeginEdge = getEdge(attrs, "origin", SUMO_ATTR_FROM_TAZ, id, false);
83  myEndEdge = getEdge(attrs, "destination", SUMO_ATTR_TO_TAZ, id, myEmptyDestinationsAllowed);
84  } else {
85  myBeginEdge = getEdge(attrs, "origin", SUMO_ATTR_FROM, id, false);
86  myEndEdge = getEdge(attrs, "destination", SUMO_ATTR_TO, id, myEmptyDestinationsAllowed);
87  }
89  myParameter->id = id;
90  // recheck attributes
91  if (!ok) {
92  return;
93  }
94  if (myCurrentDepart < 0) {
95  WRITE_ERROR("The departure time must be positive.");
96  return;
97  }
98  }
99  // check whether a vehicle type shall be parsed
100  if (element == SUMO_TAG_VTYPE || element == SUMO_TAG_VTYPE__DEPRECATED) {
102  } else if (myCurrentVehicleType != 0) {
104  }
105 }
106 
107 
108 std::string
110  // try to get the id, do not report an error if not given or empty...
111  bool ok = true;
112  std::string id = attrs.getOptStringReporting(SUMO_ATTR_ID, 0, ok, "", false);
113  // get a valid vehicle id
114  if (id == "") {
115  return myIdSupplier.getNext();
116  } else {
117  return id;
118  }
119 }
120 
121 
122 ROEdge*
124  const std::string& purpose,
125  SumoXMLAttr which, const std::string& vid,
126  bool emptyAllowed) {
127  UNUSED_PARAMETER(purpose);
128  bool ok = true;
129  std::string id = attrs.getStringReporting(which, 0, ok, !emptyAllowed);
130  if (which == SUMO_ATTR_FROM_TAZ) {
131  id += "-source";
132  }
133  if (which == SUMO_ATTR_TO_TAZ) {
134  id += "-sink";
135  }
136  ROEdge* e = myNet.getEdge(id);
137  if (e == 0 && !emptyAllowed) {
138  WRITE_ERROR("The edge '" + id + "' is not known.\n Vehicle id='" + vid + "'.");
139  }
140  return e;
141 }
142 
143 
144 void
146  if ((element == SUMO_TAG_TRIP || element == SUMO_TAG_TRIP__DEPRECATED) &&
147  !MsgHandler::getErrorInstance()->wasInformed()) {
148 
149  if (myCurrentDepart < myBegin || myCurrentDepart >= myEnd) {
150  delete myParameter;
151  return;
152  }
156  // check whether any errors occured
157  if (MsgHandler::getErrorInstance()->wasInformed()) {
158  return;
159  }
160  if (myNet.addRouteDef(route)) {
161  myNextRouteRead = true;
162  // build the vehicle
163  ROVehicle* veh = new ROVehicle(*myParameter, route, type);
165  } else {
166  WRITE_ERROR("The vehicle '" + myParameter->id + "' occurs at least twice.");
167  delete route;
168  }
169  delete myParameter;
170  myParameter = 0;
171  }
172  if (element == SUMO_TAG_VTYPE || element == SUMO_TAG_VTYPE__DEPRECATED) {
176  }
177 }
178 
179 
180 /****************************************************************************/
181