SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ODDistrictHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // An XML-Handler for districts
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>
34 #include <utility>
35 #include <iostream>
38 #include <utils/common/ToString.h>
41 #include "ODDistrict.h"
42 #include "ODDistrictCont.h"
43 #include "ODDistrictHandler.h"
44 
45 #ifdef CHECK_MEMORY_LEAKS
46 #include <foreign/nvwa/debug_new.h>
47 #endif // CHECK_MEMORY_LEAKS
48 
49 
50 // ===========================================================================
51 // method definitions
52 // ===========================================================================
54  const std::string& file)
55  : SUMOSAXHandler(file), myContainer(cont), myCurrentDistrict(0),
56  myHaveWarnedAboutDeprecatedDistrict(false), myHaveWarnedAboutDeprecatedDSource(false), myHaveWarnedAboutDeprecatedDSink(false) {}
57 
58 
60 
61 
62 void
64  const SUMOSAXAttributes& attrs) {
65  switch (element) {
69  WRITE_WARNING("'" + toString(SUMO_TAG_DISTRICT__DEPRECATED) + "' is deprecated, please use '" + toString(SUMO_TAG_TAZ) + "'.");
70  }
71  case SUMO_TAG_TAZ:
72  openDistrict(attrs);
73  break;
77  WRITE_WARNING("'" + toString(SUMO_TAG_DSOURCE__DEPRECATED) + "' is deprecated, please use '" + toString(SUMO_TAG_TAZSOURCE) + "'.");
78  }
79  case SUMO_TAG_TAZSOURCE:
80  addSource(attrs);
81  break;
85  WRITE_WARNING("'" + toString(SUMO_TAG_DSINK__DEPRECATED) + "' is deprecated, please use '" + toString(SUMO_TAG_TAZSINK) + "'.");
86  }
87  case SUMO_TAG_TAZSINK:
88  addSink(attrs);
89  break;
90  default:
91  break;
92  }
93 }
94 
95 
96 void
98  if (element == SUMO_TAG_DISTRICT__DEPRECATED || element == SUMO_TAG_TAZ) {
99  closeDistrict();
100  }
101 }
102 
103 
104 void
106  myCurrentDistrict = 0;
107  // get the id, report an error if not given or empty...
108  bool ok = true;
109  std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok);
110  if (!ok) {
111  return;
112  }
113  myCurrentDistrict = new ODDistrict(id);
114 }
115 
116 
117 void
119  std::pair<std::string, SUMOReal> vals = parseConnection(attrs);
120  if (vals.second >= 0) {
121  myCurrentDistrict->addSource(vals.first, vals.second);
122  }
123 }
124 
125 
126 void
128  std::pair<std::string, SUMOReal> vals = parseConnection(attrs);
129  if (vals.second >= 0) {
130  myCurrentDistrict->addSink(vals.first, vals.second);
131  }
132 }
133 
134 
135 
136 std::pair<std::string, SUMOReal>
138  // check the current district first
139  if (myCurrentDistrict == 0) {
140  return std::pair<std::string, SUMOReal>("", -1);
141  }
142  // get the id, report an error if not given or empty...
143  bool ok = true;
144  std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok);
145  if (!ok) {
146  return std::pair<std::string, SUMOReal>("", -1);
147  }
148  // get the weight
149  SUMOReal weight = attrs.getSUMORealReporting(SUMO_ATTR_WEIGHT, id.c_str(), ok);
150  if (ok) {
151  if (weight < 0) {
152  WRITE_ERROR("'probability' must be positive (in definition of " +
153  attrs.getObjectType() + " '" + id + "').");
154  } else {
155  return std::pair<std::string, SUMOReal>(id, weight);
156  }
157  }
158  return std::pair<std::string, SUMOReal>("", -1);
159 }
160 
161 
162 void
164  if (myCurrentDistrict != 0) {
166  }
167 }
168 
169 
170 
171 /****************************************************************************/
172