SUMO - Simulation of Urban MObility
MSDevice.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2007-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Abstract in-vehicle device
18 /****************************************************************************/
19 #ifndef MSDevice_h
20 #define MSDevice_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <string>
29 #include <vector>
30 #include <map>
31 #include <set>
32 #include <random>
34 #include <utils/common/Named.h>
36 
37 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
41 class OutputDevice;
42 class SUMOVehicle;
43 class MSTransportable;
44 class OptionsCont;
45 class SUMOSAXAttributes;
46 
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
65 class MSDevice : public MSMoveReminder, public Named {
66 public:
70  static void insertOptions(OptionsCont& oc);
71 
75  static bool checkOptions(OptionsCont& oc);
76 
77 
83  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into);
84 
85  static std::mt19937* getEquipmentRNG() {
86  return &myEquipmentRNG;
87  }
88 
90  virtual const std::string deviceName() const = 0;
91 
94  static bool equippedByParameter(const MSTransportable* t, const std::string& deviceName, bool outputOptionSet);
95 
97  static void cleanupAll();
98 
99 public:
105  MSDevice(SUMOVehicle& holder, const std::string& id) :
106  MSMoveReminder(id), Named(id), myHolder(holder) {
107  }
108 
109 
111  virtual ~MSDevice() { }
112 
113 
119  return myHolder;
120  }
121 
122 
134  virtual void generateOutput() const {
135  }
136 
142  virtual void saveState(OutputDevice& out) const;
143 
144 
150  virtual void loadState(const SUMOSAXAttributes& attrs);
151 
153  virtual std::string getParameter(const std::string& key) const {
154  throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
155  }
156 
158  virtual void setParameter(const std::string& key, const std::string& value) {
159  UNUSED_PARAMETER(value);
160  throw InvalidArgument("Setting parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
161  }
162 
163 protected:
166 
173  static void insertDefaultAssignmentOptions(const std::string& deviceName, const std::string& optionsTopic, OptionsCont& oc);
174 
175 
182  static bool equippedByDefaultAssignmentOptions(const OptionsCont& oc, const std::string& deviceName, SUMOVehicle& v, bool outputOptionSet);
184 
185 
188  static std::string getStringParam(const SUMOVehicle& v, const OptionsCont& oc, std::string paramName, std::string deflt, bool required);
189  static double getFloatParam(const SUMOVehicle& v, const OptionsCont& oc, std::string paramName, double deflt, bool required);
190  static bool getBoolParam(const SUMOVehicle& v, const OptionsCont& oc, std::string paramName, bool deflt, bool required);
192 
193 protected:
196 
197 private:
199  static std::map<std::string, std::set<std::string> > myExplicitIDs;
200 
202  static std::mt19937 myEquipmentRNG;
203 
204 
205 private:
207  MSDevice(const MSDevice&);
208 
210  MSDevice& operator=(const MSDevice&);
211 
212 };
213 
214 
215 #endif
216 
217 /****************************************************************************/
218 
static bool getBoolParam(const SUMOVehicle &v, const OptionsCont &oc, std::string paramName, bool deflt, bool required)
Definition: MSDevice.cpp:264
virtual void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this device. Throw exception for unsupported key ...
Definition: MSDevice.h:158
virtual ~MSDevice()
Destructor.
Definition: MSDevice.h:111
SUMOVehicle & myHolder
The vehicle that stores the device.
Definition: MSDevice.h:195
static std::map< std::string, std::set< std::string > > myExplicitIDs
vehicles which explicitly carry a device, sorted by device, first
Definition: MSDevice.h:199
virtual std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key ...
Definition: MSDevice.h:153
virtual void generateOutput() const
Called on writing tripinfo output.
Definition: MSDevice.h:134
static std::mt19937 * getEquipmentRNG()
Definition: MSDevice.h:85
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:33
static bool equippedByParameter(const MSTransportable *t, const std::string &deviceName, bool outputOptionSet)
Determines whether a transportable should get a certain device.
Definition: MSDevice.cpp:175
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice *> &into)
Build devices for the given vehicle, if needed.
Definition: MSDevice.cpp:88
virtual const std::string deviceName() const =0
return the name for this type of device
Representation of a vehicle.
Definition: SUMOVehicle.h:60
Encapsulated SAX-Attributes.
virtual void saveState(OutputDevice &out) const
Saves the state of the device.
Definition: MSDevice.cpp:187
static std::mt19937 myEquipmentRNG
A random number generator used to choose from vtype/route distributions and computing the speed facto...
Definition: MSDevice.h:202
static double getFloatParam(const SUMOVehicle &v, const OptionsCont &oc, std::string paramName, double deflt, bool required)
Definition: MSDevice.cpp:231
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc)
Adds common command options that allow to assign devices to vehicles.
Definition: MSDevice.cpp:112
Something on a lane to be noticed about vehicle movement.
static void cleanupAll()
perform cleanup for all devices
Definition: MSDevice.cpp:105
Base class for objects which have an id.
Definition: Named.h:49
static bool checkOptions(OptionsCont &oc)
check device-specific options
Definition: MSDevice.cpp:80
Abstract in-vehicle device.
Definition: MSDevice.h:65
virtual void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
Definition: MSDevice.cpp:193
static std::string getStringParam(const SUMOVehicle &v, const OptionsCont &oc, std::string paramName, std::string deflt, bool required)
Definition: MSDevice.cpp:198
A storage for options typed value containers)
Definition: OptionsCont.h:92
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v, bool outputOptionSet)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.cpp:126
static void insertOptions(OptionsCont &oc)
Inserts options for building devices.
Definition: MSDevice.cpp:64
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
MSDevice & operator=(const MSDevice &)
Invalidated assignment operator.
MSDevice(SUMOVehicle &holder, const std::string &id)
Constructor.
Definition: MSDevice.h:105
SUMOVehicle & getHolder() const
Returns the vehicle that holds this device.
Definition: MSDevice.h:118