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-2019 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 /****************************************************************************/
15 /****************************************************************************/
16 
17 #ifndef VEHICLEENGINEHANDLER_H
18 #define VEHICLEENGINEHANDLER_H
19 
20 #include <string>
21 #include <map>
22 #include <stack>
23 #include <sstream>
24 #include <vector>
25 #include <iostream>
26 #include <xercesc/sax2/Attributes.hpp>
27 #include <xercesc/sax2/DefaultHandler.hpp>
28 #include "EngineParameters.h"
29 
30 //definition of tag names of the xml file
31 #define ENGINE_TAG_VEHICLES "vehicles"
32 #define ENGINE_TAG_VEHICLE "vehicle"
33 #define ENGINE_TAG_VEHICLE_ID "id"
34 #define ENGINE_TAG_VEHICLE_DESCRIPTION "description"
35 #define ENGINE_TAG_GEARS "gears"
36 #define ENGINE_TAG_GEAR "gear"
37 #define ENGINE_TAG_GEAR_N "n"
38 #define ENGINE_TAG_GEAR_RATIO "ratio"
39 #define ENGINE_TAG_GEAR_DIFFERENTIAL "differential"
40 #define ENGINE_TAG_MASS "mass"
41 #define ENGINE_TAG_MASS_MASS "mass"
42 #define ENGINE_TAG_MASS_FACTOR "massFactor"
43 #define ENGINE_TAG_WHEELS "wheels"
44 #define ENGINE_TAG_WHEELS_DIAMETER "diameter"
45 #define ENGINE_TAG_WHEELS_FRICTION "friction"
46 #define ENGINE_TAG_WHEELS_CR1 "cr1"
47 #define ENGINE_TAG_WHEELS_CR2 "cr2"
48 #define ENGINE_TAG_DRAG "drag"
49 #define ENGINE_TAG_DRAG_CAIR "cAir"
50 #define ENGINE_TAG_DRAG_SECTION "section"
51 #define ENGINE_TAG_ENGINE "engine"
52 #define ENGINE_TAG_ENGINE_TYPE "type"
53 #define ENGINE_TAG_ENGINE_EFFICIENCY "efficiency"
54 #define ENGINE_TAG_ENGINE_CYLINDERS "cylinders"
55 #define ENGINE_TAG_ENGINE_MINRPM "minRpm"
56 #define ENGINE_TAG_ENGINE_MAXRPM "maxRpm"
57 #define ENGINE_TAG_ENGINE_TAU_EX "tauEx"
58 #define ENGINE_TAG_ENGINE_TAU_BURN "tauBurn"
59 #define ENGINE_TAG_ENGINE_POWER "power"
60 #define ENGINE_TAG_ENGINE_POWER_RPM "rpm"
61 #define ENGINE_TAG_ENGINE_POWER_HP "hp"
62 #define ENGINE_TAG_ENGINE_POWER_KW "kw"
63 #define ENGINE_TAG_ENGINE_POWER_SLOPE "slope"
64 #define ENGINE_TAG_ENGINE_POWER_INTERCEPT "intercept"
65 #define ENGINE_TAG_SHIFTING "shifting"
66 #define ENGINE_TAG_SHIFTING_RPM "rpm"
67 #define ENGINE_TAG_SHIFTING_DELTARPM "deltaRpm"
68 #define ENGINE_TAG_BRAKES "brakes"
69 #define ENGINE_TAG_BRAKES_TAU "tau"
70 
71 #define TAG_VEHICLES 0
72 #define TAG_VEHICLE 1
73 #define TAG_GEARS 2
74 #define TAG_ENGINE 3
75 
76 // ===========================================================================
77 // class definitions
78 // ===========================================================================
82 class VehicleEngineHandler : public XERCES_CPP_NAMESPACE::DefaultHandler {
83 
84 public:
85 
91  VehicleEngineHandler(const std::string& toLoad);
92 
93 
95  virtual ~VehicleEngineHandler();
96 
97  void startElement(const XMLCh* const uri, const XMLCh* const localname,
98  const XMLCh* const qname, const XERCES_CPP_NAMESPACE::Attributes& attrs);
99 
100  void endElement(const XMLCh* const uri, const XMLCh* const localname,
101  const XMLCh* const qname);
102 
103  void endDocument();
104 
106 
107 protected:
108 
113  void loadMassData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
114  \
119  void loadDragData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
124  void loadWheelsData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
128  void loadEngineData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
132  void loadGearData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
136  void loadDifferentialData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
141  void loadEngineModelData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
145  void loadShiftingData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
149  void loadBrakesData(const XERCES_CPP_NAMESPACE::Attributes& attrs);
150 
156  int existsAttribute(std::string tag, const char* attribute, const XERCES_CPP_NAMESPACE::Attributes& attrs);
161  std::string parseStringAttribute(std::string tag, const char* attribute, const XERCES_CPP_NAMESPACE::Attributes& attrs);
167  int parseIntAttribute(std::string tag, const char* attribute, const XERCES_CPP_NAMESPACE::Attributes& attrs);
173  double parseDoubleAttribute(std::string tag, const char* attribute, const XERCES_CPP_NAMESPACE::Attributes& attrs);
179  double parsePolynomialCoefficient(int index, const XERCES_CPP_NAMESPACE::Attributes& attrs);
183  void raiseMissingAttributeError(std::string tag, std::string attribute);
187  void raiseUnknownTagError(std::string tag);
188 
189 
190 private:
191 
192  //current tag we're into
194  //vehicle type to load
195  std::string vehicleToLoad;
196  //skip loading of current vehicle data
197  bool skip;
198  //current loaded gear
200  //where to store loaded data
202  //vector of gear ratios
203  std::vector<double> gearRatios;
204 
205 private:
208 
211 
212 };
213 
214 #endif
215 
216 /****************************************************************************/
217 
void loadWheelsData(const XERCES_CPP_NAMESPACE::Attributes &attrs)
std::string parseStringAttribute(std::string tag, const char *attribute, const XERCES_CPP_NAMESPACE::Attributes &attrs)
void loadBrakesData(const XERCES_CPP_NAMESPACE::Attributes &attrs)
double parsePolynomialCoefficient(int index, const XERCES_CPP_NAMESPACE::Attributes &attrs)
void loadDifferentialData(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)
void loadEngineModelData(const XERCES_CPP_NAMESPACE::Attributes &attrs)
const VehicleEngineHandler & operator=(const VehicleEngineHandler &s)
invalidated assignment operator
void loadDragData(const XERCES_CPP_NAMESPACE::Attributes &attrs)
EngineParameters engineParameters
void loadMassData(const XERCES_CPP_NAMESPACE::Attributes &attrs)
std::vector< double > gearRatios
const EngineParameters & getEngineParameters()
void raiseMissingAttributeError(std::string tag, std::string attribute)
void loadGearData(const XERCES_CPP_NAMESPACE::Attributes &attrs)
VehicleEngineHandler(const std::string &toLoad)
void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
int parseIntAttribute(std::string tag, const char *attribute, 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 loadEngineData(const XERCES_CPP_NAMESPACE::Attributes &attrs)
virtual ~VehicleEngineHandler()
Destructor.
void loadShiftingData(const XERCES_CPP_NAMESPACE::Attributes &attrs)
int existsAttribute(std::string tag, const char *attribute, const XERCES_CPP_NAMESPACE::Attributes &attrs)