LCOV - code coverage report
Current view: top level - src/utils/vehicle - SUMOTrafficObject.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 77.5 % 40 31
Test Date: 2024-12-21 15:45:41 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2002-2024 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    SUMOTrafficObject.cpp
      15              : /// @author  Michael Behrisch
      16              : /// @date    2024-06-27
      17              : ///
      18              : // Abstract base class for vehicle, person, and container representations
      19              : /****************************************************************************/
      20              : #include <config.h>
      21              : 
      22              : #include <utils/common/MsgHandler.h>
      23              : #include <utils/common/ToString.h>
      24              : #include <utils/options/OptionsCont.h>
      25              : #include "SUMOVehicleParameter.h"
      26              : #include "SUMOTrafficObject.h"
      27              : 
      28              : 
      29              : // ===========================================================================
      30              : // method definitions
      31              : // ===========================================================================
      32              : std::string
      33     11632026 : SUMOTrafficObject::getStringParam(const std::string& paramName, const bool required, const std::string& deflt) const {
      34     11632026 :     if (getParameter().hasParameter(paramName)) {
      35         1564 :         return getParameter().getParameter(paramName, "");
      36     11631244 :     } else if (getVTypeParameter().hasParameter(paramName)) {
      37        30034 :         return getVTypeParameter().getParameter(paramName, "");
      38              :     } else {
      39     11616227 :         const OptionsCont& oc = OptionsCont::getOptions();
      40     11616227 :         if (oc.exists(paramName) && oc.isSet(paramName)) {
      41     11561115 :             return oc.getValueString(paramName);
      42              :         } else {
      43        55112 :             if (required) {
      44            2 :                 const std::string type = isVehicle() ? "vehicle" : (isPerson() ? "person" : "container");
      45            6 :                 throw ProcessError(TLF("Missing parameter '%' for % '%'.", paramName, type, getID()));
      46              :             } else {
      47        55110 :                 if (oc.exists(paramName)) {
      48           51 :                     return oc.getValueString(paramName);
      49              :                 }
      50              :                 return deflt;
      51              :             }
      52              :         }
      53              :     }
      54              : }
      55              : 
      56              : 
      57              : double
      58      1709123 : SUMOTrafficObject::getFloatParam(const std::string& paramName, const bool required, const double deflt) const {
      59      1709123 :     const std::string val = getStringParam(paramName, required, toString(deflt));
      60              :     try {
      61      1709123 :         Distribution_Parameterized dist(val);
      62      1709123 :         const std::string& error = dist.isValid();
      63      1709123 :         if (error != "") {
      64           24 :             throw ProcessError(error);
      65              :         }
      66      1709111 :         return dist.sample();
      67      1709135 :     } catch (const ProcessError& e) {
      68           12 :         const std::string type = isVehicle() ? "vehicle" : (isPerson() ? "person" : "container");
      69           36 :         WRITE_ERRORF(TL("Invalid distribution / float value '%' for parameter '%' in % '%' (%)."), val, paramName, type, getID(), e.what());
      70           12 :         return deflt;
      71           12 :     }
      72              : }
      73              : 
      74              : 
      75              : bool
      76      1518811 : SUMOTrafficObject::getBoolParam(const std::string& paramName, const bool required, const bool deflt) const {
      77      1518811 :     const std::string val = getStringParam(paramName, required, toString(deflt));
      78              :     try {
      79      1518811 :         return StringUtils::toBool(val);
      80            0 :     } catch (const ProcessError&) {
      81            0 :         const std::string type = isVehicle() ? "vehicle" : (isPerson() ? "person" : "container");
      82            0 :         WRITE_ERRORF(TL("Invalid boolean value '%' for parameter '%' in % '%'."), val, paramName, type, getID());
      83            0 :         return deflt;
      84            0 :     }
      85              : }
      86              : 
      87              : 
      88              : SUMOTime
      89      3263077 : SUMOTrafficObject::getTimeParam(const std::string& paramName, const bool required, const SUMOTime deflt) const {
      90      3263077 :     const std::string val = getStringParam(paramName, required, time2string(deflt));
      91              :     try {
      92      3263077 :         return string2time(val);
      93            0 :     } catch (const ProcessError&) {
      94            0 :         const std::string type = isVehicle() ? "vehicle" : (isPerson() ? "person" : "container");
      95            0 :         WRITE_ERRORF(TL("Invalid time value '%' for parameter '%' in % '%'."), val, paramName, type, getID());
      96              :         return deflt;
      97            0 :     }
      98              : }
      99              : 
     100              : 
     101              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1