Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2016-2024 German Aerospace Center (DLR) and others. 4 : // PHEMlight module 5 : // Copyright (C) 2016-2023 Technische Universitaet Graz, https://www.tugraz.at/ 6 : // This program and the accompanying materials are made available under the 7 : // terms of the Eclipse Public License 2.0 which is available at 8 : // https://www.eclipse.org/legal/epl-2.0/ 9 : // This Source Code may also be made available under the following Secondary 10 : // Licenses when the conditions for such availability set forth in the Eclipse 11 : // Public License 2.0 are satisfied: GNU General Public License, version 2 12 : // or later which is available at 13 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 14 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 15 : /****************************************************************************/ 16 : /// @file Helpers.cpp 17 : /// @author Martin Dippold 18 : /// @author Michael Behrisch 19 : /// @date July 2016 20 : /// 21 : // 22 : /****************************************************************************/ 23 : #include <config.h> 24 : 25 : #include "Helpers.h" 26 : #include "Constants.h" 27 : 28 : 29 : namespace PHEMlightdllV5 { 30 : 31 52 : const std::string& Helpers::getvClass() const { 32 52 : return _vClass; 33 : } 34 : 35 0 : void Helpers::setvClass(const std::string& value) { 36 0 : _vClass = value; 37 0 : } 38 : 39 18 : const std::string& Helpers::geteClass() const { 40 18 : return _eClass; 41 : } 42 : 43 0 : void Helpers::seteClass(const std::string& value) { 44 0 : _eClass = value; 45 0 : } 46 : 47 24 : const std::string& Helpers::getpClass() const { 48 24 : return _pClass; 49 : } 50 : 51 0 : void Helpers::setpClass(const std::string& value) { 52 0 : _pClass = value; 53 0 : } 54 : 55 4 : const std::string& Helpers::getsClass() const { 56 4 : return _sClass; 57 : } 58 : 59 0 : void Helpers::setsClass(const std::string& value) { 60 0 : _sClass = value; 61 0 : } 62 : 63 152 : const std::string& Helpers::getgClass() const { 64 152 : return _Class; 65 : } 66 : 67 0 : void Helpers::setgClass(const std::string& value) { 68 0 : _Class = value; 69 0 : } 70 : 71 0 : const std::string& Helpers::getuClass() const { 72 0 : return _uClass; 73 : } 74 : 75 0 : void Helpers::setuClass(const std::string& value) { 76 0 : _uClass = value; 77 0 : } 78 : 79 0 : const std::string& Helpers::getErrMsg() const { 80 0 : return _ErrMsg; 81 : } 82 : 83 0 : void Helpers::setErrMsg(const std::string& value) { 84 0 : _ErrMsg = value; 85 0 : } 86 : 87 0 : const std::string& Helpers::getCommentPrefix() const { 88 0 : return _commentPrefix; 89 : } 90 : 91 38 : void Helpers::setCommentPrefix(const std::string& value) { 92 38 : _commentPrefix = value; 93 38 : } 94 : 95 0 : const std::string& Helpers::getPHEMDataV() const { 96 0 : return _PHEMDataV; 97 : } 98 : 99 38 : void Helpers::setPHEMDataV(const std::string& value) { 100 38 : _PHEMDataV = value; 101 38 : } 102 : 103 38 : bool Helpers::getvclass(const std::string& VEH) { 104 : // Set the drive train efficency 105 38 : Constants::setDRIVE_TRAIN_EFFICIENCY(Constants::DRIVE_TRAIN_EFFICIENCY_All); 106 : 107 : //Get the vehicle class 108 38 : if (VEH.find(Constants::strPKW) != std::string::npos) { 109 38 : _vClass = Constants::strPKW; 110 38 : return true; 111 : } 112 0 : else if (VEH.find(Constants::strLNF) != std::string::npos) { 113 0 : _vClass = Constants::strLNF; 114 0 : return true; 115 : } 116 0 : else if (VEH.find(Constants::strLKW) != std::string::npos) { 117 0 : _vClass = Constants::strLKW; 118 0 : return true; 119 : } 120 0 : else if (VEH.find(Constants::strLSZ) != std::string::npos) { 121 0 : _vClass = Constants::strLSZ; 122 0 : return true; 123 : } 124 0 : else if (VEH.find(Constants::strRB) != std::string::npos) { 125 0 : _vClass = Constants::strRB; 126 0 : return true; 127 : } 128 0 : else if (VEH.find(Constants::strLB) != std::string::npos) { 129 0 : _vClass = Constants::strLB; 130 0 : Constants::setDRIVE_TRAIN_EFFICIENCY(Constants::DRIVE_TRAIN_EFFICIENCY_CB); 131 0 : return true; 132 : } 133 0 : else if (VEH.find(Constants::strMR2) != std::string::npos) { 134 0 : _vClass = Constants::strMR2; 135 0 : return true; 136 : } 137 0 : else if (VEH.find(Constants::strMR4) != std::string::npos) { 138 0 : _vClass = Constants::strMR4; 139 0 : return true; 140 : } 141 0 : else if (VEH.find(Constants::strMR) != std::string::npos) { 142 0 : _vClass = Constants::strMR; 143 0 : return true; 144 : } 145 0 : else if (VEH.find(Constants::strKKR) != std::string::npos) { 146 0 : _vClass = Constants::strKKR; 147 0 : return true; 148 : } 149 : //Should never happens 150 0 : _ErrMsg = std::string("Vehicle class not defined! (") + VEH + std::string(")"); 151 0 : return false; 152 : } 153 : 154 38 : bool Helpers::getpclass(const std::string& VEH) { 155 76 : if ((int)VEH.find(std::string("_") + Constants::strBEV) > 0) { 156 0 : _pClass = Constants::strBEV; 157 0 : return true; 158 : } 159 76 : else if ((int)VEH.find(std::string("_") + Constants::strDiesel) > 0) { 160 16 : _pClass = Constants::strDiesel; 161 16 : return true; 162 : } 163 44 : else if ((int)VEH.find(std::string("_") + Constants::strGasoline) > 0) { 164 22 : _pClass = Constants::strGasoline; 165 22 : return true; 166 : } 167 0 : else if ((int)VEH.find(std::string("_") + Constants::strCNG) > 0) { 168 0 : _pClass = Constants::strCNG; 169 0 : return true; 170 : } 171 0 : else if ((int)VEH.find(std::string("_") + Constants::strLPG) > 0) { 172 0 : _pClass = Constants::strLPG; 173 0 : return true; 174 : } 175 : //Should never happens 176 0 : _ErrMsg = std::string("Fuel class not defined! (") + VEH + std::string(")"); 177 0 : return false; 178 : } 179 : 180 38 : bool Helpers::getsclass(const std::string& VEH) { 181 38 : if (VEH.find(Constants::strLKW) != std::string::npos) { 182 0 : if ((int)VEH.find(std::string("_") + Constants::strSII) > 0) { 183 0 : _sClass = Constants::strSII; 184 0 : return true; 185 : } 186 0 : else if ((int)VEH.find(std::string("_") + Constants::strSI) > 0) { 187 0 : _sClass = Constants::strSI; 188 0 : return true; 189 : } 190 : else { 191 : //Should never happen 192 0 : _ErrMsg = std::string("Size class not defined! (") + VEH + std::string(")"); 193 0 : return false; 194 : } 195 : } 196 38 : else if (VEH.find(Constants::strLNF) != std::string::npos) { 197 0 : if ((int)VEH.find(std::string("_") + Constants::strSIII) > 0) { 198 0 : _sClass = Constants::strSIII; 199 0 : return true; 200 : } 201 0 : else if ((int)VEH.find(std::string("_") + Constants::strSII) > 0) { 202 0 : _sClass = Constants::strSII; 203 0 : return true; 204 : } 205 0 : else if ((int)VEH.find(std::string("_") + Constants::strSI) > 0) { 206 0 : _sClass = Constants::strSI; 207 0 : return true; 208 : } 209 : else { 210 0 : _ErrMsg = std::string("Size class not defined! (") + VEH.substr((int)VEH.rfind("\\"), VEH.length() - (int)VEH.rfind("\\")) + std::string(")"); 211 0 : return false; 212 : } 213 : } 214 38 : else if (VEH.find(Constants::strLB) != std::string::npos) { 215 0 : if ((int)VEH.find(std::string("_") + Constants::strMidi) > 0) { 216 0 : _sClass = Constants::strMidi; 217 0 : return true; 218 : } 219 0 : else if ((int)VEH.find(std::string("_") + Constants::strHeavy) > 0) { 220 0 : _sClass = Constants::strHeavy; 221 0 : return true; 222 : } 223 : else { 224 0 : _sClass = ""; 225 0 : return true; 226 : } 227 : } 228 : else { 229 38 : _sClass = ""; 230 38 : return true; 231 : } 232 : } 233 : 234 38 : bool Helpers::geteclass(const std::string& VEH) { 235 76 : if ((int)VEH.find(std::string("_") + Constants::strEU) > 0) { 236 76 : if ((int)VEH.find("_", (int)VEH.find(std::string("_") + Constants::strEU) + 1) > 0) { 237 190 : _eClass = Constants::strEU + VEH.substr((int)VEH.find(std::string("_") + Constants::strEU) + 3, (int)VEH.find("_", (int)VEH.find(std::string("_") + Constants::strEU) + 1) - ((int)VEH.find(std::string("_") + Constants::strEU) + 3)); 238 38 : return true; 239 : } 240 0 : else if ((int)VEH.find(".", (int)VEH.find(std::string("_") + Constants::strEU) + 1) > 0) { 241 0 : _eClass = Constants::strEU + VEH.substr((int)VEH.find(std::string("_") + Constants::strEU) + 3, (int)VEH.find(".", (int)VEH.find(std::string("_") + Constants::strEU) + 1) - ((int)VEH.find(std::string("_") + Constants::strEU) + 3)); 242 0 : return true; 243 : } 244 : else { 245 0 : _eClass = Constants::strEU + VEH.substr((int)VEH.find(std::string("_") + Constants::strEU) + 3, VEH.length() - ((int)VEH.find(std::string("_") + Constants::strEU) + 3)); 246 0 : return true; 247 : } 248 : } 249 0 : else if ((int)VEH.find(std::string("_") + Constants::strBEV) > 0) { 250 0 : _eClass = ""; 251 0 : return true; 252 : } 253 : //Should never happens 254 0 : _ErrMsg = std::string("Euro class not defined! (") + VEH + std::string(")"); 255 0 : return false; 256 : } 257 : 258 38 : bool Helpers::getuclass(const std::string& VEH) { 259 76 : if ((int)VEH.find(std::string("_") + Constants::strHybrid) > 0) { 260 0 : _uClass = Constants::strHybrid; 261 0 : return true; 262 : } 263 76 : else if ((int)VEH.find(std::string("_") + Constants::strSU) > 0) { 264 0 : _uClass = Constants::strSU; 265 0 : return true; 266 : } 267 : else { 268 38 : _uClass = ""; 269 38 : return true; 270 : } 271 : } 272 : 273 38 : bool Helpers::setclass(const std::string& VEH) { 274 : //Get the classes 275 38 : if (!getvclass(VEH)) { 276 : return false; 277 : } 278 38 : if (!geteclass(VEH)) { 279 : return false; 280 : } 281 38 : if (!getpclass(VEH)) { 282 : return false; 283 : } 284 38 : if (!getsclass(VEH)) { 285 : return false; 286 : } 287 38 : if (!getuclass(VEH)) { 288 : return false; 289 : } 290 : 291 38 : if ((int)VEH.rfind("\\") <= 0) { 292 38 : _Class = VEH; 293 : } 294 : else { 295 0 : std::string vehstr = VEH.substr((int)VEH.rfind("\\") + 1, VEH.length() - (int)VEH.rfind("\\") - 1); 296 0 : _Class = vehstr.substr(0, (int)vehstr.find(".")); 297 : } 298 : return true; 299 : } 300 : }