Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2007-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 : /****************************************************************************/ 14 : /// @file SAXWeightsHandler.h 15 : /// @author Daniel Krajzewicz 16 : /// @author Jakob Erdmann 17 : /// @author Michael Behrisch 18 : /// @date Fri, 30 Mar 2007 19 : /// 20 : // An XML-handler for network weights 21 : /****************************************************************************/ 22 : #pragma once 23 : #include <config.h> 24 : 25 : #include <string> 26 : #include <utils/xml/SUMOSAXHandler.h> 27 : #include <utils/common/SUMOTime.h> 28 : 29 : 30 : // =========================================================================== 31 : // class definitions 32 : // =========================================================================== 33 : /** 34 : * @class SAXWeightsHandler 35 : * @brief An XML-handler for network weights 36 : * 37 : * As network weights are used both in the simulation and the routers, a base 38 : * class for loading them was built. Instances of this class should be supplied 39 : * with at least one definition about what shall be retrieved 40 : * (ToRetrieveDefinition, defined as inner class) which also contains the information 41 : * about the retriever (EdgeFloatTimeLineRetriever, defined as inner class). 42 : * 43 : * The ToRetrieveDefinition names the attribute which the SAXWeightsHandler shall 44 : * parse and reporte. Within the parsed xml-file these attributes may be embedded 45 : * in "lane" or "edge" elements, one for each edge or for each lane (see below). 46 : * These elements should be embedded in interval-tags which specify the time the 47 : * weight is valid at. 48 : * The boolean "edgeBased" tells SAXWeightsHandler whether the weights are supplied 49 : * on edge- or on lane-basis (whether it shall parse the "edge" or the "lane" elements). 50 : * 51 : * Examples for files the SAXWeightsHandler can handle are the edgedump and the lanedump 52 : * generated by the simulation. 53 : * 54 : * The EdgeFloatTimeLineRetriever to which read values will be reported should have the 55 : * method "addEdgeWeight" implemented. It wil be supplied with the current edge name, 56 : * the interval the weight is valid for and the value. 57 : */ 58 : class SAXWeightsHandler : public SUMOSAXHandler { 59 : public: 60 : /** 61 : * @class EdgeFloatTimeLineRetriever 62 : * @brief Interface for a class which obtains read weights for named edges 63 : */ 64 0 : class EdgeFloatTimeLineRetriever { 65 : 66 : public: 67 : /// @brief Constructor 68 1759 : EdgeFloatTimeLineRetriever() { } 69 : 70 : /// @brief Destructor 71 : virtual ~EdgeFloatTimeLineRetriever() { } 72 : 73 : /** @brief Adds a weight for a given edge and time period 74 : * 75 : * @param[in] id The id of the object to add a weight for 76 : * @param[in] val The weight 77 : * @param[in] beg The begin of the interval the weight is valid for 78 : * @param[in] end The end of the interval the weight is valid for 79 : */ 80 0 : virtual void addEdgeWeight(const std::string& id, double val, double beg, double end) const { 81 : UNUSED_PARAMETER(id); 82 : UNUSED_PARAMETER(val); 83 : UNUSED_PARAMETER(beg); 84 : UNUSED_PARAMETER(end); 85 0 : } 86 : 87 0 : virtual void addEdgeRelWeight(const std::string& from, const std::string& to, 88 : double val, double beg, double end) const { 89 : UNUSED_PARAMETER(from); 90 : UNUSED_PARAMETER(to); 91 : UNUSED_PARAMETER(val); 92 : UNUSED_PARAMETER(beg); 93 : UNUSED_PARAMETER(end); 94 0 : } 95 : 96 : /// @note: note sure why the other functions are const 97 0 : virtual void addTazRelWeight(const std::string intervalID, const std::string& from, const std::string& to, 98 : double val, double beg, double end) { 99 : UNUSED_PARAMETER(intervalID); 100 : UNUSED_PARAMETER(from); 101 : UNUSED_PARAMETER(to); 102 : UNUSED_PARAMETER(val); 103 : UNUSED_PARAMETER(beg); 104 : UNUSED_PARAMETER(end); 105 0 : } 106 : 107 : private: 108 : /// @brief we made the assignment operator invalid 109 : EdgeFloatTimeLineRetriever& operator=(const EdgeFloatTimeLineRetriever&) = delete; 110 : }; 111 : 112 : /** 113 : * @class ToRetrieveDefinition 114 : * @brief Complete definition about what shall be retrieved and where to store it 115 : */ 116 : class ToRetrieveDefinition { 117 : public: 118 : /// @brief Constructor 119 : ToRetrieveDefinition(const std::string& attributeName, bool edgeBased, 120 : EdgeFloatTimeLineRetriever& destination); 121 : 122 : /// Destructor 123 : ~ToRetrieveDefinition(); 124 : 125 : public: 126 : /// @brief The attribute name that shall be parsed 127 : std::string myAttributeName; 128 : 129 : /// @brief Information whether edge values shall be used (lane value if false) 130 : bool myAmEdgeBased; 131 : 132 : /// @brief The class that shall be called when new data is avaiable 133 : EdgeFloatTimeLineRetriever& myDestination; 134 : 135 : /// @brief Aggregated value over the lanes read within the current edge 136 : double myAggValue; 137 : 138 : /// @brief The number of lanes read for the current edge 139 : int myNoLanes; 140 : 141 : /// @brief Information whether the attribute has been found for the current edge 142 : bool myHadAttribute; 143 : 144 : private: 145 : /// @brief Invalidated copy constructor. 146 : ToRetrieveDefinition(const ToRetrieveDefinition&) = delete; 147 : 148 : /// @brief Invalidated assignment operator. 149 : ToRetrieveDefinition& operator=(const ToRetrieveDefinition&) = delete; 150 : }; 151 : 152 : /** 153 : * @brief Constructor 154 : * 155 : * Gets a list of retriever definitions. Please note that the retrievers are 156 : * not deleted! 157 : */ 158 : SAXWeightsHandler(const std::vector<ToRetrieveDefinition*>& defs, const std::string& file); 159 : 160 : /** 161 : * @brief Constructor 162 : * 163 : * Gets a single definition. Please note that the retrievers are not deleted! 164 : */ 165 : SAXWeightsHandler(ToRetrieveDefinition* def, const std::string& file); 166 : 167 : /// @brief Destructor 168 : ~SAXWeightsHandler(); 169 : 170 : protected: 171 : /// @name inherited from GenericSAXHandler 172 : //@{ 173 : 174 : /** @brief Called on the opening of a tag; 175 : * 176 : * @param[in] element ID of the currently opened element 177 : * @param[in] attrs Attributes within the currently opened element 178 : * @exception ProcessError If something fails 179 : * @see GenericSAXHandler::myStartElement 180 : */ 181 : void myStartElement(int element, const SUMOSAXAttributes& attrs); 182 : 183 : /** @brief Called when a closing tag occurs 184 : * 185 : * @param[in] element ID of the currently opened element 186 : * @exception ProcessError If something fails 187 : * @see GenericSAXHandler::myEndElement 188 : */ 189 : void myEndElement(int elemente); 190 : 191 : //@} 192 : 193 : private: 194 : /// @brief Parses the data of an edge or lane for the previously read times 195 : void tryParse(const SUMOSAXAttributes& attrs, bool isEdge); 196 : 197 : /// @brief Parses the data of an edgeRelation for the previously read times 198 : void tryParseEdgeRel(const SUMOSAXAttributes& attrs); 199 : 200 : /// @brief Parses the data of an tazRelation for the previously read times 201 : void tryParseTazRel(const SUMOSAXAttributes& attrs); 202 : 203 : /// @brief List of definitions what shall be read and whereto stored while parsing the file 204 : std::vector<ToRetrieveDefinition*> myDefinitions; 205 : 206 : /// @brief the id of the interval being parsed 207 : std::string myCurrentID; 208 : 209 : /// @brief the begin of the time period that is currently processed 210 : double myCurrentTimeBeg; 211 : 212 : /// @brief the end of the time period that is currently processed 213 : double myCurrentTimeEnd; 214 : 215 : /// @brief the edge which is currently being processed 216 : std::string myCurrentEdgeID; 217 : 218 : /// @brief we made the copy constructor invalid 219 : SAXWeightsHandler(const SAXWeightsHandler& src) = delete; 220 : 221 : /// @brief we made the assignment operator invalid 222 : SAXWeightsHandler& operator=(const SAXWeightsHandler& src) = delete; 223 : };