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