SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ROJTRTurnDefLoader.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Loader for the of turning percentages and source/sink 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 <set>
34 #include <string>
36 #include <utils/xml/XMLSubSys.h>
41 #include <utils/common/ToString.h>
43 #include <router/RONet.h>
44 #include "ROJTREdge.h"
45 #include "ROJTRTurnDefLoader.h"
46 
47 #ifdef CHECK_MEMORY_LEAKS
48 #include <foreign/nvwa/debug_new.h>
49 #endif // CHECK_MEMORY_LEAKS
50 
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
56  : SUMOSAXHandler("turn-ratio-file"), myNet(net),
57  myIntervalBegin(0), myIntervalEnd(SUMOTime_MAX), myEdge(0),
58  myHaveWarnedAboutDeprecatedSources(false),
59  myHaveWarnedAboutDeprecatedSinks(false),
60  myHaveWarnedAboutDeprecatedFromEdge(false),
61  myHaveWarnedAboutDeprecatedToEdge(false) {}
62 
63 
65 
66 
67 void
69  const SUMOSAXAttributes& attrs) {
70  bool ok = true;
71  switch (element) {
72  case SUMO_TAG_INTERVAL:
75  break;
79  WRITE_WARNING("'" + toString(SUMO_TAG_FROMEDGE__DEPRECATED) + "' is deprecated; please use '" + toString(SUMO_TAG_FROMEDGE) + "'.");
80  }
81  case SUMO_TAG_FROMEDGE:
82  beginFromEdge(attrs);
83  break;
87  WRITE_WARNING("'" + toString(SUMO_TAG_TOEDGE__DEPRECATED) + "' is deprecated; please use '" + toString(SUMO_TAG_TOEDGE) + "'.");
88  }
89  case SUMO_TAG_TOEDGE:
90  addToEdge(attrs);
91  break;
92  case SUMO_TAG_SINK:
93  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
94  std::string edges = attrs.getStringReporting(SUMO_ATTR_EDGES, 0, ok);
96  while (st.hasNext()) {
97  std::string id = st.next();
98  ROEdge* edge = myNet.getEdge(id);
99  if (edge == 0) {
100  throw ProcessError("The edge '" + id + "' declared as a sink is not known.");
101  }
102  edge->setType(ROEdge::ET_SINK);
103  }
104  }
105  break;
106  case SUMO_TAG_SOURCE:
107  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
108  std::string edges = attrs.getStringReporting(SUMO_ATTR_EDGES, 0, ok);
110  while (st.hasNext()) {
111  std::string id = st.next();
112  ROEdge* edge = myNet.getEdge(id);
113  if (edge == 0) {
114  throw ProcessError("The edge '" + id + "' declared as a source is not known.");
115  }
116  edge->setType(ROEdge::ET_SOURCE);
117  }
118  }
119  break;
120  default:
121  break;
122  }
123 }
124 
125 
126 void
128  const std::string& chars) {
129  switch (element) {
130  case SUMO_TAG_SINK: {
131  ROEdge* edge = myNet.getEdge(chars);
132  if (edge == 0) {
133  throw ProcessError("The edge '" + chars + "' declared as a sink is not known.");
134  }
137  WRITE_WARNING("Using characters for sinks is deprecated; use attribute 'edges' instead.");
138  }
139  edge->setType(ROEdge::ET_SINK);
140  }
141  break;
142  case SUMO_TAG_SOURCE: {
143  ROEdge* edge = myNet.getEdge(chars);
144  if (edge == 0) {
145  throw ProcessError("The edge '" + chars + "' declared as a source is not known.");
146  }
149  WRITE_WARNING("Using characters for sources is deprecated; use attribute 'edges' instead.");
150  }
151  edge->setType(ROEdge::ET_SOURCE);
152  }
153  break;
154  default:
155  break;
156  }
157 }
158 
159 
160 void
162  myEdge = 0;
163  bool ok = true;
164  // get the id, report an error if not given or empty...
165  std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok);
166  if (!ok) {
167  return;
168  }
169  //
170  myEdge = static_cast<ROJTREdge*>(myNet.getEdge(id));
171  if (myEdge == 0) {
172  WRITE_ERROR("The edge '" + id + "' is not known within the network (within a 'from-edge' tag).");
173  return;
174  }
175 }
176 
177 
178 void
180  if (myEdge == 0) {
181  return;
182  }
183  bool ok = true;
184  // get the id, report an error if not given or empty...
185  std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok);
186  if (!ok) {
187  return;
188  }
189  //
190  ROJTREdge* edge = static_cast<ROJTREdge*>(myNet.getEdge(id));
191  if (edge == 0) {
192  WRITE_ERROR("The edge '" + id + "' is not known within the network (within a 'to-edge' tag).");
193  return;
194  }
195  SUMOReal probability = attrs.getSUMORealReporting(SUMO_ATTR_PROB, id.c_str(), ok);
196  if (ok) {
197  if (probability < 0) {
198  WRITE_ERROR("'probability' must be positive (in definition of to-edge '" + id + "').");
199  } else {
201  }
202  }
203 }
204 
205 
206 
207 /****************************************************************************/
208