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 
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.getStringReporting(SUMO_ATTR_ID, 0, ok);
94  if (!ok) {
95  return;
96  }
97  myCurrentDistrict = new ODDistrict(id);
98 }
99 
100 
101 void
103  std::pair<std::string, SUMOReal> vals = parseConnection(attrs);
104  if (vals.second >= 0) {
105  myCurrentDistrict->addSource(vals.first, vals.second);
106  }
107 }
108 
109 
110 void
112  std::pair<std::string, SUMOReal> vals = parseConnection(attrs);
113  if (vals.second >= 0) {
114  myCurrentDistrict->addSink(vals.first, vals.second);
115  }
116 }
117 
118 
119 
120 std::pair<std::string, SUMOReal>
122  // check the current district first
123  if (myCurrentDistrict == 0) {
124  return std::pair<std::string, SUMOReal>("", -1);
125  }
126  // get the id, report an error if not given or empty...
127  bool ok = true;
128  std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok);
129  if (!ok) {
130  return std::pair<std::string, SUMOReal>("", -1);
131  }
132  // get the weight
133  SUMOReal weight = attrs.getSUMORealReporting(SUMO_ATTR_WEIGHT, id.c_str(), ok);
134  if (ok) {
135  if (weight < 0) {
136  WRITE_ERROR("'probability' must be positive (in definition of " + attrs.getObjectType() + " '" + id + "').");
137  } else {
138  return std::pair<std::string, SUMOReal>(id, weight);
139  }
140  }
141  return std::pair<std::string, SUMOReal>("", -1);
142 }
143 
144 
145 void
147  if (myCurrentDistrict != 0) {
149  }
150 }
151 
152 
153 
154 /****************************************************************************/
155