/****************************************************************************/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 CommonXMLStructure.h14/// @author Pablo Alvarez Lopez15/// @date May 202116///17// Structure for common XML Parsing18/****************************************************************************/19#pragma once20#include <config.h>2122#include <utils/common/SUMOTime.h>23#include <utils/common/RGBColor.h>24#include <utils/geom/PositionVector.h>25#include <utils/vehicle/SUMOVehicleParameter.h>26#include <utils/vehicle/SUMOVTypeParameter.h>27#include <utils/xml/SUMOSAXHandler.h>28#include <utils/xml/SUMOXMLDefinitions.h>293031// ===========================================================================32// class definitions33// ===========================================================================3435class CommonXMLStructure {3637public:3839/// @brief class declaration40class SumoBaseObject;4142/// @brief plan parameters (used for group all from-to parameters related with plans)43class PlanParameters {4445public:46// @brief default constructor47PlanParameters();4849/// @brief constructor for parsing the parameters from SUMOSAXAttributes50PlanParameters(const CommonXMLStructure::SumoBaseObject* sumoBaseObject,51const SUMOSAXAttributes& attrs, bool& parsedOk);5253/// @brief clear parameters54void clear();5556/// @brief check if this is a single-edge plan57bool isSingleEdgePlan() const;5859/// @brief get number of defined plans60int getNumberOfDefinedParameters() const;6162/// @brief get the walk tag for the current combination of parameters63SumoXMLTag getWalkTag() const;6465/// @brief get the personTrip tag for the current combination of parameters66SumoXMLTag getPersonTripTag() const;6768/// @brief get the ride tag for the current combination of parameters69SumoXMLTag getRideTag() const;7071/// @brief get the transport tag for the current combination of parameters72SumoXMLTag getTransportTag() const;7374/// @brief get the tranship tag for the current combination of parameters75SumoXMLTag getTranshipTag() const;7677/// @brief get the person stop tag for the current combination of parameters78SumoXMLTag getPersonStopTag() const;7980/// @brief get the container stop tag for the current combination of parameters81SumoXMLTag getContainerStopTag() const;8283/// @brief from edge84std::string fromEdge;8586/// @brief to edge87std::string toEdge;8889/// @brief consecutive edges90std::vector<std::string> consecutiveEdges;9192/// @brief from junction93std::string fromJunction;9495/// @brief to junction96std::string toJunction;9798/// @brief from TAZ99std::string fromTAZ;100101/// @brief to TAZ102std::string toTAZ;103104/// @brief from busStop105std::string fromBusStop;106107/// @brief to busStop108std::string toBusStop;109110/// @brief from trainStop111std::string fromTrainStop;112113/// @brief to trainStop114std::string toTrainStop;115116/// @brief from containerStop117std::string fromContainerStop;118119/// @brief to containerStop120std::string toContainerStop;121122/// @brief from chargingStation123std::string fromChargingStation;124125/// @brief to chargingStation126std::string toChargingStation;127128/// @brief from parkingArea129std::string fromParkingArea;130131/// @brief to parkingArea132std::string toParkingArea;133134/// @brief from route135std::string fromRoute;136137/// @brief to route138std::string toRoute;139140private:141/// @brief get previous plan obj142const CommonXMLStructure::SumoBaseObject* getPreviousPlanObj(const CommonXMLStructure::SumoBaseObject* sumoBaseObject) const;143144/// @brief update the from attributes145void updateFromAttributes(const CommonXMLStructure::SumoBaseObject* sumoBaseObject);146147/// @brief reste all previous from attributes148void resetPreviousFromAttributes(const CommonXMLStructure::SumoBaseObject* previousPlanObj, const std::string& newType, const std::string& newId) const;149150/// @brief write ignoring message151void writeIgnoringMessage(const CommonXMLStructure::SumoBaseObject* previousPlanObj, const std::string& oldType, const std::string& oldId,152const std::string& newType, const std::string& newId) const;153};154155/// @brief SumoBaseObject156class SumoBaseObject {157158public:159/// @brief constructor160SumoBaseObject(SumoBaseObject* sumoBaseObjectParent);161162/// @brief destructor163~SumoBaseObject();164165/// @brief clear SumoBaseObject166void clear();167168/// @brief set SumoBaseObject tag169void setTag(const SumoXMLTag tag);170171/// @brief mark as successfully created172void markAsCreated();173174/// @name get functions175/// @{176177/// @brief get XML myTag178SumoXMLTag getTag() const;179180/// @brief check if the object was successfully created in build<...> function181bool wasCreated() const;182183/// @brief get pointer to mySumoBaseObjectParent SumoBaseObject (if is null, then is the root)184SumoBaseObject* getParentSumoBaseObject() const;185186/// @brief get all attributes in string format187std::map<std::string, std::string> getAllAttributes() const;188189/// @brief get string attribute190const std::string& getStringAttribute(const SumoXMLAttr attr) const;191192/// @brief get int attribute193int getIntAttribute(const SumoXMLAttr attr) const;194195/// @brief get double attribute196double getDoubleAttribute(const SumoXMLAttr attr) const;197198/// @brief get bool attribute199bool getBoolAttribute(const SumoXMLAttr attr) const;200201/// @brief get Position attribute202const Position& getPositionAttribute(const SumoXMLAttr attr) const;203204/// @brief get time attribute205SUMOTime getTimeAttribute(const SumoXMLAttr attr) const;206207/// @brief get 'period' attribute208SUMOTime getPeriodAttribute() const;209210/// @brief get color attribute211const RGBColor& getColorAttribute(const SumoXMLAttr attr) const;212213/// @brief get string list attribute214const std::vector<std::string>& getStringListAttribute(const SumoXMLAttr attr) const;215216/// @brief get double list attribute217const std::vector<double>& getDoubleListAttribute(const SumoXMLAttr attr) const;218219/// @brief get PositionVector attribute220const PositionVector& getPositionVectorAttribute(const SumoXMLAttr attr) const;221222/// @brief get parent ID223const std::string& getParentID(const SumoXMLTag tag) const;224225/// @brief vehicle class226SUMOVehicleClass getVClass() const;227228/// @brief get current vType229const SUMOVTypeParameter& getVehicleTypeParameter() const;230231/// @brief get vehicle parameters232const SUMOVehicleParameter& getVehicleParameter() const;233234/// @brief get stop parameters235const SUMOVehicleParameter::Stop& getStopParameter() const;236237/// @brief get parameters238const std::map<std::string, std::string>& getParameters() const;239240/// @brief get plan parameteres241const CommonXMLStructure::PlanParameters& getPlanParameters() const;242243/// @brief get SumoBaseObject children244const std::vector<SumoBaseObject*>& getSumoBaseObjectChildren() const;245246/// @}247248/// @brief has function249/// @{250251/// @brief check if current SumoBaseObject has the given string attribute252bool hasStringAttribute(const SumoXMLAttr attr) const;253254/// @brief check if current SumoBaseObject has the given int attribute255bool hasIntAttribute(const SumoXMLAttr attr) const;256257/// @brief check if current SumoBaseObject has the given double attribute258bool hasDoubleAttribute(const SumoXMLAttr attr) const;259260/// @brief check if current SumoBaseObject has the given bool attribute261bool hasBoolAttribute(const SumoXMLAttr attr) const;262263/// @brief check if current SumoBaseObject has the given bool attribute264bool hasPositionAttribute(const SumoXMLAttr attr) const;265266/// @brief check if current SumoBaseObject has the given time attribute267bool hasTimeAttribute(const SumoXMLAttr attr) const;268269/// @brief check if current SumoBaseObject has the given color attribute270bool hasColorAttribute(const SumoXMLAttr attr) const;271272/// @brief check if current SumoBaseObject has the given string list attribute273bool hasStringListAttribute(const SumoXMLAttr attr) const;274275/// @brief check if current SumoBaseObject has the given double list attribute276bool hasDoubleListAttribute(const SumoXMLAttr attr) const;277278/// @brief check if current SumoBaseObject has the given positionVector attribute279bool hasPositionVectorAttribute(const SumoXMLAttr attr) const;280281/// @brief check if current SumoBaseObject has the given parent ID282bool hasParentID(const SumoXMLTag tag) const;283284/// @}285286/// @name add functions287/// @{288289/// @brief add string attribute into current SumoBaseObject node290void addStringAttribute(const SumoXMLAttr attr, const std::string& value);291292/// @brief add int attribute into current SumoBaseObject node293void addIntAttribute(const SumoXMLAttr attr, const int value);294295/// @brief add double attribute into current SumoBaseObject node296void addDoubleAttribute(const SumoXMLAttr attr, const double value);297298/// @brief add bool attribute into current SumoBaseObject node299void addBoolAttribute(const SumoXMLAttr attr, const bool value);300301/// @brief add Position attribute into current SumoBaseObject node302void addPositionAttribute(const SumoXMLAttr attr, const Position& value);303304/// @brief add time attribute into current SumoBaseObject node305void addTimeAttribute(const SumoXMLAttr attr, const SUMOTime value);306307/// @brief add color attribute into current SumoBaseObject node308void addColorAttribute(const SumoXMLAttr attr, const RGBColor& value);309310/// @brief add string list attribute into current SumoBaseObject node311void addStringListAttribute(const SumoXMLAttr attr, const std::vector<std::string>& value);312313/// @brief add double list attribute into current SumoBaseObject node314void addDoubleListAttribute(const SumoXMLAttr attr, const std::vector<double>& value);315316/// @brief add PositionVector attribute into current SumoBaseObject node317void addPositionVectorAttribute(const SumoXMLAttr attr, const PositionVector& value);318319/// @brief add parameters into current SumoBaseObject node (format: key=value1|key2=value2|....)320void addParameters(const std::string& value);321322/// @brief add parameter into current SumoBaseObject node323void addParameter(const std::string& key, const std::string& value);324325/// @brief add parent (string) attribute into current SumoBaseObject node326void addParentID(const SumoXMLTag tag, const std::string& ID);327328/// @brief set vehicle class329void setVClass(SUMOVehicleClass vClass);330331/// @brief set vehicle type parameters332void setVehicleTypeParameter(const SUMOVTypeParameter* vehicleTypeParameter);333334/// @brief set vehicle parameters335void setVehicleParameter(const SUMOVehicleParameter* vehicleParameter);336337/// @brief add stop parameters338void setStopParameter(const SUMOVehicleParameter::Stop& stopParameter);339340/// @brief set plan parmeter341void setPlanParameters(const CommonXMLStructure::PlanParameters& planParameters);342343/// @}344345protected:346/// @brief pointer to SumoBaseObject parent (If is null, then is the root)347SumoBaseObject* mySumoBaseObjectParent;348349/// @brief XML myTag350SumoXMLTag myTag = SUMO_TAG_NOTHING;351352/// @brief flag to check if object was created in build<..> function (by default false)353bool myWasCreated = false;354355/// @brief string attributes356std::map<const SumoXMLAttr, std::string> myStringAttributes;357358/// @brief int attributes359std::map<const SumoXMLAttr, int> myIntAttributes;360361/// @brief double attributes362std::map<const SumoXMLAttr, double> myDoubleAttributes;363364/// @brief bool attributes365std::map<const SumoXMLAttr, bool> myBoolAttributes;366367/// @brief Position attributes368std::map<const SumoXMLAttr, Position> myPositionAttributes;369370/// @brief SUMOTime attributes371std::map<const SumoXMLAttr, SUMOTime> myTimeAttributes;372373/// @brief RGBColor attributes374std::map<const SumoXMLAttr, RGBColor> myColorAttributes;375376/// @brief stringList attributes377std::map<const SumoXMLAttr, std::vector<std::string> > myStringListAttributes;378379/// @brief stringList attributes380std::map<const SumoXMLAttr, std::vector<double> > myDoubleListAttributes;381382/// @brief PositionVector attributes383std::map<const SumoXMLAttr, PositionVector> myPositionVectorAttributes;384385/// @brief myParameters386std::map<std::string, std::string> myParameters;387388/// @brief parent IDs389std::map<const SumoXMLTag, std::string> myParentIDs;390391/// @brief SumoBaseObject children392std::vector<SumoBaseObject*> mySumoBaseObjectChildren;393394/// @brief vehicle class395SUMOVehicleClass myVClass = SVC_IGNORING;396397/// @brief vehicle type parameter398SUMOVTypeParameter myVehicleTypeParameter;399400/// @brief vehicle parameter401SUMOVehicleParameter myVehicleParameter;402403/// @brief stop parameter404SUMOVehicleParameter::Stop myStopParameter;405406/// @brief plan parameters407CommonXMLStructure::PlanParameters myPlanParameters;408409/// @brief add SumoBaseObject child410void addSumoBaseObjectChild(SumoBaseObject* sumoBaseObject);411412/// @brief remove SumoBaseObject child413void removeSumoBaseObjectChild(SumoBaseObject* sumoBaseObject);414415private:416/// @brief flag for defined vehicle type parameter417bool myDefinedVehicleTypeParameter = false;418419/// @brief @brief flag for defined vehicle parameter420bool myDefinedVehicleParameter = false;421422/// @brief @brief flag for defined stop parameter423bool myDefinedStopParameter = false;424425/// @brief handle attribute error426void handleAttributeError(const SumoXMLAttr attr, const std::string& type) const;427428/// @brief invalidate copy constructor429SumoBaseObject(const SumoBaseObject& s) = delete;430431/// @brief invalidate assignment operator432SumoBaseObject& operator=(const SumoBaseObject& s) = delete;433};434435/// @brief Constructor436CommonXMLStructure();437438/// @brief Destructor439~CommonXMLStructure();440441/// @brief open SUMOBaseOBject442void openSUMOBaseOBject();443444/// @brief close SUMOBaseOBject445void closeSUMOBaseOBject();446447/// @brief abort SUMOBaseOBject448void abortSUMOBaseOBject();449450/// @brief get SumoBaseObject root451CommonXMLStructure::SumoBaseObject* getSumoBaseObjectRoot() const;452453/// @brief get current editedSumoBaseObject454CommonXMLStructure::SumoBaseObject* getCurrentSumoBaseObject() const;455456protected:457/// @brief SumoBaseObject root458CommonXMLStructure::SumoBaseObject* mySumoBaseObjectRoot;459460/// @brief last inserted SumoBaseObject461CommonXMLStructure::SumoBaseObject* myCurrentSumoBaseObject;462463private:464/// @brief invalidate copy constructor465CommonXMLStructure(const CommonXMLStructure& s) = delete;466467/// @brief invalidate assignment operator468CommonXMLStructure& operator=(const CommonXMLStructure& s) = delete;469};470471472