/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-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 ODDistrictHandler.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @date Sept 200218///19// An XML-Handler for districts20/****************************************************************************/21#pragma once22#include <config.h>2324#include <string>25#include <utility>26#include <utils/xml/SUMOSAXHandler.h>272829// ===========================================================================30// class declarations31// ===========================================================================32class ODDistrict;33class ODDistrictCont;343536// ===========================================================================37// class definitions38// ===========================================================================39/**40* @class ODDistrictHandler41* @brief An XML-Handler for districts42*43* This SUMOSAXHandler parses districts and their sinks and sources from44* and stores them into a the district container given at initialisation.45*/46class ODDistrictHandler : public SUMOSAXHandler {47public:48/** @brief Constructor49*50* Saves the given district containe in order to fill it.51* @param[in] cont The container of districts to fill52* @param[in] file The file that will be processed53*/54ODDistrictHandler(ODDistrictCont& cont, const std::string& file);555657/// @brief Destructor58~ODDistrictHandler();596061protected:62/// @name inherited from GenericSAXHandler63//@{6465/** @brief Called when an opening-tag occurs66*67* Processes district elements via openDistrict, their sinks (via68* addSink) and sources (via addSource).69*70* @param[in] element The enum of the currently opened element71* @param[in] attrs Attributes of the currently opened element72* @exception ProcessError If an error within the parsed file occurs73* @see GenericSAXHandler::myStartElement74*/75void myStartElement(int element,76const SUMOSAXAttributes& attrs);777879/** @brief Called when a closing tag occurs80*81* Processes district elements via closeDistrict.82*83* @param[in] element ID of the currently opened element84* @exception ProcessError If an error within the parsed file occurs85*/86void myEndElement(int element);87//@}888990private:91/** @brief Begins the parsing of a district92*93* Tries to retrieve the id of a district, adds a message to the94* error handler if this fails. Otherwise builds a new district95* with this id at myCurrentDistrict.96*97* @param[in] attrs Attributes of the currently opened element98*/99void openDistrict(const SUMOSAXAttributes& attrs);100101102/** @brief Adds a read source to the current district103*104* Tries to get the id and the weight of the currently parsed source105* from the attributes using getValues. If the retrieval could be106* done without errors (weight>=0), the so retrieved weighted source107* is added to myCurrentDistrict using addSource. (getValues checks108* whether myCurrentDistrict is valid)109*110* @param[in] attrs Attributes of the currently opened element111* @todo Checking whether myCurrentDistrict is valid through getValues is not quite nice112*/113void addSource(const SUMOSAXAttributes& attrs);114115116/** @brief Adds a read sink to the current district117*118* Tries to get the id and the weight of the currently parsed sink119* from the attributes using getValues. If the retrieval could be120* done without errors (weight>=0), the so retrieved weighted sink121* is added to myCurrentDistrict using addSink. (getValues checks122* whether myCurrentDistrict is valid)123*124* @param[in] attrs Attributes of the currently opened element125* @todo Checking whether myCurrentDistrict is valid through getValues is not quite nice126*/127void addSink(const SUMOSAXAttributes& attrs);128129130/** @brief Closes the processing of the current district131*132* Adds myCurrentDistrict to myContainer.133*/134void closeDistrict();135136137/** @brief Returns the id and weight for a taz/tazSink/tazSource138*139* Checks whether myCurrentDistrict (the currently processed140* district) is !=0; in this case, both the id and the weight141* are parsed. If one of them is missing or the weight is not numerical,142* an error is generated and reported to MsgHandler. The "type"-parameter143* is used in order to inform the user whether a source or a sink was144* processed. In the case of an error, the returned weight is -1.145*146* If no error occurs, the correct id and weight are returned.147*148* @param[in] attrs Attributes of the currently opened element149* @param[in] type The type of the currntly processed connection (sink/source)150* @return The id and the weight of a taz151*/152std::pair<std::string, double> parseTAZ(const SUMOSAXAttributes& attrs);153154private:155/// The container to add read districts to156ODDistrictCont& myContainer;157158/// The currently parsed district159ODDistrict* myCurrentDistrict;160161162private:163/// @brief invalidated copy constructor164ODDistrictHandler(const ODDistrictHandler& s);165166/// @brief invalidated assignment operator167ODDistrictHandler& operator=(const ODDistrictHandler& s);168169170};171172173