Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2013-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_Example.h 15 : /// @author Daniel Krajzewicz 16 : /// @author Jakob Erdmann 17 : /// @date 11.06.2013 18 : /// 19 : // A device which stands as an implementation example and which outputs movereminder calls 20 : /****************************************************************************/ 21 : #pragma once 22 : #include <config.h> 23 : 24 : #include "MSVehicleDevice.h" 25 : #include <utils/common/SUMOTime.h> 26 : 27 : 28 : // =========================================================================== 29 : // class declarations 30 : // =========================================================================== 31 : class SUMOTrafficObject; 32 : 33 : 34 : // =========================================================================== 35 : // class definitions 36 : // =========================================================================== 37 : /** 38 : * @class MSDevice_Example 39 : * @brief A device which collects info on the vehicle trip (mainly on departure and arrival) 40 : * 41 : * Each device collects departure time, lane and speed and the same for arrival. 42 : * 43 : * @see MSDevice 44 : */ 45 : class MSDevice_Example : public MSVehicleDevice { 46 : public: 47 : /** @brief Inserts MSDevice_Example-options 48 : * @param[filled] oc The options container to add the options to 49 : */ 50 : static void insertOptions(OptionsCont& oc); 51 : 52 : 53 : /** @brief Build devices for the given vehicle, if needed 54 : * 55 : * The options are read and evaluated whether a example-device shall be built 56 : * for the given vehicle. 57 : * 58 : * The built device is stored in the given vector. 59 : * 60 : * @param[in] v The vehicle for which a device may be built 61 : * @param[filled] into The vector to store the built device in 62 : */ 63 : static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into); 64 : 65 : /// @brief resets counters 66 : static void cleanup(); 67 : 68 : public: 69 : /// @brief Destructor. 70 : ~MSDevice_Example(); 71 : 72 : 73 : 74 : /// @name Methods called on vehicle movement / state change, overwriting MSDevice 75 : /// @{ 76 : 77 : /** @brief Checks for waiting steps when the vehicle moves 78 : * 79 : * @param[in] veh Vehicle that asks this reminder. 80 : * @param[in] oldPos Position before move. 81 : * @param[in] newPos Position after move with newSpeed. 82 : * @param[in] newSpeed Moving speed. 83 : * 84 : * @return True (always). 85 : */ 86 : bool notifyMove(SUMOTrafficObject& veh, double oldPos, 87 : double newPos, double newSpeed); 88 : 89 : 90 : /** @brief Saves departure info on insertion 91 : * 92 : * @param[in] veh The entering vehicle. 93 : * @param[in] reason how the vehicle enters the lane 94 : * @return Always true 95 : * @see MSMoveReminder::notifyEnter 96 : * @see MSMoveReminder::Notification 97 : */ 98 : bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0); 99 : 100 : 101 : /** @brief Saves arrival info 102 : * 103 : * @param[in] veh The leaving vehicle. 104 : * @param[in] lastPos Position on the lane when leaving. 105 : * @param[in] isArrival whether the vehicle arrived at its destination 106 : * @param[in] isLaneChange whether the vehicle changed from the lane 107 : * @return True if it did not leave the net. 108 : */ 109 : bool notifyLeave(SUMOTrafficObject& veh, double lastPos, 110 : MSMoveReminder::Notification reason, const MSLane* enteredLane = 0); 111 : /// @} 112 : 113 : 114 : /// @brief return the name for this type of device 115 0 : const std::string deviceName() const { 116 0 : return "example"; 117 : } 118 : 119 : /// @brief try to retrieve the given parameter from this device. Throw exception for unsupported key 120 : std::string getParameter(const std::string& key) const; 121 : 122 : /// @brief try to set the given parameter for this device. Throw exception for unsupported key 123 : void setParameter(const std::string& key, const std::string& value); 124 : 125 : /** @brief Called on writing tripinfo output 126 : * 127 : * @param[in] os The stream to write the information into 128 : * @exception IOError not yet implemented 129 : * @see MSDevice::generateOutput 130 : */ 131 : void generateOutput(OutputDevice* tripinfoOut) const; 132 : 133 : 134 : 135 : private: 136 : /** @brief Constructor 137 : * 138 : * @param[in] holder The vehicle that holds this device 139 : * @param[in] id The ID of the device 140 : */ 141 : MSDevice_Example(SUMOVehicle& holder, const std::string& id, double customValue1, 142 : double customValue2, double customValue3); 143 : 144 : 145 : 146 : private: 147 : // private state members of the Example device 148 : 149 : /// @brief a value which is initialised based on a commandline/configuration option 150 : double myCustomValue1; 151 : 152 : /// @brief a value which is initialised based on a vehicle parameter 153 : double myCustomValue2; 154 : 155 : /// @brief a value which is initialised based on a vType parameter 156 : double myCustomValue3; 157 : 158 : 159 : 160 : private: 161 : /// @brief Invalidated copy constructor. 162 : MSDevice_Example(const MSDevice_Example&); 163 : 164 : /// @brief Invalidated assignment operator. 165 : MSDevice_Example& operator=(const MSDevice_Example&); 166 : 167 : 168 : };