/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2026 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 declaration27// ===========================================================================2829class FileBucket;3031// ===========================================================================32// class definitions33// ===========================================================================3435class CommonHandler {3637public:38/**@brief Constructor39* @param[in] bucket FileBucket in which place the element40*/41CommonHandler(FileBucket* fileBucket);4243/// @brief Destructor44virtual ~CommonHandler();4546/// @brief force overwritte elements (used if we're reloading elements)47void forceOverwriteElements();4849/// @brief force remain elements (used if we're reloading elements)50void forceRemainElements();5152/// @brief abort loading53void abortLoading();5455/// @brief get flag for mark if a element wasn't created56bool isErrorCreatingElement() const;5758/// @brief force overwritte elements (used if we're reloading elements)59bool isForceOverwriteElements() const;6061/// @brief force remain elements (used if we're reloading elements)62bool isForceRemainElements() const;6364/// @brief abort loading65bool isAbortLoading() const;6667protected:68/// @brief fileBucket69FileBucket* myFileBucket = nullptr;7071/// @brief common XML Structure72CommonXMLStructure myCommonXMLStructure;7374/// @brief flag for mark if a element wasn't created75bool myErrorCreatingElement = false;7677/// @brief overwrite elements78bool myOverwriteElements = false;7980/// @brief remain elements81bool myRemainElements = false;8283/// @brief abort loading84bool myAbortLoading = false;8586/// @brief parse generic parameters87void parseParameters(const SUMOSAXAttributes& attrs);8889/// @brief get embedded route from children90CommonXMLStructure::SumoBaseObject* getEmbeddedRoute(const CommonXMLStructure::SumoBaseObject* sumoBaseObject) const;9192/// @name check functions93/// @{9495/// @brief check parsed parents96void checkParsedParent(const SumoXMLTag currentTag, const std::vector<SumoXMLTag>& parentTags, bool& ok);9798/// @brief check list of IDs99bool checkListOfVehicleTypes(const SumoXMLTag tag, const std::string& id, const std::vector<std::string>& vTypeIDs);100101/// @brief check if the given object is within a distribution (VType or routes)102bool checkWithinDistribution(CommonXMLStructure::SumoBaseObject* obj);103104/// @brief check vehicle parents105bool checkVehicleParents(CommonXMLStructure::SumoBaseObject* obj);106107/// @brief check person plan parents108bool checkPersonPlanParents(CommonXMLStructure::SumoBaseObject* obj);109110/// @brief check container plan parents111bool checkContainerPlanParents(CommonXMLStructure::SumoBaseObject* obj);112113/// @brief check stop parents114bool checkStopParents(CommonXMLStructure::SumoBaseObject* obj);115116/// @brief check if the given int value is NOT negative117bool checkNegative(const SumoXMLTag tag, const std::string& id, const SumoXMLAttr attribute, const int value, const bool canBeZero);118119/// @brief check if the given double value is NOT negative120bool checkNegative(const SumoXMLTag tag, const std::string& id, const SumoXMLAttr attribute, const double value, const bool canBeZero);121122/// @brief check if the given SUMOTime value is NOT negative123bool checkNegative(const SumoXMLTag tag, const std::string& id, const SumoXMLAttr attribute, const SUMOTime value, const bool canBeZero);124125/// @brief check if the given filename is valid126bool checkFileName(const SumoXMLTag tag, const std::string& id, const SumoXMLAttr attribute, const std::string& value);127128/// @brief check if the given additional ID is valid129bool checkValidAdditionalID(const SumoXMLTag tag, const std::string& value);130131/// @brief check if the given detector ID is valid132bool checkValidDetectorID(const SumoXMLTag tag, const std::string& value);133134/// @brief check if the given demand elmement ID is valid135bool checkValidDemandElementID(const SumoXMLTag tag, const std::string& value);136137/// @}138139/// @brief write warning overwritting element140void writeWarningOverwriting(const SumoXMLTag tag, const std::string& id);141142/// @brief write warning duplicated element143bool writeWarningDuplicated(const SumoXMLTag tag, const std::string& id, const SumoXMLTag checkedTag);144145/// @brief write error and enable error creating element146bool writeError(const std::string& error);147148/// @brief write error "invalid position"149bool writeErrorInvalidPosition(const SumoXMLTag tag, const std::string& id);150151/// @brief write error "invalid list of lanes"152bool writeErrorInvalidLanes(const SumoXMLTag tag, const std::string& id);153154/// @brief write error "invalid parent element" giving ids of current and parent element155bool writeErrorInvalidParent(const SumoXMLTag tag, const std::string& id, const std::vector<SumoXMLTag> parentTags, const std::string& parentID);156157/// @brief write error "invalid parent element" giving only the id of parent element158bool writeErrorInvalidParent(const SumoXMLTag tag, const std::vector<SumoXMLTag> parentTags, const std::string& parentID);159160/// @brief write error "invalid parent element" without giving IDs161bool writeErrorInvalidParent(const SumoXMLTag tag, const std::vector<SumoXMLTag> parentTags);162163private:164/// @brief parse list of parent tags165std::string parseParentTags(std::vector<SumoXMLTag> parentTags) const;166167/// @brief invalidate default onstructor168CommonHandler() = delete;169170/// @brief invalidate copy constructor171CommonHandler(const CommonHandler& s) = delete;172173/// @brief invalidate assignment operator174CommonHandler& operator=(const CommonHandler& s) = delete;175};176177178