SUMO - Simulation of Urban MObility
MSDetectorFileOutput.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-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 /****************************************************************************/
18 // Base of value-generating classes (detectors)
19 /****************************************************************************/
20 #ifndef MSDetectorFileOutput_h
21 #define MSDetectorFileOutput_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <string>
30 #include <set>
31 
32 #include <utils/common/Named.h>
33 #include <utils/common/SUMOTime.h>
37 #include <microsim/MSVehicleType.h>
39 #include <microsim/MSNet.h>
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class GUIDetectorWrapper;
46 
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
55 };
56 
64 class MSDetectorFileOutput : public Named {
65 public:
67  MSDetectorFileOutput(const std::string& id, const std::string& vTypes)
68  : Named(id) {
69  const std::vector<std::string> vt = StringTokenizer(vTypes).getVector();
70  myVehicleTypes.insert(vt.begin(), vt.end());
71  }
72 
74  MSDetectorFileOutput(const std::string& id, const std::set<std::string>& vTypes)
75  : Named(id), myVehicleTypes(vTypes) {
76  }
77 
78 
80  virtual ~MSDetectorFileOutput() { }
81 
82 
85 
92  virtual void writeXMLOutput(OutputDevice& dev,
93  SUMOTime startTime, SUMOTime stopTime) = 0;
94 
95 
104  virtual void writeXMLDetectorProlog(OutputDevice& dev) const = 0;
105 
106 
114  virtual void reset() { }
115 
116 
121  virtual void detectorUpdate(const SUMOTime step) {
122  UNUSED_PARAMETER(step);
123  }
124 
125 
132  return 0;
133  }
134 
135 
141  bool vehicleApplies(const SUMOVehicle& veh) const {
142  if (myVehicleTypes.empty() || myVehicleTypes.count(veh.getVehicleType().getID()) > 0) {
143  return true;
144  } else {
145  std::set<std::string> vTypeDists = MSNet::getInstance()->getVehicleControl().getVTypeDistributionMembership(veh.getVehicleType().getID());
146  for (auto vTypeDist : vTypeDists) {
147  if (myVehicleTypes.count(vTypeDist) > 0) {
148  return true;
149  }
150  }
151  return false;
152  }
153  }
154 
155 
160  bool isTyped() const {
161  return !myVehicleTypes.empty();
162  }
163 
164 
165 protected:
167  std::set<std::string> myVehicleTypes;
168 
169 private:
172 
175 
176 
177 };
178 
179 
180 #endif
181 
182 /****************************************************************************/
183 
long long int SUMOTime
Definition: SUMOTime.h:36
bool vehicleApplies(const SUMOVehicle &veh) const
Checks whether the detector measures vehicles of the given type.
virtual void reset()
Resets collected values.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:165
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:33
virtual void detectorUpdate(const SUMOTime step)
Updates the detector (computes values)
virtual void writeXMLDetectorProlog(OutputDevice &dev) const =0
Open the XML-output.
std::set< std::string > getVTypeDistributionMembership(const std::string &id) const
Return the distribution IDs the vehicle type is a member of.
MSDetectorFileOutput(const std::string &id, const std::string &vTypes)
Constructor.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
MSDetectorFileOutput & operator=(const MSDetectorFileOutput &)
Invalidated assignment operator.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:316
virtual ~MSDetectorFileOutput()
(virtual) destructor
std::set< std::string > myVehicleTypes
The vehicle types to look for (empty means all)
MSDetectorFileOutput(const std::string &id, const std::set< std::string > &vTypes)
Constructor.
Base class for objects which have an id.
Definition: Named.h:58
std::vector< std::string > getVector()
bool isTyped() const
Checks whether the detector is type specific.
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
virtual void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)=0
Write the generated output to the given device.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Builds the graphical representation.
Base of value-generating classes (detectors)
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.