Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2007-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 MSVehicleDevice.h
15 : /// @author Michael Behrisch
16 : /// @author Daniel Krajzewicz
17 : /// @author Jakob Erdmann
18 : /// @date Tue, 04 Dec 2007
19 : ///
20 : // Abstract in-vehicle device
21 : /****************************************************************************/
22 : #pragma once
23 : #include <config.h>
24 :
25 : #include <string>
26 : #include <vector>
27 : #include <map>
28 : #include <set>
29 : #include <random>
30 : #include <utils/vehicle/SUMOVehicle.h>
31 : #include <microsim/MSMoveReminder.h>
32 : #include "MSDevice.h"
33 :
34 :
35 : // ===========================================================================
36 : // class definitions
37 : // ===========================================================================
38 : /**
39 : * @class MSVehicleDevice
40 : * @brief Abstract in-vehicle device
41 : *
42 : * The MSVehicleDevice-interface brings the following interfaces to a vehicle that
43 : * may be overwritten by real devices:
44 : * @arg Retrieval of the vehicle that holds the device
45 : * @arg Building and retrieval of a device id
46 : * @arg Methods called on vehicle movement / state change
47 : *
48 : * The "methods called on vehicle movement / state change" are called for each
49 : * device within the corresponding vehicle methods. MSVehicleDevice brings already
50 : * an empty (nothing doing) implementation of these.
51 : */
52 : class MSVehicleDevice : public MSMoveReminder, public MSDevice {
53 : public:
54 : /** @brief Constructor
55 : *
56 : * @param[in] holder The vehicle that holds this device
57 : * @param[in] id The ID of the device
58 : */
59 4566639 : MSVehicleDevice(SUMOVehicle& holder, const std::string& id) :
60 4566639 : MSMoveReminder(id), MSDevice(id), myHolder(holder) {
61 4566639 : }
62 :
63 :
64 : /// @brief Destructor
65 4565727 : virtual ~MSVehicleDevice() { }
66 :
67 :
68 : /** @brief Returns the vehicle that holds this device
69 : *
70 : * @return The vehicle that holds this device
71 : */
72 : inline SUMOVehicle& getHolder() const {
73 259105 : return myHolder;
74 : }
75 :
76 : inline SUMOVehicle::NumericalID getNumericalID() const {
77 59636519 : return myHolder.getNumericalID();
78 : }
79 :
80 : /// @brief Function-object for stable sorting of objects with numerical ids
81 : struct ComparatorNumericalVehicleIdLess {
82 : bool operator()(const MSVehicleDevice* const a, const MSVehicleDevice* const b) const {
83 5224 : return a->myHolder.getNumericalID() < b->myHolder.getNumericalID();
84 : }
85 : };
86 :
87 :
88 : protected:
89 : /// @brief The vehicle that stores the device
90 : SUMOVehicle& myHolder;
91 :
92 : private:
93 : /// @brief Invalidated copy constructor.
94 : MSVehicleDevice(const MSVehicleDevice&);
95 :
96 : /// @brief Invalidated assignment operator.
97 : MSVehicleDevice& operator=(const MSVehicleDevice&);
98 :
99 : };
|