LCOV - code coverage report
Current view: top level - src/foreign/PHEMlight/cpp - Helpers.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 34.3 % 143 49
Test Date: 2024-10-17 15:44:51 Functions: 52.4 % 21 11

            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 2016 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 PHEMlightdll {
      30              : 
      31            0 :     const std::string& Helpers::getvClass() const {
      32            0 :         return _vClass;
      33              :     }
      34              : 
      35            0 :     void Helpers::setvClass(const std::string& value) {
      36            0 :         _vClass = value;
      37            0 :     }
      38              : 
      39          109 :     const std::string& Helpers::geteClass() const {
      40          109 :         return _eClass;
      41              :     }
      42              : 
      43            0 :     void Helpers::seteClass(const std::string& value) {
      44            0 :         _eClass = value;
      45            0 :     }
      46              : 
      47          109 :     const std::string& Helpers::gettClass() const {
      48          109 :         return _tClass;
      49              :     }
      50              : 
      51            0 :     void Helpers::settClass(const std::string& value) {
      52            0 :         _tClass = value;
      53            0 :     }
      54              : 
      55            0 :     const std::string& Helpers::getsClass() const {
      56            0 :         return _sClass;
      57              :     }
      58              : 
      59            0 :     void Helpers::setsClass(const std::string& value) {
      60            0 :         _sClass = value;
      61            0 :     }
      62              : 
      63          436 :     const std::string& Helpers::getgClass() const {
      64          436 :         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::getErrMsg() const {
      72            0 :         return _ErrMsg;
      73              :     }
      74              : 
      75            0 :     void Helpers::setErrMsg(const std::string& value) {
      76            0 :         _ErrMsg = value;
      77            0 :     }
      78              : 
      79        15088 :     const std::string& Helpers::getCommentPrefix() const {
      80        15088 :         return _commentPrefix;
      81              :     }
      82              : 
      83          109 :     void Helpers::setCommentPrefix(const std::string& value) {
      84          109 :         _commentPrefix = value;
      85          109 :     }
      86              : 
      87            0 :     const std::string& Helpers::getPHEMDataV() const {
      88            0 :         return _PHEMDataV;
      89              :     }
      90              : 
      91          109 :     void Helpers::setPHEMDataV(const std::string& value) {
      92          109 :         _PHEMDataV = value;
      93          109 :     }
      94              : 
      95          109 :     bool Helpers::getvclass(const std::string& VEH) {
      96              :         // Set the drive train efficency
      97          109 :         Constants::setDRIVE_TRAIN_EFFICIENCY(Constants::DRIVE_TRAIN_EFFICIENCY_All);
      98              : 
      99              :         //Get the vehicle class
     100          109 :         if (VEH.find(Constants::strPKW) != std::string::npos) {
     101          109 :             _vClass = Constants::strPKW;
     102          109 :             return true;
     103              :         }
     104            0 :         else if (VEH.find(Constants::strLNF) != std::string::npos) {
     105            0 :             _vClass = Constants::strLNF;
     106            0 :             return true;
     107              :         }
     108            0 :         else if (VEH.find(Constants::strLKW) != std::string::npos) {
     109            0 :             _vClass = Constants::strLKW;
     110            0 :             return true;
     111              :         }
     112            0 :         else if (VEH.find(Constants::strLSZ) != std::string::npos) {
     113            0 :             _vClass = Constants::strLSZ;
     114            0 :             return true;
     115              :         }
     116            0 :         else if (VEH.find(Constants::strRB) != std::string::npos) {
     117            0 :             _vClass = Constants::strRB;
     118            0 :             return true;
     119              :         }
     120            0 :         else if (VEH.find(Constants::strLB) != std::string::npos) {
     121            0 :             _vClass = Constants::strLB;
     122            0 :             Constants::setDRIVE_TRAIN_EFFICIENCY(Constants::DRIVE_TRAIN_EFFICIENCY_CB);
     123            0 :             return true;
     124              :         }
     125            0 :         else if (VEH.find(Constants::strMR2) != std::string::npos) {
     126            0 :             _vClass = Constants::strMR2;
     127            0 :             return true;
     128              :         }
     129            0 :         else if (VEH.find(Constants::strMR4) != std::string::npos) {
     130            0 :             _vClass = Constants::strMR4;
     131            0 :             return true;
     132              :         }
     133            0 :         else if (VEH.find(Constants::strKKR) != std::string::npos) {
     134            0 :             _vClass = Constants::strKKR;
     135            0 :             return true;
     136              :         }
     137              :         //Should never happens
     138            0 :         _ErrMsg = std::string("Vehicle class not defined! (") + VEH + std::string(")");
     139            0 :         return false;
     140              :     }
     141              : 
     142          109 :     bool Helpers::gettclass(const std::string& VEH) {
     143          327 :         if ((int)VEH.find(std::string("_") + Constants::strDiesel) > 0) {
     144           69 :             if ((int)VEH.find(std::string("_") + Constants::strHybrid) > 0) {
     145            0 :                 _tClass = Constants::strDiesel + std::string("_") + Constants::strHybrid;
     146            0 :                 return true;
     147              :             }
     148              :             else {
     149           23 :                 _tClass = Constants::strDiesel;
     150           23 :                 return true;
     151              :             }
     152              : 
     153              :         }
     154          258 :         else if ((int)VEH.find(std::string("_") + Constants::strGasoline) > 0) {
     155          258 :             if ((int)VEH.find(std::string("_") + Constants::strHybrid) > 0) {
     156            0 :                 _tClass = Constants::strGasoline + std::string("_") + Constants::strHybrid;
     157            0 :                 return true;
     158              :             }
     159              :             else {
     160           86 :                 _tClass = Constants::strGasoline;
     161           86 :                 return true;
     162              :             }
     163              :         }
     164            0 :         else if ((int)VEH.find(std::string("_") + Constants::strCNG) > 0) {
     165            0 :             _tClass = Constants::strCNG;
     166            0 :             return true;
     167              :         }
     168            0 :         else if ((int)VEH.find(std::string("_") + Constants::strBEV) > 0) {
     169            0 :             _tClass = Constants::strBEV;
     170            0 :             return true;
     171              :         }
     172              :         //Should never happens
     173            0 :         _ErrMsg = std::string("Fuel class not defined! (") + VEH + std::string(")");
     174            0 :         return false;
     175              :     }
     176              : 
     177          109 :     bool Helpers::getsclass(const std::string& VEH) {
     178          109 :         if (VEH.find(Constants::strLKW) != std::string::npos) {
     179            0 :             if ((int)VEH.find(std::string("_") + Constants::strSII) > 0) {
     180            0 :                 _sClass = Constants::strSII;
     181            0 :                 return true;
     182              :             }
     183            0 :             else if ((int)VEH.find(std::string("_") + Constants::strSI) > 0) {
     184            0 :                 _sClass = Constants::strSI;
     185            0 :                 return true;
     186              :             }
     187              :             else {
     188              :                 //Should never happen
     189            0 :                 _ErrMsg = std::string("Size class not defined! (") + VEH + std::string(")");
     190            0 :                 return false;
     191              :             }
     192              :         }
     193          109 :         else if (VEH.find(Constants::strLNF) != std::string::npos) {
     194            0 :             if ((int)VEH.find(std::string("_") + Constants::strSIII) > 0) {
     195            0 :                 _sClass = Constants::strSIII;
     196            0 :                 return true;
     197              :             }
     198            0 :             else if ((int)VEH.find(std::string("_") + Constants::strSII) > 0) {
     199            0 :                 _sClass = Constants::strSII;
     200            0 :                 return true;
     201              :             }
     202            0 :             else if ((int)VEH.find(std::string("_") + Constants::strSI) > 0) {
     203            0 :                 _sClass = Constants::strSI;
     204            0 :                 return true;
     205              :             }
     206              :             else {
     207            0 :                 _ErrMsg = std::string("Size class not defined! (") + VEH.substr((int)VEH.rfind("\\"), VEH.length() - (int)VEH.rfind("\\")) + std::string(")");
     208            0 :                 return false;
     209              :             }
     210              :         }
     211              :         else {
     212          109 :             _sClass = "";
     213          109 :             return true;
     214              :         }
     215              :     }
     216              : 
     217          109 :     bool Helpers::geteclass(const std::string& VEH) {
     218          327 :         if ((int)VEH.find(std::string("_") + Constants::strEU) > 0) {
     219          327 :             if ((int)VEH.find("_", (int)VEH.find(std::string("_") + Constants::strEU) + 1) > 0) {
     220            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));
     221            0 :                 return true;
     222              :             }
     223          327 :             else if ((int)VEH.find(".", (int)VEH.find(std::string("_") + Constants::strEU) + 1) > 0) {
     224            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));
     225            0 :                 return true;
     226              :             }
     227              :             else {
     228          436 :                 _eClass = Constants::strEU + VEH.substr((int)VEH.find(std::string("_") + Constants::strEU) + 3, VEH.length() - ((int)VEH.find(std::string("_") + Constants::strEU) + 3));
     229          109 :                 return true;
     230              :             }
     231              :         }
     232            0 :         else if ((int)VEH.find(std::string("_") + Constants::strBEV) > 0) {
     233            0 :             _eClass = "";
     234            0 :             return true;
     235              :         }
     236              :         //Should never happens
     237            0 :         _ErrMsg = std::string("Euro class not defined! (") + VEH + std::string(")");
     238            0 :         return false;
     239              :     }
     240              : 
     241          109 :     bool Helpers::setclass(const std::string& VEH) {
     242          109 :         if (getvclass(VEH)) {
     243          109 :             _Class = _vClass;
     244              :         }
     245              :         else {
     246              :             return false;
     247              :         }
     248          109 :         if (getsclass(VEH)) {
     249          109 :             if (_sClass != "") {
     250            0 :                 _Class = _Class + std::string("_") + getsClass();
     251              :             }
     252              :         }
     253              :         else {
     254              :             return false;
     255              :         }
     256          109 :         if (gettclass(VEH)) {
     257          218 :             _Class = _Class + std::string("_") + gettClass();
     258              :         }
     259              :         else {
     260              :             return false;
     261              :         }
     262          109 :         if (geteclass(VEH)) {
     263          109 :             if (_eClass != "") {
     264          327 :                 _Class = _Class + std::string("_") + geteClass();
     265              :             }
     266              :         }
     267              :         else {
     268              :             return false;
     269              :         }
     270              :         return true;
     271              :     }
     272              : }
        

Generated by: LCOV version 2.0-1