1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2008-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 /****************************************************************************/ 10 /// @file SUMOVehicleParserHelper.h 11 /// @author Daniel Krajzewicz 12 /// @author Jakob Erdmann 13 /// @author Michael Behrisch 14 /// @author Laura Bieker 15 /// @date Mon, 07.04.2008 16 /// @version $Id$ 17 /// 18 // Helper methods for parsing vehicle attributes 19 /****************************************************************************/ 20 #ifndef SUMOVehicleParserHelper_h 21 #define SUMOVehicleParserHelper_h 22 23 24 // =========================================================================== 25 // included modules 26 // =========================================================================== 27 #include <config.h> 28 29 #include <random> 30 #include <string> 31 #include <utils/common/SUMOTime.h> 32 #include <utils/xml/SUMOXMLDefinitions.h> 33 34 35 // =========================================================================== 36 // class declarations 37 // =========================================================================== 38 class SUMOSAXAttributes; 39 class SUMOVehicleParameter; 40 class SUMOVTypeParameter; 41 42 43 // =========================================================================== 44 // class definitions 45 // =========================================================================== 46 /** 47 * @class SUMOVehicleParserHelper 48 * @brief Helper methods for parsing vehicle attributes 49 * 50 * This class supports helper methods for parsing a vehicle's attributes. 51 */ 52 class SUMOVehicleParserHelper { 53 public: 54 /** @brief Parses a flow's attributes 55 * 56 * Parses all attributes stored in "SUMOVehicleParameter". 57 * 58 * @see SUMOVehicleParameter 59 * @param[in] attr The SAX-attributes to get vehicle parameter from 60 * @return The parsed attribute structure if no error occurred, 0 otherwise 61 * @exception ProcessError If an attribute's value is invalid 62 * @note: the caller is responsible for deleting the returned pointer 63 */ 64 static SUMOVehicleParameter* parseFlowAttributes(const SUMOSAXAttributes& attrs, const SUMOTime beginDefault, const SUMOTime endDefault, bool isPerson = false); 65 66 67 /** @brief Parses a vehicle's attributes 68 * 69 * Parses all attributes stored in "SUMOVehicleParameter". 70 * 71 * @see SUMOVehicleParameter 72 * @param[in] attr The SAX-attributes to get vehicle parameter from 73 * @param[in] optionalID Whether the id shall be skipped 74 * @param[in] skipDepart Whether parsing the departure time shall be skipped 75 * @param[in] isPerson Whether a person is parsed 76 * @return The parsed attribute structure if no error occurred, 0 otherwise 77 * @exception ProcessError If an attribute's value is invalid 78 * @note: the caller is responsible for deleting the returned pointer 79 */ 80 static SUMOVehicleParameter* parseVehicleAttributes(const SUMOSAXAttributes& attrs, 81 const bool optionalID = false, const bool skipDepart = false, const bool isPerson = false); 82 83 84 /** @brief Starts to parse a vehicle type 85 * 86 * @param[in] attr The SAX-attributes to get vehicle parameter from 87 * @param[in] file The name of the file being parsed (for resolving paths) 88 * @exception ProcessError If an attribute's value is invalid 89 * @see SUMOVTypeParameter 90 * @note: the caller is responsible for deleting the returned pointer 91 */ 92 static SUMOVTypeParameter* beginVTypeParsing(const SUMOSAXAttributes& attrs, const std::string& file); 93 94 95 /** @brief Parses an element embedded in vtype definition 96 * 97 * @param[in, filled] into The structure to fill with parsed values 98 * @param[in] element The id of the currently parsed XML-element 99 * @param[in] attr The SAX-attributes to get vehicle parameter from 100 * @param[in] fromVType Whether the attributes are a part of the vtype-definition 101 * @exception ProcessError If an attribute's value is invalid 102 * @see SUMOVTypeParameter 103 */ 104 static void parseVTypeEmbedded(SUMOVTypeParameter& into, 105 const SumoXMLTag element, const SUMOSAXAttributes& attrs, 106 const bool fromVType = false); 107 108 /// @brief Parses lane change model attributes 109 static void parseLCParams(SUMOVTypeParameter& into, LaneChangeModel model, const SUMOSAXAttributes& attrs); 110 111 /// @brief Parses junction model attributes 112 static void parseJMParams(SUMOVTypeParameter& into, const SUMOSAXAttributes& attrs); 113 114 /** @brief Parses the vehicle class 115 * 116 * When given, the vehicle class is parsed using getVehicleClassID. 117 * Exceptions occuring within this process are catched and reported. 118 * 119 * If no vehicle class is available in the attributes, the default class (SVC_IGNORING) 120 * is returned. 121 * 122 * @param[in] attrs The attributes to read the class from 123 * @param[in] id The id of the parsed element, for error message generation 124 * @return The parsed vehicle class 125 * @see SUMOVehicleClass 126 * @todo Recheck how errors are handled and what happens if they occure 127 */ 128 static SUMOVehicleClass parseVehicleClass(const SUMOSAXAttributes& attrs, const std::string& id); 129 130 131 /** @brief Parses the vehicle class 132 * 133 * When given, the vehicle class is parsed using getVehicleShapeID. 134 * Exceptions occuring within this process are catched and reported. 135 * 136 * If no vehicle class is available in the attributes, the default class (SVS_UNKNOWN) 137 * is returned. 138 * 139 * @param[in] attrs The attributes to read the class from 140 * @param[in] id The id of the parsed element, for error message generation 141 * @return The parsed vehicle shape 142 * @see SUMOVehicleShape 143 * @todo Recheck how errors are handled and what happens if they occure 144 */ 145 static SUMOVehicleShape parseGuiShape(const SUMOSAXAttributes& attrs, const std::string& id); 146 147 /// @brief parse departPos or arrivalPos for a walk 148 static double parseWalkPos(SumoXMLAttr attr, const std::string& id, double maxPos, const std::string& val, std::mt19937* rng = 0); 149 150 151 /** @brief Checks and converts given value for the action step length from seconds 152 * to miliseconds assuring it being a positive multiple of the simulation step width 153 * 154 * @param[in] given The value parsed from the configuration (seconds). 155 * @return The milisecond value rounded to the next positive multiple of the simulation step length. 156 */ 157 static SUMOTime processActionStepLength(double given); 158 159 160 private: 161 /** @brief Parses attributes common to vehicles and flows 162 * 163 * Parses all attributes stored in "SUMOVehicleParameter". 164 * 165 * @see SUMOVehicleParameter 166 * @param[in] attr The SAX-attributes to get vehicle parameter from 167 * @param[out] ret The parameter to parse into 168 * @param[in] element The name of the element (vehicle or flow) 169 * @exception ProcessError If an attribute's value is invalid 170 */ 171 static void parseCommonAttributes(const SUMOSAXAttributes& attrs, 172 SUMOVehicleParameter* ret, std::string element); 173 174 175 typedef std::map<SumoXMLTag, std::set<SumoXMLAttr> > CFAttrMap; 176 typedef std::map<LaneChangeModel, std::set<SumoXMLAttr> > LCAttrMap; 177 178 // returns allowed attrs for each known CF-model (init on first use) 179 static const CFAttrMap& getAllowedCFModelAttrs(); 180 181 // brief allowed attrs for each known CF-model 182 static CFAttrMap allowedCFModelAttrs; 183 // brief allowed attrs for each known LC-model 184 static LCAttrMap allowedLCModelAttrs; 185 // brief allowed attrs for the junction model 186 static std::set<SumoXMLAttr> allowedJMAttrs; 187 188 189 }; 190 191 192 #endif 193 194 /****************************************************************************/ 195 196