/****************************************************************************/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 CommonHandler.h14/// @author Pablo Alvarez Lopez15/// @date Dec 202416///17// Collection of functions used in handlers18/****************************************************************************/19#pragma once20#include <config.h>2122#include <utils/xml/CommonXMLStructure.h>23#include <utils/xml/SUMOSAXHandler.h>2425// ===========================================================================26// class definitions27// ===========================================================================28/**29* @class CommonHandler30* @brief The XML-Handler for network loading31*32* The SAX2-handler responsible for parsing networks and routes to load.33* This is an extension of the MSRouteHandler as routes and vehicles may also34* be loaded from network descriptions.35*/36class CommonHandler {3738public:39/**@brief Constructor40* @param[in] filename Name of the parsed file41*/42CommonHandler(const std::string& filename);4344/// @brief Destructor45virtual ~CommonHandler();4647/// @brief force overwritte elements (used if we're reloading elements)48void forceOverwriteElements();4950/// @brief force remain elements (used if we're reloading elements)51void forceRemainElements();5253/// @brief abort loading54void abortLoading();5556/// @brief get flag for mark if a element wasn't created57bool isErrorCreatingElement() const;5859/// @brief force overwritte elements (used if we're reloading elements)60bool isForceOverwriteElements() const;6162/// @brief force remain elements (used if we're reloading elements)63bool isForceRemainElements() const;6465/// @brief abort loading66bool isAbortLoading() const;6768protected:69/// @brief filename70const std::string myFilename;7172/// @brief common XML Structure73CommonXMLStructure myCommonXMLStructure;7475/// @brief flag for mark if a element wasn't created76bool myErrorCreatingElement = false;7778/// @brief overwrite elements79bool myOverwriteElements = false;8081/// @brief remain elements82bool myRemainElements = false;8384/// @brief abort loading85bool myAbortLoading = false;8687/// @brief parse generic parameters88void parseParameters(const SUMOSAXAttributes& attrs);8990/// @brief get embedded route from children91CommonXMLStructure::SumoBaseObject* getEmbeddedRoute(const CommonXMLStructure::SumoBaseObject* sumoBaseObject) const;9293/// @name check functions94/// @{9596/// @brief check parsed parents97void checkParsedParent(const SumoXMLTag currentTag, const std::vector<SumoXMLTag>& parentTags, bool& ok);9899/// @brief check list of IDs100bool checkListOfVehicleTypes(const SumoXMLTag tag, const std::string& id, const std::vector<std::string>& vTypeIDs);101102/// @brief check if the given object is within a distribution (VType or routes)103bool checkWithinDistribution(CommonXMLStructure::SumoBaseObject* obj);104105/// @brief check vehicle parents106bool checkVehicleParents(CommonXMLStructure::SumoBaseObject* obj);107108/// @brief check person plan parents109bool checkPersonPlanParents(CommonXMLStructure::SumoBaseObject* obj);110111/// @brief check container plan parents112bool checkContainerPlanParents(CommonXMLStructure::SumoBaseObject* obj);113114/// @brief check stop parents115bool checkStopParents(CommonXMLStructure::SumoBaseObject* obj);116117/// @brief check if the given int value is NOT negative118bool checkNegative(const SumoXMLTag tag, const std::string& id, const SumoXMLAttr attribute, const int value, const bool canBeZero);119120/// @brief check if the given double value is NOT negative121bool checkNegative(const SumoXMLTag tag, const std::string& id, const SumoXMLAttr attribute, const double value, const bool canBeZero);122123/// @brief check if the given SUMOTime value is NOT negative124bool checkNegative(const SumoXMLTag tag, const std::string& id, const SumoXMLAttr attribute, const SUMOTime value, const bool canBeZero);125126/// @brief check if the given filename is valid127bool checkFileName(const SumoXMLTag tag, const std::string& id, const SumoXMLAttr attribute, const std::string& value);128129/// @brief check if the given additional ID is valid130bool checkValidAdditionalID(const SumoXMLTag tag, const std::string& value);131132/// @brief check if the given detector ID is valid133bool checkValidDetectorID(const SumoXMLTag tag, const std::string& value);134135/// @brief check if the given demand elmement ID is valid136bool checkValidDemandElementID(const SumoXMLTag tag, const std::string& value);137138/// @}139140/// @brief write warning overwritting element141void writeWarningOverwriting(const SumoXMLTag tag, const std::string& id);142143/// @brief write warning duplicated element144bool writeWarningDuplicated(const SumoXMLTag tag, const std::string& id, const SumoXMLTag checkedTag);145146/// @brief write error and enable error creating element147bool writeError(const std::string& error);148149/// @brief write error "invalid position"150bool writeErrorInvalidPosition(const SumoXMLTag tag, const std::string& id);151152/// @brief write error "empty edges"153bool writeErrorEmptyEdges(const SumoXMLTag tag, const std::string& id);154155/// @brief write error "invalid list of lanes"156bool writeErrorInvalidLanes(const SumoXMLTag tag, const std::string& id);157158/// @brief write error "invalid parent element" giving ids of current and parent element159bool writeErrorInvalidParent(const SumoXMLTag tag, const std::string& id, const SumoXMLTag parentTag, const std::string& parentID);160161/// @brief write error "invalid parent element" giving only the id of parent element162bool writeErrorInvalidParent(const SumoXMLTag tag, const SumoXMLTag parentTag, const std::string& parentID);163164/// @brief write error "invalid parent element" without giving IDs165bool writeErrorInvalidParent(const SumoXMLTag tag, const SumoXMLTag parentTag);166167private:168/// @brief invalidate default onstructor169CommonHandler() = delete;170171/// @brief invalidate copy constructor172CommonHandler(const CommonHandler& s) = delete;173174/// @brief invalidate assignment operator175CommonHandler& operator=(const CommonHandler& s) = delete;176};177178179