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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Abstract in-vehicle device
20 /****************************************************************************/
21 #ifndef MSDevice_h
22 #define MSDevice_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <vector>
36 #include <map>
37 #include <set>
38 #include <random>
40 #include <utils/common/Named.h>
42 
43 
44 // ===========================================================================
45 // class declarations
46 // ===========================================================================
47 class OutputDevice;
48 class SUMOVehicle;
49 class OptionsCont;
50 class SUMOSAXAttributes;
51 
52 
53 // ===========================================================================
54 // class definitions
55 // ===========================================================================
70 class MSDevice : public MSMoveReminder, public Named {
71 public:
75  static void insertOptions(OptionsCont& oc);
76 
80  static bool checkOptions(OptionsCont& oc);
81 
82 
88  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into);
89 
90  static std::mt19937* getEquipmentRNG() {
91  return &myEquipmentRNG;
92  }
93 
95  virtual const std::string deviceName() const = 0;
96 
98  static void cleanupAll();
99 
100 public:
106  MSDevice(SUMOVehicle& holder, const std::string& id) :
107  MSMoveReminder(id), Named(id), myHolder(holder) {
108  }
109 
110 
112  virtual ~MSDevice() { }
113 
114 
120  return myHolder;
121  }
122 
123 
135  virtual void generateOutput() const {
136  }
137 
143  virtual void saveState(OutputDevice& out) const;
144 
145 
151  virtual void loadState(const SUMOSAXAttributes& attrs);
152 
154  virtual std::string getParameter(const std::string& key) const {
155  throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
156  }
157 
159  virtual void setParameter(const std::string& key, const std::string& value) {
160  UNUSED_PARAMETER(value);
161  throw InvalidArgument("Setting parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
162  }
163 
164 protected:
167 
174  static void insertDefaultAssignmentOptions(const std::string& deviceName, const std::string& optionsTopic, OptionsCont& oc);
175 
176 
183  static bool equippedByDefaultAssignmentOptions(const OptionsCont& oc, const std::string& deviceName, SUMOVehicle& v);
185 
186 protected:
189 
190 private:
192  static std::map<std::string, std::set<std::string> > myExplicitIDs;
193 
195  static std::mt19937 myEquipmentRNG;
196 
197 
198 private:
200  MSDevice(const MSDevice&);
201 
203  MSDevice& operator=(const MSDevice&);
204 
205 };
206 
207 
208 #endif
209 
210 /****************************************************************************/
211 
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:159
virtual ~MSDevice()
Destructor.
Definition: MSDevice.h:112
SUMOVehicle & myHolder
The vehicle that stores the device.
Definition: MSDevice.h:188
static std::map< std::string, std::set< std::string > > myExplicitIDs
vehicles which explicitly carry a device, sorted by device, first
Definition: MSDevice.h:192
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:154
virtual void generateOutput() const
Called on writing tripinfo output.
Definition: MSDevice.h:135
static std::mt19937 * getEquipmentRNG()
Definition: MSDevice.h:90
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice *> &into)
Build devices for the given vehicle, if needed.
Definition: MSDevice.cpp:81
virtual const std::string deviceName() const =0
return the name for this type of device
Representation of a vehicle.
Definition: SUMOVehicle.h:66
Encapsulated SAX-Attributes.
virtual void saveState(OutputDevice &out) const
Saves the state of the device.
Definition: MSDevice.cpp:151
static std::mt19937 myEquipmentRNG
A random number generator used to choose from vtype/route distributions and computing the speed facto...
Definition: MSDevice.h:195
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:101
Something on a lane to be noticed about vehicle movement.
static void cleanupAll()
perform cleanup for all devices
Definition: MSDevice.cpp:95
Base class for objects which have an id.
Definition: Named.h:45
static bool checkOptions(OptionsCont &oc)
check device-specific options
Definition: MSDevice.cpp:73
Abstract in-vehicle device.
Definition: MSDevice.h:70
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.cpp:115
virtual void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
Definition: MSDevice.cpp:157
A storage for options typed value containers)
Definition: OptionsCont.h:98
static void insertOptions(OptionsCont &oc)
Inserts options for building devices.
Definition: MSDevice.cpp:60
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
MSDevice & operator=(const MSDevice &)
Invalidated assignment operator.
MSDevice(SUMOVehicle &holder, const std::string &id)
Constructor.
Definition: MSDevice.h:106
SUMOVehicle & getHolder() const
Returns the vehicle that holds this device.
Definition: MSDevice.h:119