LCOV - code coverage report
Current view: top level - src/utils/vehicle - SUMOTrafficObject.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 44.4 % 9 4
Test Date: 2025-12-06 15:35:27 Functions: 50.0 % 4 2

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    SUMOTrafficObject.h
      15              : /// @author  Jakob Erdmann
      16              : /// @date    Mon, 25 Mar 2019
      17              : ///
      18              : // Abstract base class for vehicle, person, and container representations
      19              : /****************************************************************************/
      20              : #pragma once
      21              : #include <config.h>
      22              : 
      23              : #include <string>
      24              : #include <vector>
      25              : #include <typeinfo>
      26              : #include <memory>
      27              : #include <utils/common/SUMOTime.h>
      28              : #include <utils/common/Named.h>
      29              : #include <utils/common/SUMOVehicleClass.h>
      30              : 
      31              : 
      32              : // ===========================================================================
      33              : // class declarations
      34              : // ===========================================================================
      35              : class MSVehicleType;
      36              : class SUMOVehicleParameter;
      37              : class SUMOVTypeParameter;
      38              : class MSEdge;
      39              : class MSLane;
      40              : class Position;
      41              : class MSDevice;
      42              : class MSRoute;
      43              : 
      44              : typedef std::shared_ptr<const MSRoute> ConstMSRoutePtr;
      45              : 
      46              : 
      47              : // ===========================================================================
      48              : // class definitions
      49              : // ===========================================================================
      50              : /**
      51              :  * @class SUMOTrafficObject
      52              :  * @brief Representation of a vehicle, person, or container
      53              :  */
      54              : class SUMOTrafficObject : public Named {
      55              : public:
      56              :     typedef long long int NumericalID;
      57              : 
      58              :     /// @brief Constructor
      59              :     SUMOTrafficObject(const std::string& id) : Named(id) {}
      60              : 
      61              :     /// @brief Destructor
      62            0 :     virtual ~SUMOTrafficObject() {}
      63              : 
      64              :     /** @brief Whether it is a vehicle
      65              :      * @return true for vehicles, false otherwise
      66              :      */
      67      1685005 :     virtual bool isVehicle() const {
      68      1685005 :         return false;
      69              :     }
      70              : 
      71              :     /** @brief Whether it is a person
      72              :      * @return true for persons, false otherwise
      73              :      */
      74      9394645 :     virtual bool isPerson() const {
      75      9394645 :         return false;
      76              :     }
      77              : 
      78              :     /** @brief Whether it is a container
      79              :      * @return true for containers, false otherwise
      80              :      */
      81            0 :     virtual bool isContainer() const {
      82            0 :         return false;
      83              :     }
      84              : 
      85              :     /// @brief return the numerical ID which is only for internal usage
      86              :     //  (especially fast comparison in maps which need vehicles as keys)
      87              :     virtual NumericalID getNumericalID() const = 0;
      88              : 
      89              :     /// @brief return an object-specific random constant
      90              :     virtual long long int getRandomSeed() const = 0;
      91              : 
      92              :     /** @brief Returns the object's "vehicle" type
      93              :      * @return The vehicle's type
      94              :      */
      95              :     virtual const MSVehicleType& getVehicleType() const = 0;
      96              : 
      97              :     /** @brief Returns the object's "vehicle" type parameter
      98              :      * @return The type parameter
      99              :      */
     100              :     virtual const SUMOVTypeParameter& getVTypeParameter() const = 0;
     101              : 
     102              :     /** @brief Replaces the current vehicle type by the one given
     103              :     *
     104              :     * If the currently used vehicle type is marked as being used by this object
     105              :     *  only, it is deleted, first. The new, given type is then assigned to
     106              :     *  "myVType".
     107              :     * @param[in] type The new vehicle type
     108              :     * @see MSTransportable::myVType
     109              :     */
     110              :     virtual void replaceVehicleType(const MSVehicleType* type) = 0;
     111              : 
     112              : 
     113              :     /** @brief Returns the vehicle's parameter (including departure definition)
     114              :      *
     115              :      * @return The vehicle's parameter
     116              :      */
     117              :     virtual const SUMOVehicleParameter& getParameter() const = 0;
     118              : 
     119              :     /** @brief Returns the associated RNG for this object
     120              :     * @return The vehicle's associated RNG
     121              :     */
     122              :     virtual SumoRNG* getRNG() const = 0;
     123              : 
     124              :     /// @brief @return The index of the associated RNG
     125              :     virtual int getRNGIndex() const = 0;
     126              : 
     127              :     /** @brief Returns whether the object is at a stop
     128              :      * @return Whether it has stopped
     129              :      */
     130              :     virtual bool isStopped() const = 0;
     131              : 
     132              :     /** @brief Returns the edge the object is currently at
     133              :      *
     134              :      * @return The current edge in the object's route
     135              :      */
     136              :     virtual const MSEdge* getEdge() const = 0;
     137              : 
     138              :     /// @brief returns the next edge (possibly an internal edge)
     139              :     virtual const MSEdge* getNextEdgePtr() const = 0;
     140              : 
     141              :     /// @brief returns the numerical IDs of edges to be used (possibly of future stages)
     142              :     virtual const std::set<NumericalID> getUpcomingEdgeIDs() const = 0;
     143              : 
     144              :     /** @brief Returns the lane the object is currently at
     145              :      *
     146              :      * @return The current lane or nullptr if the object is not on a lane
     147              :      */
     148              :     virtual const MSLane* getLane() const = 0;
     149              : 
     150              :     /** @brief Returns the lane the where the rear of the object is currently at
     151              :      *
     152              :      * @return The current back lane or nullptr if the object is not on a lane
     153              :      */
     154              :     virtual const MSLane* getBackLane() const = 0;
     155              : 
     156              : 
     157              :     /// @brief return index of edge within route
     158              :     virtual int getRoutePosition() const = 0;
     159              : 
     160              :     /** @brief Returns the end point for reroutes (usually the last edge of the route)
     161              :      *
     162              :      * @return The rerouting end point
     163              :      */
     164              :     virtual const MSEdge* getRerouteDestination() const = 0;
     165              : 
     166              :     /// Replaces the current route by the given one
     167              :     virtual bool replaceRoute(ConstMSRoutePtr route, const std::string& info, bool onInit = false, int offset = 0, bool addStops = true, bool removeStops = true, std::string* msgReturn = nullptr) = 0;
     168              : 
     169              :     /** @brief Returns the slope of the road at object's position in degrees
     170              :      * @return The slope
     171              :      */
     172              :     virtual double getSlope() const = 0;
     173              : 
     174              :     virtual double getChosenSpeedFactor() const = 0;
     175              : 
     176              :     /** @brief Returns the object's access class
     177              :      * @return The object's access class
     178              :      */
     179              :     virtual SUMOVehicleClass getVClass() const = 0;
     180              : 
     181              :     /** @brief Returns whether this object is ignoring transient permission
     182              :      * changes (during routing)
     183              :      */
     184            0 :     virtual bool ignoreTransientPermissions() const {
     185            0 :         return false;
     186              :     };
     187              : 
     188              :     virtual int getRoutingMode() const = 0;
     189              : 
     190              :     /** @brief Returns the object's maximum speed (minimum of technical and desired maximum speed)
     191              :      * @return The object's maximum speed
     192              :      */
     193              :     virtual double getMaxSpeed() const = 0;
     194              : 
     195              :     virtual SUMOTime getWaitingTime(const bool accumulated = false) const = 0;
     196              : 
     197              :     /** @brief Returns the object's current speed
     198              :      * @return The object's speed
     199              :      */
     200              :     virtual double getSpeed() const = 0;
     201              : 
     202              :     // This definition was introduced to make the MSVehicle's previousSpeed Refs. #2579
     203              :     /** @brief Returns the object's previous speed
     204              :      * @return The object's previous speed
     205              :      */
     206              :     virtual double getPreviousSpeed() const = 0;
     207              : 
     208              : 
     209              :     /** @brief Returns the object's acceleration
     210              :      * @return The acceleration
     211              :      */
     212              :     virtual double getAcceleration() const = 0;
     213              : 
     214              :     /** @brief Get the object's position along the lane
     215              :      * @return The position of the object (in m from the lane's begin)
     216              :      */
     217              :     virtual double getPositionOnLane() const = 0;
     218              : 
     219              :     /** @brief Get the object's back position along the given lane
     220              :      * @return The position of the object (in m from the given lane's begin)
     221              :      */
     222              :     virtual double getBackPositionOnLane(const MSLane* lane) const = 0;
     223              : 
     224              : 
     225              :     /** @brief Return current position (x/y, cartesian)
     226              :      *
     227              :      * If the object is not in the net, Position::INVALID.
     228              :      * @param[in] offset optional offset in longitudinal direction
     229              :      * @return The current position (in cartesian coordinates)
     230              :      * @see myLane
     231              :      */
     232              :     virtual Position getPosition(const double offset = 0) const = 0;
     233              : 
     234              :     /** @brief Returns the object's angle in degrees
     235              :      */
     236              :     virtual double getAngle() const = 0;
     237              : 
     238              :     /** @brief Returns whether this object has arrived
     239              :      */
     240              :     virtual bool hasArrived() const = 0;
     241              : 
     242              :     /// @brief whether the vehicle is individually influenced (via TraCI or special parameters)
     243              :     virtual bool hasInfluencer() const = 0;
     244              : 
     245              :     /// @brief whether this object is selected in the GUI
     246              :     virtual bool isSelected() const = 0;
     247              : 
     248              :     /// @brief Returns a device of the given type if it exists or nullptr if not
     249              :     virtual MSDevice* getDevice(const std::type_info& type) const = 0;
     250              : 
     251              :     /// @name Helper methods for parsing parameters from the object itself, it's type or the global OptionsCont
     252              :     /// @{
     253              :     /** @brief Retrieve a string parameter for the traffic object.
     254              :      * @param paramName the parameter name
     255              :      * @param required whether it is an error if the parameter is not set
     256              :      * @param deflt the default value to take if the parameter is not set (the default in the OptionsCont takes precedence)
     257              :      * @return the string value
     258              :      */
     259              :     std::string getStringParam(const std::string& paramName, const bool required = false, const std::string& deflt = "") const;
     260              : 
     261              :     /** @brief Retrieve a floating point parameter for the traffic object.
     262              :      * @param paramName the parameter name
     263              :      * @param required whether it is an error if the parameter is not set
     264              :      * @param deflt the default value to take if the parameter is not set (the default in the OptionsCont takes precedence)
     265              :      * @param checkDist whether the given value may be a distribution definition
     266              :      * @return the float value
     267              :      */
     268              :     double getFloatParam(const std::string& paramName, const bool required = false, const double deflt = INVALID_DOUBLE, bool checkDist = true) const;
     269              : 
     270              :     /** @brief Retrieve a boolean parameter for the traffic object.
     271              :      * @param paramName the parameter name
     272              :      * @param required whether it is an error if the parameter is not set
     273              :      * @param deflt the default value to take if the parameter is not set (the default in the OptionsCont takes precedence)
     274              :      * @return the bool value
     275              :      */
     276              :     bool getBoolParam(const std::string& paramName, const bool required = false, const bool deflt = false) const;
     277              : 
     278              :     /** @brief Retrieve a time parameter for the traffic object.
     279              :      * @param paramName the parameter name
     280              :      * @param required whether it is an error if the parameter is not set
     281              :      * @param deflt the default value to take if the parameter is not set (the default in the OptionsCont takes precedence)
     282              :      * @return the time value
     283              :      */
     284              :     SUMOTime getTimeParam(const std::string& paramName, const bool required = false, const SUMOTime deflt = SUMOTime_MIN) const;
     285              :     /// @}
     286              : };
        

Generated by: LCOV version 2.0-1