Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
XMLHelpers.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// Helpers for writing commonly used XML attributes and elements
19/****************************************************************************/
20#include <config.h>
21
24#include "XMLHelpers.h"
25
26
29 for (const auto& keyValue : params.getParametersMap()) {
30 device.openTag(SUMO_TAG_PARAM);
31 device.writeAttr(SUMO_ATTR_KEY, keyValue.first, false, true);
32 device.writeAttr(SUMO_ATTR_VALUE, keyValue.second, false, true);
33 device.closeTag();
34 }
35 return device;
36}
37
38
41 if (permissions == SVCAll || permissions == SVC_UNSPECIFIED) {
42 device.writeOptionalAttr(SUMO_ATTR_ALLOW, "", true);
43 device.writeOptionalAttr(SUMO_ATTR_DISALLOW, "", true);
44 return device;
45 }
46 if (permissions == 0) {
47 device.writeOptionalAttr(SUMO_ATTR_ALLOW, "", true);
48 device.writeAttr(SUMO_ATTR_DISALLOW, "all");
49 return device;
50 }
51 int num_allowed = 0;
52 for (SVCPermissions mask = 1; mask <= SUMOVehicleClass_MAX; mask = mask << 1) {
53 if ((mask & permissions) == mask) {
54 ++num_allowed;
55 }
56 }
57 const int numVClasses = getNumVehicleClasses();
58 if (num_allowed <= (numVClasses - num_allowed) && num_allowed > 0) {
60 device.writeOptionalAttr(SUMO_ATTR_DISALLOW, "", true);
61 } else {
62 device.writeOptionalAttr(SUMO_ATTR_ALLOW, "", true);
64 }
65 return device;
66}
67
68
71 return device.writeOptionalAttr(SUMO_ATTR_PREFER, getVehicleClassNames(preferred), preferred == SVCAll || preferred == 0);
72}
const SVCPermissions SVCAll
all VClasses are allowed
const SVCPermissions SVC_UNSPECIFIED
permissions not specified
const std::string & getVehicleClassNames(SVCPermissions permissions, bool expand)
Returns the ids of the given classes, divided using a ' '.
int getNumVehicleClasses()
returns the number of (non-grouping) vehicle classes
const SUMOVehicleClass SUMOVehicleClass_MAX
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ SUMO_TAG_PARAM
parameter associated to a certain key
@ SUMO_ATTR_PREFER
@ SUMO_ATTR_DISALLOW
@ SUMO_ATTR_ALLOW
@ SUMO_ATTR_VALUE
@ SUMO_ATTR_KEY
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
OutputDevice & writeOptionalAttr(const SumoXMLAttr attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute unless null
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
An upper class for objects with additional parameters.
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
static OutputDevice & writeParams(OutputDevice &device, const Parameterised &params)
write the parameters of the given object as param tags
static OutputDevice & writePreferences(OutputDevice &device, SVCPermissions preferred)
writes the prefer attribute if needed
static OutputDevice & writePermissions(OutputDevice &device, SVCPermissions permissions)
writes allowed disallowed attributes if needed