Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
METypeHandler.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-2026 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/****************************************************************************/
18// The XML-Handler for loading meso edge types
19// This is a dedicated handler because meso types must be loaded from additional
20// files before any other objects are loaded from them
21/****************************************************************************/
22#include <config.h>
23
24#include <string>
25#include "METypeHandler.h"
28#include <microsim/MSNet.h>
29#include <mesosim/MESegment.h>
30
31
32// ===========================================================================
33// method definitions
34// ===========================================================================
35METypeHandler::METypeHandler(const std::string& file, MSNet& net) :
36 SUMOSAXHandler(file),
37 myNet(net),
39{
40}
41
42
44
45
46void
48 const SUMOSAXAttributes& attrs) {
49 try {
50 switch (element) {
51 case SUMO_TAG_TYPE: {
52 bool ok = true;
53 myCurrentTypeID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
54 break;
55 }
56 case SUMO_TAG_MESO: {
57 addMesoEdgeType(attrs);
58 break;
59 }
60 default:
61 break;
62 }
63 } catch (InvalidArgument& e) {
64 WRITE_ERROR(e.what());
65 }
66}
67
68
69void
71 switch (element) {
72 case SUMO_TAG_TYPE:
73 myCurrentTypeID = "";
74 break;
75 default:
76 break;
77 }
78}
79
80
81
82void
84 bool ok = true;
85 MESegment::MesoEdgeType edgeType = myNet.getMesoType(""); // init defaults
86 edgeType.tauff = attrs.getOptSUMOTimeReporting(SUMO_ATTR_MESO_TAUFF, myCurrentTypeID.c_str(), ok, edgeType.tauff);
87 edgeType.taufj = attrs.getOptSUMOTimeReporting(SUMO_ATTR_MESO_TAUFJ, myCurrentTypeID.c_str(), ok, edgeType.taufj);
88 edgeType.taujf = attrs.getOptSUMOTimeReporting(SUMO_ATTR_MESO_TAUJF, myCurrentTypeID.c_str(), ok, edgeType.taujf);
89 edgeType.taujj = attrs.getOptSUMOTimeReporting(SUMO_ATTR_MESO_TAUJJ, myCurrentTypeID.c_str(), ok, edgeType.taujj);
90 edgeType.jamThreshold = attrs.getOpt<double>(SUMO_ATTR_JAM_DIST_THRESHOLD, myCurrentTypeID.c_str(), ok, edgeType.jamThreshold);
91 edgeType.junctionControl = attrs.getOpt<bool>(SUMO_ATTR_MESO_JUNCTION_CONTROL, myCurrentTypeID.c_str(), ok, edgeType.junctionControl);
92 edgeType.tlsPenalty = attrs.getOpt<double>(SUMO_ATTR_MESO_TLS_PENALTY, myCurrentTypeID.c_str(), ok, edgeType.tlsPenalty);
93 edgeType.tlsFlowPenalty = attrs.getOpt<double>(SUMO_ATTR_MESO_TLS_FLOW_PENALTY, myCurrentTypeID.c_str(), ok, edgeType.tlsFlowPenalty);
95 edgeType.overtaking = attrs.getOpt<bool>(SUMO_ATTR_MESO_OVERTAKING, myCurrentTypeID.c_str(), ok, edgeType.overtaking);
96 edgeType.edgeLength = attrs.getOpt<double>(SUMO_ATTR_MESO_EDGELENGHT, myCurrentTypeID.c_str(), ok, edgeType.edgeLength);
97
98 if (ok) {
99 myNet.addMesoType(myCurrentTypeID, edgeType);
100 }
102}
103
104
105/****************************************************************************/
#define WRITE_ERROR(msg)
Definition MsgHandler.h:295
@ SUMO_TAG_MESO
edge-specific meso settings
@ SUMO_TAG_TYPE
type (edge)
@ SUMO_ATTR_MESO_TLS_FLOW_PENALTY
@ SUMO_ATTR_MESO_JUNCTION_CONTROL
@ SUMO_ATTR_JAM_DIST_THRESHOLD
@ SUMO_ATTR_MESO_OVERTAKING
@ SUMO_ATTR_MESO_EDGELENGHT
@ SUMO_ATTR_MESO_TAUFF
@ SUMO_ATTR_MESO_MINOR_PENALTY
@ SUMO_ATTR_MESO_TAUJF
@ SUMO_ATTR_ID
@ SUMO_ATTR_MESO_TAUFJ
@ SUMO_ATTR_MESO_TAUJJ
@ SUMO_ATTR_MESO_TLS_PENALTY
void myEndElement(int element)
Called when a closing tag occurs.
std::string myCurrentTypeID
The id of the currently processed edge type.
METypeHandler(const std::string &file, MSNet &net)
Constructor.
MSNet & myNet
The net to fill (preinitialised).
virtual ~METypeHandler()
Destructor.
void addMesoEdgeType(const SUMOSAXAttributes &attrs)
Loads edge type specific meso parameters.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
bool myHaveSeenMesoEdgeType
whether edge type specific meso parameters were loaded
The simulated network and simulation perfomer.
Definition MSNet.h:89
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.
SUMOTime getOptSUMOTimeReporting(int attr, const char *objectid, bool &ok, SUMOTime defaultValue, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
SUMOSAXHandler(const std::string &file="", const std::string &expectedRoot="")
Constructor.
edge type specific meso parameters
Definition MESegment.h:58