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-sim.org/
12 // Copyright (C) 2001-2014 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 
57 
59 
60 
61 void
63  const SUMOSAXAttributes& attrs) {
64  switch (element) {
65  case SUMO_TAG_TAZ:
66  openDistrict(attrs);
67  break;
68  case SUMO_TAG_TAZSOURCE:
69  addSource(attrs);
70  break;
71  case SUMO_TAG_TAZSINK:
72  addSink(attrs);
73  break;
74  default:
75  break;
76  }
77 }
78 
79 
80 void
82  if (element == SUMO_TAG_TAZ) {
83  closeDistrict();
84  }
85 }
86 
87 
88 void
91  // get the id, report an error if not given or empty...
92  bool ok = true;
93  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
94  if (!ok) {
95  return;
96  }
97  myCurrentDistrict = new ODDistrict(id);
98  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
99  std::vector<std::string> desc = attrs.getStringVector(SUMO_ATTR_EDGES);
100  for (std::vector<std::string>::const_iterator i = desc.begin(); i != desc.end(); ++i) {
101  myCurrentDistrict->addSource(*i, 1.);
102  myCurrentDistrict->addSink(*i, 1.);
103  }
104  }
105 }
106 
107 
108 void
110  std::pair<std::string, SUMOReal> vals = parseConnection(attrs);
111  if (vals.second >= 0) {
112  myCurrentDistrict->addSource(vals.first, vals.second);
113  }
114 }
115 
116 
117 void
119  std::pair<std::string, SUMOReal> vals = parseConnection(attrs);
120  if (vals.second >= 0) {
121  myCurrentDistrict->addSink(vals.first, vals.second);
122  }
123 }
124 
125 
126 
127 std::pair<std::string, SUMOReal>
129  // check the current district first
130  if (myCurrentDistrict == 0) {
131  return std::pair<std::string, SUMOReal>("", -1);
132  }
133  // get the id, report an error if not given or empty...
134  bool ok = true;
135  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
136  if (!ok) {
137  return std::pair<std::string, SUMOReal>("", -1);
138  }
139  // get the weight
140  SUMOReal weight = attrs.get<SUMOReal>(SUMO_ATTR_WEIGHT, id.c_str(), ok);
141  if (ok) {
142  if (weight < 0) {
143  WRITE_ERROR("'probability' must be positive (in definition of " + attrs.getObjectType() + " '" + id + "').");
144  } else {
145  return std::pair<std::string, SUMOReal>(id, weight);
146  }
147  }
148  return std::pair<std::string, SUMOReal>("", -1);
149 }
150 
151 
152 void
154  if (myCurrentDistrict != 0) {
156  }
157 }
158 
159 
160 
161 /****************************************************************************/
162