SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RODFDetectorHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // A handler for loading detector descriptions
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
13 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
40 #include <utils/common/ToString.h>
43 #include "RODFDetectorHandler.h"
44 #include "RODFNet.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  const std::string& file)
56  : SUMOSAXHandler(file),
57  myNet(optNet), myIgnoreErrors(ignoreErrors), myContainer(con),
58  myHaveWarnedAboutDeprecatedDetectorDefinition(false) {}
59 
60 
62 
63 
64 void
66  const SUMOSAXAttributes& attrs) {
69  WRITE_WARNING("Using '" + toString(SUMO_TAG_DETECTOR_DEFINITION__DEPRECATED) + "' is deprecated. Please use '" + toString(SUMO_TAG_DETECTOR_DEFINITION) + "' instead.");
70  }
72  try {
73  bool ok = true;
74  // get the id, report an error if not given or empty...
75  std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok);
76  if (!ok) {
77  throw ProcessError();
78  }
79  std::string lane = attrs.getStringReporting(SUMO_ATTR_LANE, id.c_str(), ok);
80  if (!ok) {
81  throw ProcessError();
82  }
83  ROEdge* edge = myNet->getEdge(lane.substr(0, lane.rfind('_')));
84  unsigned int laneIndex = TplConvertSec<char>::_2intSec(lane.substr(lane.rfind('_') + 1).c_str(), INT_MAX);
85  if (edge == 0 || laneIndex >= edge->getLaneNo()) {
86  throw ProcessError("Unknown lane '" + lane + "' for detector '" + id + "' in '" + getFileName() + "'.");
87  }
88  SUMOReal pos = attrs.getSUMORealReporting(SUMO_ATTR_POSITION, id.c_str(), ok);
89  std::string mml_type = attrs.getOptStringReporting(SUMO_ATTR_TYPE, id.c_str(), ok, "");
90  if (!ok) {
91  throw ProcessError();
92  }
94  if (mml_type == "between") {
95  type = BETWEEN_DETECTOR;
96  } else if (mml_type == "source" || mml_type == "highway_source") { // !!! highway-source is legacy (removed accoring output on 06.08.2007)
97  type = SOURCE_DETECTOR;
98  } else if (mml_type == "sink") {
99  type = SINK_DETECTOR;
100  }
101  RODFDetector* detector = new RODFDetector(id, lane, pos, type);
102  if (!myContainer.addDetector(detector)) {
103  delete detector;
104  throw ProcessError("Could not add detector '" + id + "' (probably the id is already used).");
105  }
106  } catch (ProcessError& e) {
107  if (myIgnoreErrors) {
108  WRITE_WARNING(e.what());
109  } else {
110  throw e;
111  }
112  }
113  }
114 }
115 
116 
117 
118 /****************************************************************************/
119