LCOV - code coverage report
Current view: top level - src/microsim/devices - MSDevice_Transportable.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 4 5 80.0 %
Date: 2024-04-29 15:38:36 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2001-2024 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    MSDevice_Transportable.h
      15             : /// @author  Daniel Krajzewicz
      16             : /// @author  Jakob Erdmann
      17             : /// @author  Michael Behrisch
      18             : /// @author  Melanie Weber
      19             : /// @author  Andreas Kendziorra
      20             : /// @date    Fri, 30.01.2009
      21             : ///
      22             : // A device which is used to keep track of persons and containers riding with a vehicle
      23             : /****************************************************************************/
      24             : #pragma once
      25             : #include <config.h>
      26             : 
      27             : #include <vector>
      28             : #include "MSVehicleDevice.h"
      29             : #include <utils/common/SUMOTime.h>
      30             : #include <microsim/MSVehicle.h>
      31             : #include <utils/common/WrappingCommand.h>
      32             : 
      33             : 
      34             : // ===========================================================================
      35             : // class definitions
      36             : // ===========================================================================
      37             : /**
      38             :  * @class MSDevice_Transportable
      39             :  * @see MSDevice
      40             :  */
      41             : class MSDevice_Transportable : public MSVehicleDevice {
      42             : public:
      43             :     /** @brief Build devices for the given vehicle, if needed
      44             :      *
      45             :      * The built device is stored in the given vector.
      46             :      *
      47             :      * @param[in] v The vehicle for which a device may be built
      48             :      * @param[filled] into The vector to store the built device in
      49             :      */
      50             :     static MSDevice_Transportable* buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into, const bool isContainer);
      51             : 
      52             : 
      53             : public:
      54             :     /// @brief Destructor.
      55             :     ~MSDevice_Transportable();
      56             : 
      57             : 
      58             :     /// @name Methods called on vehicle movement / state change, overwriting MSDevice
      59             :     /// @{
      60             : 
      61             :     /** @brief Checks whether the vehicle is at a stop and transportable action is needed.
      62             :      * @param[in] veh The regarded vehicle
      63             :      * @param[in] oldPos Position before the move-micro-timestep.
      64             :      * @param[in] newPos Position after the move-micro-timestep.
      65             :      * @param[in] newSpeed The vehicle's current speed
      66             :      * @return false, if the vehicle is beyond the lane, true otherwise
      67             :      * @see MSMoveReminder
      68             :      * @see MSMoveReminder::notifyMove
      69             :      */
      70             :     bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
      71             : 
      72             : 
      73             :     /** @brief Adds passengers on vehicle insertion
      74             :      *
      75             :      * @param[in] veh The entering vehicle.
      76             :      * @param[in] reason how the vehicle enters the lane
      77             :      * @return Always true
      78             :      * @see MSMoveReminder::notifyEnter
      79             :      * @see MSMoveReminder::Notification
      80             :      */
      81             :     bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
      82             : 
      83             : 
      84             :     /** @brief Passengers leaving on arrival
      85             :      *
      86             :      * @param[in] veh The leaving vehicle.
      87             :      * @param[in] lastPos Position on the lane when leaving.
      88             :      * @param[in] isArrival whether the vehicle arrived at its destination
      89             :      * @param[in] isLaneChange whether the vehicle changed from the lane
      90             :      *
      91             :      * @return True if it did not leave the net.
      92             :      */
      93             :     bool notifyLeave(SUMOTrafficObject& veh, double lastPos,
      94             :                      MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
      95             :     /// @}
      96             : 
      97             : 
      98             :     /// @brief return the name for this type of device
      99           6 :     const std::string deviceName() const {
     100          12 :         return myAmContainer ? "container" : "person";
     101             :     }
     102             : 
     103             :     /// @brief try to retrieve the given parameter from this device. Throw exception for unsupported key
     104             :     std::string getParameter(const std::string& key) const;
     105             : 
     106             :     /** @brief Add a passenger
     107             :      *
     108             :      * @param[in] transportable The passenger / container to add.
     109             :      */
     110             :     void addTransportable(MSTransportable* transportable);
     111             : 
     112             :     /** @brief Remove a passenger (TraCI)
     113             :      *
     114             :      * @param[in] transportable The passenger / container to remove.
     115             :      */
     116             :     void removeTransportable(MSTransportable* transportable);
     117             : 
     118             : 
     119             :     bool anyLeavingAtStop(const MSStop& stop) const;
     120             : 
     121             :     /// @brief transfers transportables that want to continue in the other train part (without boarding/loading delays)
     122             :     void transferAtSplitOrJoin(MSBaseVehicle* otherVeh);
     123             : 
     124             :     /** @brief Saves the state of the device
     125             :      *
     126             :      * @param[in] out The OutputDevice to write the information into
     127             :      */
     128             :     void saveState(OutputDevice& out) const;
     129             : 
     130             :     /** @brief Loads the state of the device from the given description
     131             :      *
     132             :      * @param[in] attrs XML attributes describing the current state
     133             :      */
     134             :     void loadState(const SUMOSAXAttributes& attrs);
     135             : 
     136             :     /** @brief Return the number of passengers / containers
     137             :      * @return The number of stored transportables
     138             :      */
     139             :     int size() const {
     140      526151 :         return (int)myTransportables.size();
     141             :     }
     142             : 
     143             : 
     144             :     /** @brief Returns the list of transportables using this vehicle
     145             :      * @return transportables within this vehicle
     146             :      */
     147             :     const std::vector<MSTransportable*>& getTransportables() const {
     148       14280 :         return myTransportables;
     149             :     }
     150             : 
     151             :     std::vector<Position>& getUnboardingPositions() {
     152           0 :         return myUnboardingPositions;
     153             :     }
     154             : 
     155             :     /// @brief check if boardingDuration should be applied
     156             :     static bool willTransferAtJoin(const MSTransportable* t, const MSBaseVehicle* joinVeh);
     157             : 
     158             : protected:
     159             :     /** @brief Internal notification about the vehicle moves, see MSMoveReminder::notifyMoveInternal()
     160             :      *
     161             :      */
     162             :     void notifyMoveInternal(const SUMOTrafficObject& veh,
     163             :                             const double frontOnLane,
     164             :                             const double timeOnLane,
     165             :                             const double meanSpeedFrontOnLane,
     166             :                             const double meanSpeedVehicleOnLane,
     167             :                             const double travelledDistanceFrontOnLane,
     168             :                             const double travelledDistanceVehicleOnLane,
     169             :                             const double meanLengthOnLane);
     170             : 
     171             : private:
     172             :     /** @brief Constructor
     173             :      *
     174             :      * @param[in] holder The vehicle that holds this device
     175             :      * @param[in] id The ID of the device
     176             :      */
     177             :     MSDevice_Transportable(SUMOVehicle& holder, const std::string& id, const bool isContainer);
     178             : 
     179             : 
     180             : private:
     181             :     /// @brief Whether it is a container device
     182             :     const bool myAmContainer;
     183             : 
     184             :     /// @brief The passengers of the vehicle
     185             :     std::vector<MSTransportable*> myTransportables;
     186             : 
     187             :     /* @brief Whether the vehicle is at a stop and the stop is finished
     188             :      * true means, all passengers that wish to debord at the current stop have left
     189             :      */
     190             :     bool myStopped;
     191             : 
     192             :     /// @brief unboarding positions of passengers if vehicle is a train
     193             :     std::vector<Position> myUnboardingPositions;
     194             : 
     195             : 
     196             : private:
     197             :     /// @brief Invalidated copy constructor.
     198             :     MSDevice_Transportable(const MSDevice_Transportable&);
     199             : 
     200             :     /// @brief Invalidated assignment operator.
     201             :     MSDevice_Transportable& operator=(const MSDevice_Transportable&);
     202             : 
     203             : 
     204             : };

Generated by: LCOV version 1.14