Eclipse SUMO - Simulation of Urban MObility
VehicleEngineHandler.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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 /****************************************************************************/
19 
20 #pragma once
21 
22 #include <string>
23 #include <map>
24 #include <stack>
25 #include <sstream>
26 #include <vector>
27 #include <iostream>
28 #include <xercesc/sax2/Attributes.hpp>
29 #include <xercesc/sax2/DefaultHandler.hpp>
30 #include "EngineParameters.h"
31 
32 //definition of tag names of the xml file
33 #define ENGINE_TAG_VEHICLES "vehicles"
34 #define ENGINE_TAG_VEHICLE "vehicle"
35 #define ENGINE_TAG_VEHICLE_ID "id"
36 #define ENGINE_TAG_VEHICLE_DESCRIPTION "description"
37 #define ENGINE_TAG_GEARS "gears"
38 #define ENGINE_TAG_GEAR "gear"
39 #define ENGINE_TAG_GEAR_N "n"
40 #define ENGINE_TAG_GEAR_RATIO "ratio"
41 #define ENGINE_TAG_GEAR_DIFFERENTIAL "differential"
42 #define ENGINE_TAG_MASS "mass"
43 #define ENGINE_TAG_MASS_MASS "mass"
44 #define ENGINE_TAG_MASS_FACTOR "massFactor"
45 #define ENGINE_TAG_WHEELS "wheels"
46 #define ENGINE_TAG_WHEELS_DIAMETER "diameter"
47 #define ENGINE_TAG_WHEELS_FRICTION "friction"
48 #define ENGINE_TAG_WHEELS_CR1 "cr1"
49 #define ENGINE_TAG_WHEELS_CR2 "cr2"
50 #define ENGINE_TAG_DRAG "drag"
51 #define ENGINE_TAG_DRAG_CAIR "cAir"
52 #define ENGINE_TAG_DRAG_SECTION "section"
53 #define ENGINE_TAG_ENGINE "engine"
54 #define ENGINE_TAG_ENGINE_TYPE "type"
55 #define ENGINE_TAG_ENGINE_EFFICIENCY "efficiency"
56 #define ENGINE_TAG_ENGINE_CYLINDERS "cylinders"
57 #define ENGINE_TAG_ENGINE_MINRPM "minRpm"
58 #define ENGINE_TAG_ENGINE_MAXRPM "maxRpm"
59 #define ENGINE_TAG_ENGINE_TAU_EX "tauEx"
60 #define ENGINE_TAG_ENGINE_TAU_BURN "tauBurn"
61 #define ENGINE_TAG_ENGINE_POWER "power"
62 #define ENGINE_TAG_ENGINE_POWER_RPM "rpm"
63 #define ENGINE_TAG_ENGINE_POWER_HP "hp"
64 #define ENGINE_TAG_ENGINE_POWER_KW "kw"
65 #define ENGINE_TAG_ENGINE_POWER_SLOPE "slope"
66 #define ENGINE_TAG_ENGINE_POWER_INTERCEPT "intercept"
67 #define ENGINE_TAG_SHIFTING "shifting"
68 #define ENGINE_TAG_SHIFTING_RPM "rpm"
69 #define ENGINE_TAG_SHIFTING_DELTARPM "deltaRpm"
70 #define ENGINE_TAG_BRAKES "brakes"
71 #define ENGINE_TAG_BRAKES_TAU "tau"
72 
73 #define TAG_VEHICLES 0
74 #define TAG_VEHICLE 1
75 #define TAG_GEARS 2
76 #define TAG_ENGINE 3
77 
78 // ===========================================================================
79 // class definitions
80 // ===========================================================================
84 class VehicleEngineHandler : public XERCES_CPP_NAMESPACE::DefaultHandler {
85 
86 public:
87 
93  VehicleEngineHandler(const std::string& toLoad);
94 
95 
97  virtual ~VehicleEngineHandler();
98 
99  void startElement(const XMLCh* const uri, const XMLCh* const localname,
100  const XMLCh* const qname, const XERCES_CPP_NAMESPACE::Attributes& attrs);
101 
102  void endElement(const XMLCh* const uri, const XMLCh* const localname,
103  const XMLCh* const qname);
104 
105  void endDocument();
106 
108 
109 protected:
110 
115  void loadMassData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
116  \
121  void loadDragData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
126  void loadWheelsData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
130  void loadEngineData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
134  void loadGearData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
138  void loadDifferentialData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
143  void loadEngineModelData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
147  void loadShiftingData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
151  void loadBrakesData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
152 
158  int existsAttribute(std::string tag, const char* attribute, const XERCES_CPP_NAMESPACE::Attributes& attrs);
163  std::string parseStringAttribute(std::string tag, const char* attribute, const XERCES_CPP_NAMESPACE::Attributes& attrs);
169  int parseIntAttribute(std::string tag, const char* attribute, const XERCES_CPP_NAMESPACE::Attributes& attrs);
175  double parseDoubleAttribute(std::string tag, const char* attribute, const XERCES_CPP_NAMESPACE::Attributes& attrs);
181  double parsePolynomialCoefficient(int index, const XERCES_CPP_NAMESPACE::Attributes& attrs);
185  void raiseMissingAttributeError(std::string tag, std::string attribute);
189  void raiseUnknownTagError(std::string tag);
190 
191 
192 private:
193 
194  //current tag we're into
196  //vehicle type to load
197  std::string vehicleToLoad;
198  //skip loading of current vehicle data
199  bool skip;
200  //current loaded gear
202  //where to store loaded data
204  //vector of gear ratios
205  std::vector<double> gearRatios;
206 
207 private:
210 
213 
214 };
const EngineParameters & getEngineParameters()
std::string parseStringAttribute(std::string tag, const char *attribute, const XERCES_CPP_NAMESPACE::Attributes &attrs)
virtual ~VehicleEngineHandler()
Destructor.
std::vector< double > gearRatios
void loadEngineModelData(const XERCES_CPP_NAMESPACE::Attributes &attrs)
EngineParameters engineParameters
void loadDifferentialData(const XERCES_CPP_NAMESPACE::Attributes &attrs)
void loadGearData(const XERCES_CPP_NAMESPACE::Attributes &attrs)
VehicleEngineHandler(const std::string &toLoad)
double parsePolynomialCoefficient(int index, const XERCES_CPP_NAMESPACE::Attributes &attrs)
int parseIntAttribute(std::string tag, const char *attribute, const XERCES_CPP_NAMESPACE::Attributes &attrs)
void loadShiftingData(const XERCES_CPP_NAMESPACE::Attributes &attrs)
void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const XERCES_CPP_NAMESPACE::Attributes &attrs)
void loadWheelsData(const XERCES_CPP_NAMESPACE::Attributes &attrs)
void loadMassData(const XERCES_CPP_NAMESPACE::Attributes &attrs)
int existsAttribute(std::string tag, const char *attribute, const XERCES_CPP_NAMESPACE::Attributes &attrs)
void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
void loadEngineData(const XERCES_CPP_NAMESPACE::Attributes &attrs)
void loadBrakesData(const XERCES_CPP_NAMESPACE::Attributes &attrs)
void raiseUnknownTagError(std::string tag)
double parseDoubleAttribute(std::string tag, const char *attribute, const XERCES_CPP_NAMESPACE::Attributes &attrs)
const VehicleEngineHandler & operator=(const VehicleEngineHandler &s)
invalidated assignment operator
void raiseMissingAttributeError(std::string tag, std::string attribute)
void loadDragData(const XERCES_CPP_NAMESPACE::Attributes &attrs)
VehicleEngineHandler(const VehicleEngineHandler &s)
invalidated copy constructor