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-2022 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 #include <config.h>
22 
23 #include <string>
24 #include <map>
25 #include <stack>
26 #include <sstream>
27 #include <vector>
28 #include <iostream>
29 #include <xercesc/sax2/Attributes.hpp>
30 #include <xercesc/sax2/DefaultHandler.hpp>
31 #include "EngineParameters.h"
32 
33 //definition of tag names of the xml file
34 #define ENGINE_TAG_VEHICLES "vehicles"
35 #define ENGINE_TAG_VEHICLE "vehicle"
36 #define ENGINE_TAG_VEHICLE_ID "id"
37 #define ENGINE_TAG_VEHICLE_DESCRIPTION "description"
38 #define ENGINE_TAG_GEARS "gears"
39 #define ENGINE_TAG_GEAR "gear"
40 #define ENGINE_TAG_GEAR_N "n"
41 #define ENGINE_TAG_GEAR_RATIO "ratio"
42 #define ENGINE_TAG_GEAR_DIFFERENTIAL "differential"
43 #define ENGINE_TAG_MASS "mass"
44 #define ENGINE_TAG_MASS_MASS "mass"
45 #define ENGINE_TAG_MASS_FACTOR "massFactor"
46 #define ENGINE_TAG_WHEELS "wheels"
47 #define ENGINE_TAG_WHEELS_DIAMETER "diameter"
48 #define ENGINE_TAG_WHEELS_FRICTION "friction"
49 #define ENGINE_TAG_WHEELS_CR1 "cr1"
50 #define ENGINE_TAG_WHEELS_CR2 "cr2"
51 #define ENGINE_TAG_DRAG "drag"
52 #define ENGINE_TAG_DRAG_CAIR "cAir"
53 #define ENGINE_TAG_DRAG_SECTION "section"
54 #define ENGINE_TAG_ENGINE "engine"
55 #define ENGINE_TAG_ENGINE_TYPE "type"
56 #define ENGINE_TAG_ENGINE_EFFICIENCY "efficiency"
57 #define ENGINE_TAG_ENGINE_CYLINDERS "cylinders"
58 #define ENGINE_TAG_ENGINE_MINRPM "minRpm"
59 #define ENGINE_TAG_ENGINE_MAXRPM "maxRpm"
60 #define ENGINE_TAG_ENGINE_TAU_EX "tauEx"
61 #define ENGINE_TAG_ENGINE_TAU_BURN "tauBurn"
62 #define ENGINE_TAG_ENGINE_POWER "power"
63 #define ENGINE_TAG_ENGINE_POWER_RPM "rpm"
64 #define ENGINE_TAG_ENGINE_POWER_HP "hp"
65 #define ENGINE_TAG_ENGINE_POWER_KW "kw"
66 #define ENGINE_TAG_ENGINE_POWER_SLOPE "slope"
67 #define ENGINE_TAG_ENGINE_POWER_INTERCEPT "intercept"
68 #define ENGINE_TAG_SHIFTING "shifting"
69 #define ENGINE_TAG_SHIFTING_RPM "rpm"
70 #define ENGINE_TAG_SHIFTING_DELTARPM "deltaRpm"
71 #define ENGINE_TAG_BRAKES "brakes"
72 #define ENGINE_TAG_BRAKES_TAU "tau"
73 
74 #define TAG_VEHICLES 0
75 #define TAG_VEHICLE 1
76 #define TAG_GEARS 2
77 #define TAG_ENGINE 3
78 
79 // ===========================================================================
80 // class definitions
81 // ===========================================================================
85 class VehicleEngineHandler : public XERCES_CPP_NAMESPACE::DefaultHandler {
86 
87 public:
88 
94  VehicleEngineHandler(const std::string& toLoad);
95 
96 
98  virtual ~VehicleEngineHandler();
99 
100  void startElement(const XMLCh* const uri, const XMLCh* const localname,
101  const XMLCh* const qname, const XERCES_CPP_NAMESPACE::Attributes& attrs);
102 
103  void endElement(const XMLCh* const uri, const XMLCh* const localname,
104  const XMLCh* const qname);
105 
106  void endDocument();
107 
109 
110 protected:
111 
116  void loadMassData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
117  \
122  void loadDragData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
127  void loadWheelsData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
131  void loadEngineData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
135  void loadGearData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
139  void loadDifferentialData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
144  void loadEngineModelData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
148  void loadShiftingData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
152  void loadBrakesData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
153 
159  int existsAttribute(std::string tag, const char* attribute, const XERCES_CPP_NAMESPACE::Attributes& attrs);
164  std::string parseStringAttribute(std::string tag, const char* attribute, const XERCES_CPP_NAMESPACE::Attributes& attrs);
170  int parseIntAttribute(std::string tag, const char* attribute, const XERCES_CPP_NAMESPACE::Attributes& attrs);
176  double parseDoubleAttribute(std::string tag, const char* attribute, const XERCES_CPP_NAMESPACE::Attributes& attrs);
182  double parsePolynomialCoefficient(int index, const XERCES_CPP_NAMESPACE::Attributes& attrs);
186  void raiseMissingAttributeError(std::string tag, std::string attribute);
190  void raiseUnknownTagError(std::string tag);
191 
192 
193 private:
194 
195  //current tag we're into
197  //vehicle type to load
198  std::string vehicleToLoad;
199  //skip loading of current vehicle data
200  bool skip;
201  //current loaded gear
203  //where to store loaded data
205  //vector of gear ratios
206  std::vector<double> gearRatios;
207 
208 private:
211 
214 
215 };
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