/****************************************************************************/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 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 check if start and end position of a stop is valid68static bool isStopPosValid(const double startPos, const double endPos, const double laneLength, const double minLength, const bool friendlyPos);6970/// @brief returns the first departure time that was ever read71SUMOTime getFirstDepart() const;7273/// @brief Returns the last loaded depart time74SUMOTime getLastDepart() const;7576protected:77/// @name inherited from GenericSAXHandler78//@{7980/** @brief Called on the opening of a tag;81*82* @param[in] element ID of the currently opened element83* @param[in] attrs Attributes within the currently opened element84* @exception ProcessError If something fails85* @see GenericSAXHandler::myStartElement86*/87virtual void myStartElement(int element,88const SUMOSAXAttributes& attrs);8990/** @brief Called when a closing tag occurs91*92* @param[in] element ID of the currently opened element93* @exception ProcessError If something fails94* @see GenericSAXHandler::myEndElement95*/96virtual void myEndElement(int element);97//@}9899/// @name open element functions100//@{101102/// @brief opens a type distribution for reading103virtual void openVehicleTypeDistribution(const SUMOSAXAttributes& attrs) = 0;104105/// @brief closes (ends) the building of a distribution106virtual void closeVehicleTypeDistribution() = 0;107108/// @brief opens a route for reading109virtual void openRoute(const SUMOSAXAttributes& attrs) = 0;110111/// @brief opens a flow for reading112virtual void openFlow(const SUMOSAXAttributes& attrs) = 0;113114/// @brief opens a route flow for reading115virtual void openRouteFlow(const SUMOSAXAttributes& attrs) = 0;116117/// @brief opens a trip for reading118virtual void openTrip(const SUMOSAXAttributes& attrs) = 0;119//@}120121/// @name close element functions122//@{123124/**closes (ends) the building of a route.125* Afterwards no edges may be added to it;126* this method may throw exceptions when127* a) the route is empty or128* b) another route with the same id already exists129*/130virtual void closeRoute(const bool mayBeDisconnected = false) = 0;131132/// @brief opens a route distribution for reading133virtual void openRouteDistribution(const SUMOSAXAttributes& attrs) = 0;134135/// @brief closes (ends) the building of a distribution136virtual void closeRouteDistribution() = 0;137138/// @brief Ends the processing of a vehicle139virtual void closeVehicle() = 0;140141/// @brief Ends the processing of a vehicle type142virtual void closeVType() = 0;143144/// @brief Ends the processing of a person145virtual void closePerson() = 0;146147/// @brief Ends the processing of a person flow148virtual void closePersonFlow() = 0;149150/// @brief Ends the processing of a container151virtual void closeContainer() = 0;152153/// @brief Ends the processing of a container flow154virtual void closeContainerFlow() = 0;155156/// @brief Ends the processing of a flow157virtual void closeFlow() = 0;158159/// @brief Ends the processing of a trip160virtual void closeTrip() = 0;161//@}162163/// @name add element functions164//@{165166/// @brief Processing of a person or container167virtual void addTransportable(const SUMOSAXAttributes& attrs, const bool isPerson) {168UNUSED_PARAMETER(attrs);169UNUSED_PARAMETER(isPerson);170}171172/// @brief Processing of a stop173virtual Parameterised* addStop(const SUMOSAXAttributes& attrs) = 0;174175/// @brief add a routing request for a walking or intermodal person176virtual void addPersonTrip(const SUMOSAXAttributes& attrs) = 0;177178/// @brief add a fully specified walk179virtual void addWalk(const SUMOSAXAttributes& attrs) = 0;180181/// @brief Processing of a ride182virtual void addRide(const SUMOSAXAttributes& attrs) = 0;183184/// @brief Processing of a transport185virtual void addTransport(const SUMOSAXAttributes& attrs) = 0;186187/// @brief Processing of a tranship188virtual void addTranship(const SUMOSAXAttributes& attrs) = 0;189190//@}191192/// @brief Checks whether the route file is sorted by departure time if needed193virtual bool checkLastDepart();194195/// @brief save last depart (only to be used if vehicle is not discarded)196void registerLastDepart();197198/// @brief assign arbitrary vehicle parameters199void addParam(const SUMOSAXAttributes& attrs);200201/// @brief parses attributes common to all stops202bool parseStop(SUMOVehicleParameter::Stop& stop, const SUMOSAXAttributes& attrs, std::string errorSuffix, MsgHandler* const errorOutput);203204protected:205/// @brief flag to enable or disable hard fails206const bool myHardFail;207208/// @brief Parameter of the current vehicle, trip, person, container or flow209SUMOVehicleParameter* myVehicleParameter;210211/// @brief The stack of currently parsed parameterised objects212std::vector<Parameterised*> myParamStack;213214/// @brief The insertion time of the vehicle read last215SUMOTime myLastDepart;216217/// @brief The id of the current route218std::string myActiveRouteID;219220/// @brief The id of the route the current route references to221std::string myActiveRouteRefID;222223/// @brief The probability of the current route224double myActiveRouteProbability;225226/// @brief The currently parsed route's color227const RGBColor* myActiveRouteColor;228229/// @brief The currently parsed route costs230double myCurrentCosts;231232/// @brief List of the stops on the parsed route233StopParVector myActiveRouteStops;234235/// @brief The currently parsed vehicle type236SUMOVTypeParameter* myCurrentVType;237238/// @brief The default value for flow begins239SUMOTime myBeginDefault;240241/// @brief The default value for flow ends242SUMOTime myEndDefault;243244/// @brief the first read departure time245SUMOTime myFirstDepart;246247/// @brief where stop edges can be inserted into the current route (-1 means no insertion)248int myInsertStopEdgesAt;249250/// @brief hierarchy of elements being parsed251std::vector<int> myElementStack;252253/// @brief whether references to internal routes are allowed in this context254bool myAllowInternalRoutes;255256private:257/// @brief Invalidated copy constructor258SUMORouteHandler(const SUMORouteHandler& s) = delete;259260/// @brief Invalidated assignment operator261SUMORouteHandler& operator=(const SUMORouteHandler& s) = delete;262};263264265