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-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 /****************************************************************************/
20 // Base of value-generating classes (detectors)
21 /****************************************************************************/
22 #ifndef MSDetectorFileOutput_h
23 #define MSDetectorFileOutput_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 <set>
37 
38 #include <utils/common/Named.h>
39 #include <utils/common/SUMOTime.h>
43 #include <microsim/MSVehicleType.h>
44 
45 
46 // ===========================================================================
47 // class declarations
48 // ===========================================================================
49 class GUIDetectorWrapper;
50 
51 
52 // ===========================================================================
53 // class definitions
54 // ===========================================================================
59 };
60 
68 class MSDetectorFileOutput : public Named {
69 public:
71  MSDetectorFileOutput(const std::string& id, const std::string& vTypes)
72  : Named(id) {
73  const std::vector<std::string> vt = StringTokenizer(vTypes).getVector();
74  myVehicleTypes.insert(vt.begin(), vt.end());
75  }
76 
78  MSDetectorFileOutput(const std::string& id, const std::set<std::string>& vTypes)
79  : Named(id), myVehicleTypes(vTypes) {
80  }
81 
82 
84  virtual ~MSDetectorFileOutput() { }
85 
86 
89 
96  virtual void writeXMLOutput(OutputDevice& dev,
97  SUMOTime startTime, SUMOTime stopTime) = 0;
98 
99 
108  virtual void writeXMLDetectorProlog(OutputDevice& dev) const = 0;
109 
110 
118  virtual void reset() { }
119 
120 
125  virtual void detectorUpdate(const SUMOTime step) {
126  UNUSED_PARAMETER(step);
127  }
128 
129 
136  return 0;
137  }
138 
139 
145  bool vehicleApplies(const SUMOVehicle& veh) const {
146  return myVehicleTypes.empty() || myVehicleTypes.count(veh.getVehicleType().getID()) > 0;
147  }
148 
149 
154  bool isTyped() const {
155  return !myVehicleTypes.empty();
156  }
157 
158 
159 protected:
161  std::set<std::string> myVehicleTypes;
162 
163 private:
166 
169 
170 
171 };
172 
173 
174 #endif
175 
176 /****************************************************************************/
177 
bool vehicleApplies(const SUMOVehicle &veh) const
Checks whether the detector measures vehicles of the given type.
virtual void reset()
Resets collected values.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
virtual void detectorUpdate(const SUMOTime step)
Updates the detector (computes values)
virtual void writeXMLDetectorProlog(OutputDevice &dev) const =0
Open the XML-output.
MSDetectorFileOutput(const std::string &id, const std::string &vTypes)
Constructor.
Representation of a vehicle.
Definition: SUMOVehicle.h:66
MSDetectorFileOutput & operator=(const MSDetectorFileOutput &)
Invalidated assignment operator.
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:54
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.
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:70
long long int SUMOTime
Definition: TraCIDefs.h:51
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.