SUMO - Simulation of Urban MObility
MSDevice.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // Abstract in-vehicle device
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2007-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef MSDevice_h
23 #define MSDevice_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <string>
36 #include <vector>
37 #include <map>
38 #include <set>
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 class MTRand;
52 
53 
54 // ===========================================================================
55 // class definitions
56 // ===========================================================================
71 class MSDevice : public MSMoveReminder, public Named {
72 public:
76  static void insertOptions(OptionsCont& oc);
77 
81  static bool checkOptions(OptionsCont& oc);
82 
83 
89  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into);
90 
91  static MTRand* getEquipmentRNG() {
92  return &myEquipmentRNG;
93  }
94 
96  virtual const std::string deviceName() const = 0;
97 
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);
184 
185 protected:
188 
189 private:
191  static std::map<std::string, std::set<std::string> > myExplicitIDs;
192 
195 
196 
197 private:
199  MSDevice(const MSDevice&);
200 
202  MSDevice& operator=(const MSDevice&);
203 
204 };
205 
206 
207 #endif
208 
209 /****************************************************************************/
210 
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:187
static std::map< std::string, std::set< std::string > > myExplicitIDs
vehicles which explicitly carry a device, sorted by device, first
Definition: MSDevice.h:191
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
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:38
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice *> &into)
Build devices for the given vehicle, if needed.
Definition: MSDevice.cpp:79
virtual const std::string deviceName() const =0
return the name for this type of device
Representation of a vehicle.
Definition: SUMOVehicle.h:67
Encapsulated SAX-Attributes.
virtual void saveState(OutputDevice &out) const
Saves the state of the device.
Definition: MSDevice.cpp:143
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:93
Something on a lane to be noticed about vehicle movement.
Base class for objects which have an id.
Definition: Named.h:46
static bool checkOptions(OptionsCont &oc)
check device-specific options
Definition: MSDevice.cpp:71
Abstract in-vehicle device.
Definition: MSDevice.h:71
static MTRand myEquipmentRNG
A random number generator used to choose from vtype/route distributions and computing the speed facto...
Definition: MSDevice.h:194
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.cpp:107
virtual void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
Definition: MSDevice.cpp:149
A storage for options typed value containers)
Definition: OptionsCont.h:99
static void insertOptions(OptionsCont &oc)
Inserts options for building devices.
Definition: MSDevice.cpp:59
static MTRand * getEquipmentRNG()
Definition: MSDevice.h:91
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
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