/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2007-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file SAXWeightsHandler.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @date Fri, 30 Mar 200718///19// An XML-handler for network weights20/****************************************************************************/21#pragma once22#include <config.h>2324#include <string>25#include <utils/xml/SUMOSAXHandler.h>26#include <utils/common/SUMOTime.h>272829// ===========================================================================30// class definitions31// ===========================================================================32/**33* @class SAXWeightsHandler34* @brief An XML-handler for network weights35*36* As network weights are used both in the simulation and the routers, a base37* class for loading them was built. Instances of this class should be supplied38* with at least one definition about what shall be retrieved39* (ToRetrieveDefinition, defined as inner class) which also contains the information40* about the retriever (EdgeFloatTimeLineRetriever, defined as inner class).41*42* The ToRetrieveDefinition names the attribute which the SAXWeightsHandler shall43* parse and reporte. Within the parsed xml-file these attributes may be embedded44* in "lane" or "edge" elements, one for each edge or for each lane (see below).45* These elements should be embedded in interval-tags which specify the time the46* weight is valid at.47* The boolean "edgeBased" tells SAXWeightsHandler whether the weights are supplied48* on edge- or on lane-basis (whether it shall parse the "edge" or the "lane" elements).49*50* Examples for files the SAXWeightsHandler can handle are the edgedump and the lanedump51* generated by the simulation.52*53* The EdgeFloatTimeLineRetriever to which read values will be reported should have the54* method "addEdgeWeight" implemented. It wil be supplied with the current edge name,55* the interval the weight is valid for and the value.56*/57class SAXWeightsHandler : public SUMOSAXHandler {58public:59/**60* @class EdgeFloatTimeLineRetriever61* @brief Interface for a class which obtains read weights for named edges62*/63class EdgeFloatTimeLineRetriever {6465public:66/// @brief Constructor67EdgeFloatTimeLineRetriever() { }6869/// @brief Destructor70virtual ~EdgeFloatTimeLineRetriever() { }7172/** @brief Adds a weight for a given edge and time period73*74* @param[in] id The id of the object to add a weight for75* @param[in] val The weight76* @param[in] beg The begin of the interval the weight is valid for77* @param[in] end The end of the interval the weight is valid for78*/79virtual void addEdgeWeight(const std::string& id, double val, double beg, double end) const {80UNUSED_PARAMETER(id);81UNUSED_PARAMETER(val);82UNUSED_PARAMETER(beg);83UNUSED_PARAMETER(end);84}8586virtual void addEdgeRelWeight(const std::string& from, const std::string& to,87double val, double beg, double end) const {88UNUSED_PARAMETER(from);89UNUSED_PARAMETER(to);90UNUSED_PARAMETER(val);91UNUSED_PARAMETER(beg);92UNUSED_PARAMETER(end);93}9495/// @note: note sure why the other functions are const96virtual void addTazRelWeight(const std::string intervalID, const std::string& from, const std::string& to,97double val, double beg, double end) {98UNUSED_PARAMETER(intervalID);99UNUSED_PARAMETER(from);100UNUSED_PARAMETER(to);101UNUSED_PARAMETER(val);102UNUSED_PARAMETER(beg);103UNUSED_PARAMETER(end);104}105106private:107/// @brief we made the assignment operator invalid108EdgeFloatTimeLineRetriever& operator=(const EdgeFloatTimeLineRetriever&) = delete;109};110111/**112* @class ToRetrieveDefinition113* @brief Complete definition about what shall be retrieved and where to store it114*/115class ToRetrieveDefinition {116public:117/// @brief Constructor118ToRetrieveDefinition(const std::string& attributeName, bool edgeBased,119EdgeFloatTimeLineRetriever& destination);120121/// Destructor122~ToRetrieveDefinition();123124public:125/// @brief The attribute name that shall be parsed126std::string myAttributeName;127128/// @brief Information whether edge values shall be used (lane value if false)129bool myAmEdgeBased;130131/// @brief The class that shall be called when new data is avaiable132EdgeFloatTimeLineRetriever& myDestination;133134/// @brief Aggregated value over the lanes read within the current edge135double myAggValue;136137/// @brief The number of lanes read for the current edge138int myNoLanes;139140/// @brief Information whether the attribute has been found for the current edge141bool myHadAttribute;142143/// @brief Information whether the attribute was found to contain non-numerical data (for any edge)144bool myHadNonNumeric;145146private:147/// @brief Invalidated copy constructor.148ToRetrieveDefinition(const ToRetrieveDefinition&) = delete;149150/// @brief Invalidated assignment operator.151ToRetrieveDefinition& operator=(const ToRetrieveDefinition&) = delete;152};153154/**155* @brief Constructor156*157* Gets a list of retriever definitions. Please note that the retrievers are158* not deleted!159*/160SAXWeightsHandler(const std::vector<ToRetrieveDefinition*>& defs, const std::string& file);161162/**163* @brief Constructor164*165* Gets a single definition. Please note that the retrievers are not deleted!166*/167SAXWeightsHandler(ToRetrieveDefinition* def, const std::string& file);168169/// @brief Destructor170~SAXWeightsHandler();171172protected:173/// @name inherited from GenericSAXHandler174//@{175176/** @brief Called on the opening of a tag;177*178* @param[in] element ID of the currently opened element179* @param[in] attrs Attributes within the currently opened element180* @exception ProcessError If something fails181* @see GenericSAXHandler::myStartElement182*/183void myStartElement(int element, const SUMOSAXAttributes& attrs);184185/** @brief Called when a closing tag occurs186*187* @param[in] element ID of the currently opened element188* @exception ProcessError If something fails189* @see GenericSAXHandler::myEndElement190*/191void myEndElement(int elemente);192193//@}194195private:196/// @brief Parses the data of an edge or lane for the previously read times197void tryParse(const SUMOSAXAttributes& attrs, bool isEdge);198199/// @brief Parses the data of an edgeRelation for the previously read times200void tryParseEdgeRel(const SUMOSAXAttributes& attrs);201202/// @brief Parses the data of an tazRelation for the previously read times203void tryParseTazRel(const SUMOSAXAttributes& attrs);204205/// @brief List of definitions what shall be read and whereto stored while parsing the file206std::vector<ToRetrieveDefinition*> myDefinitions;207208/// @brief the id of the interval being parsed209std::string myCurrentID;210211/// @brief the begin of the time period that is currently processed212double myCurrentTimeBeg;213214/// @brief the end of the time period that is currently processed215double myCurrentTimeEnd;216217/// @brief the edge which is currently being processed218std::string myCurrentEdgeID;219220/// @brief we made the copy constructor invalid221SAXWeightsHandler(const SAXWeightsHandler& src) = delete;222223/// @brief we made the assignment operator invalid224SAXWeightsHandler& operator=(const SAXWeightsHandler& src) = delete;225};226227228