Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
RODFDetectorHandler.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
21// A handler for loading detector descriptions
22/****************************************************************************/
23#include <config.h>
24
25#include <string>
34#include "RODFDetectorHandler.h"
35#include "RODFNet.h"
36
37
38// ===========================================================================
39// method definitions
40// ===========================================================================
42 const std::string& file)
43 : SUMOSAXHandler(file),
44 myNet(optNet), myIgnoreErrors(ignoreErrors), myContainer(con) {}
45
46
48
49
50void
52 const SUMOSAXAttributes& attrs) {
53 if (element == SUMO_TAG_DETECTOR_DEFINITION || element == SUMO_TAG_E1DETECTOR || element == SUMO_TAG_INDUCTION_LOOP) {
54 try {
55 bool ok = true;
56 // get the id, report an error if not given or empty...
57 std::string id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
58 if (!ok) {
59 throw ProcessError();
60 }
61 std::string lane = attrs.get<std::string>(SUMO_ATTR_LANE, id.c_str(), ok);
62 if (!ok) {
63 throw ProcessError();
64 }
66 int laneIndex = SUMOXMLDefinitions::getIndexFromLane(lane);
67 if (edge == nullptr || laneIndex >= edge->getNumLanes()) {
68 throw ProcessError("Unknown lane '" + lane + "' for detector '" + id + "' in '" + getFileName() + "'.");
69 }
70 double pos = attrs.get<double>(SUMO_ATTR_POSITION, id.c_str(), ok);
71 std::string mml_type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, id.c_str(), ok, "");
72 if (!ok) {
73 throw ProcessError();
74 }
76 if (mml_type == "between") {
77 type = BETWEEN_DETECTOR;
78 } else if (mml_type == "source" || mml_type == "highway_source") { // !!! highway-source is legacy (removed accoring output on 06.08.2007)
79 type = SOURCE_DETECTOR;
80 } else if (mml_type == "sink") {
81 type = SINK_DETECTOR;
82 }
83 RODFDetector* detector = new RODFDetector(id, lane, pos, type);
84 if (!myContainer.addDetector(detector)) {
85 delete detector;
86 throw ProcessError(TLF("Could not add detector '%' (probably the id is already used).", id));
87 }
88 } catch (ProcessError& e) {
89 if (myIgnoreErrors) {
90 WRITE_WARNING(e.what());
91 } else {
92 throw;
93 }
94 }
95 }
96}
97
98
99/****************************************************************************/
#define WRITE_WARNING(msg)
Definition MsgHandler.h:295
#define TLF(string,...)
Definition MsgHandler.h:317
RODFDetectorType
Numerical representation of different detector types.
@ BETWEEN_DETECTOR
An in-between detector.
@ SINK_DETECTOR
@ SOURCE_DETECTOR
A source detector.
@ TYPE_NOT_DEFINED
A not yet defined detector.
@ SUMO_TAG_E1DETECTOR
an e1 detector
@ SUMO_TAG_DETECTOR_DEFINITION
definition of a detector
@ SUMO_TAG_INDUCTION_LOOP
alternative tag for e1 detector
@ SUMO_ATTR_LANE
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
const std::string & getFileName() const
returns the current file name
A container for RODFDetectors.
bool addDetector(RODFDetector *dfd)
RODFDetectorCon & myContainer
the container to put the detectors into
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
RODFDetectorHandler(RODFNet *optNet, bool ignoreErrors, RODFDetectorCon &con, const std::string &file)
Constructor.
virtual ~RODFDetectorHandler()
Destructor.
bool myIgnoreErrors
whether to ignore errors on parsing
Class representing a detector within the DFROUTER.
A DFROUTER-network.
Definition RODFNet.h:42
A basic edge for routing applications.
Definition ROEdge.h:72
int getNumLanes() const
Returns the number of lanes this edge has.
Definition ROEdge.h:265
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition RONet.h:158
Encapsulated SAX-Attributes.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue=T(), bool report=true) const
Tries to read given attribute assuming it is an int.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
SAX-handler base for SUMO-files.
static std::string getEdgeIDFromLane(const std::string laneID)
return edge id when given the lane ID
static int getIndexFromLane(const std::string laneID)
return lane index when given the lane ID