/****************************************************************************/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 SUMORouteHandler.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @date Mon, 9 Jul 200118///19// Parser for routes during their loading20/****************************************************************************/21#pragma once22#include <config.h>2324#include <utils/common/IDSupplier.h>25#include <utils/common/SUMOTime.h>26#include <utils/vehicle/SUMOVehicleParameter.h>27#include <utils/xml/SUMOSAXHandler.h>282930// ===========================================================================31// class declarations32// ===========================================================================33class MsgHandler;34class SUMOVTypeParameter;353637// ===========================================================================38// class definitions39// ===========================================================================40/**41* @class SUMORouteHandler42* @brief Parser for routes during their loading43*44* SUMORouteHandler is the abstract super class for routers45* and simulation loading routes.46*/47class SUMORouteHandler : public SUMOSAXHandler {48public:49/// @brief enum for stops50enum StopPos {51STOPPOS_VALID,52STOPPOS_INVALID_STARTPOS,53STOPPOS_INVALID_ENDPOS,54STOPPOS_INVALID_LANELENGTH55};5657/// @brief standard constructor58SUMORouteHandler(const std::string& file, const std::string& expectedRoot, const bool hardFail);5960/// @brief standard destructor61virtual ~SUMORouteHandler();6263/**@brief check start and end position of a stop64* @brief return */65static StopPos checkStopPos(double& startPos, double& endPos, const double laneLength, const double minLength, const bool friendlyPos);6667/// @brief returns the first departure time that was ever read68SUMOTime getFirstDepart() const;6970/// @brief Returns the last loaded depart time71SUMOTime getLastDepart() const;7273protected:74/// @name inherited from GenericSAXHandler75//@{7677/** @brief Called on the opening of a tag;78*79* @param[in] element ID of the currently opened element80* @param[in] attrs Attributes within the currently opened element81* @exception ProcessError If something fails82* @see GenericSAXHandler::myStartElement83*/84virtual void myStartElement(int element,85const SUMOSAXAttributes& attrs);8687/** @brief Called when a closing tag occurs88*89* @param[in] element ID of the currently opened element90* @exception ProcessError If something fails91* @see GenericSAXHandler::myEndElement92*/93virtual void myEndElement(int element);94//@}9596/// @name open element functions97//@{9899/// @brief opens a type distribution for reading100virtual void openVehicleTypeDistribution(const SUMOSAXAttributes& attrs) = 0;101102/// @brief closes (ends) the building of a distribution103virtual void closeVehicleTypeDistribution() = 0;104105/// @brief opens a route for reading106virtual void openRoute(const SUMOSAXAttributes& attrs) = 0;107108/// @brief opens a flow for reading109virtual void openFlow(const SUMOSAXAttributes& attrs) = 0;110111/// @brief opens a route flow for reading112virtual void openRouteFlow(const SUMOSAXAttributes& attrs) = 0;113114/// @brief opens a trip for reading115virtual void openTrip(const SUMOSAXAttributes& attrs) = 0;116//@}117118/// @name close element functions119//@{120121/**closes (ends) the building of a route.122* Afterwards no edges may be added to it;123* this method may throw exceptions when124* a) the route is empty or125* b) another route with the same id already exists126*/127virtual void closeRoute(const bool mayBeDisconnected = false) = 0;128129/// @brief opens a route distribution for reading130virtual void openRouteDistribution(const SUMOSAXAttributes& attrs) = 0;131132/// @brief closes (ends) the building of a distribution133virtual void closeRouteDistribution() = 0;134135/// @brief Ends the processing of a vehicle136virtual void closeVehicle() = 0;137138/// @brief Ends the processing of a vehicle type139virtual void closeVType() = 0;140141/// @brief Ends the processing of a person142virtual void closePerson() = 0;143144/// @brief Ends the processing of a person flow145virtual void closePersonFlow() = 0;146147/// @brief Ends the processing of a container148virtual void closeContainer() = 0;149150/// @brief Ends the processing of a container flow151virtual void closeContainerFlow() = 0;152153/// @brief Ends the processing of a flow154virtual void closeFlow() = 0;155156/// @brief Ends the processing of a trip157virtual void closeTrip() = 0;158//@}159160/// @name add element functions161//@{162163/// @brief Processing of a person or container164virtual void addTransportable(const SUMOSAXAttributes& attrs, const bool isPerson) {165UNUSED_PARAMETER(attrs);166UNUSED_PARAMETER(isPerson);167}168169/// @brief Processing of a stop170virtual Parameterised* addStop(const SUMOSAXAttributes& attrs) = 0;171172/// @brief add a routing request for a walking or intermodal person173virtual void addPersonTrip(const SUMOSAXAttributes& attrs) = 0;174175/// @brief add a fully specified walk176virtual void addWalk(const SUMOSAXAttributes& attrs) = 0;177178/// @brief Processing of a ride179virtual void addRide(const SUMOSAXAttributes& attrs) = 0;180181/// @brief Processing of a transport182virtual void addTransport(const SUMOSAXAttributes& attrs) = 0;183184/// @brief Processing of a tranship185virtual void addTranship(const SUMOSAXAttributes& attrs) = 0;186187//@}188189/// @brief Checks whether the route file is sorted by departure time if needed190virtual bool checkLastDepart();191192/// @brief save last depart (only to be used if vehicle is not discarded)193void registerLastDepart();194195/// @brief assign arbitrary vehicle parameters196void addParam(const SUMOSAXAttributes& attrs);197198/// @brief parses attributes common to all stops199bool parseStop(SUMOVehicleParameter::Stop& stop, const SUMOSAXAttributes& attrs, std::string errorSuffix, MsgHandler* const errorOutput);200201protected:202/// @brief flag to enable or disable hard fails203const bool myHardFail;204205/// @brief Parameter of the current vehicle, trip, person, container or flow206SUMOVehicleParameter* myVehicleParameter;207208/// @brief The stack of currently parsed parameterised objects209std::vector<Parameterised*> myParamStack;210211/// @brief The insertion time of the vehicle read last212SUMOTime myLastDepart;213214/// @brief The id of the current route215std::string myActiveRouteID;216217/// @brief The id of the route the current route references to218std::string myActiveRouteRefID;219220/// @brief The probability of the current route221double myActiveRouteProbability;222223/// @brief The currently parsed route's color224const RGBColor* myActiveRouteColor;225226/// @brief The currently parsed route costs227double myCurrentCosts;228229/// @brief List of the stops on the parsed route230StopParVector myActiveRouteStops;231232/// @brief The currently parsed vehicle type233SUMOVTypeParameter* myCurrentVType;234235/// @brief The default value for flow begins236SUMOTime myBeginDefault;237238/// @brief The default value for flow ends239SUMOTime myEndDefault;240241/// @brief the first read departure time242SUMOTime myFirstDepart;243244/// @brief where stop edges can be inserted into the current route (-1 means no insertion)245int myInsertStopEdgesAt;246247/// @brief hierarchy of elements being parsed248std::vector<int> myElementStack;249250/// @brief whether references to internal routes are allowed in this context251bool myAllowInternalRoutes;252253/// @brief IDs of skipped vehicles to suppress errors for the triggered transportables within254std::set<std::string> mySkippedVehicles;255256private:257/// @brief Invalidated copy constructor258SUMORouteHandler(const SUMORouteHandler& s) = delete;259260/// @brief Invalidated assignment operator261SUMORouteHandler& operator=(const SUMORouteHandler& s) = delete;262};263264265