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-10-24 15:46:30 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     63061590 : SUMOTrafficObject::getStringParam(const std::string& paramName, const bool required, const std::string& deflt) const {
      34     63061590 :     if (getParameter().hasParameter(paramName)) {
      35         1468 :         return getParameter().getParameter(paramName, "");
      36     63060856 :     } else if (getVTypeParameter().hasParameter(paramName)) {
      37        29898 :         return getVTypeParameter().getParameter(paramName, "");
      38              :     } else {
      39     63045907 :         const OptionsCont& oc = OptionsCont::getOptions();
      40     63045907 :         if (oc.exists(paramName) && oc.isSet(paramName)) {
      41     62990153 :             return oc.getValueString(paramName);
      42              :         } else {
      43        55754 :             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        55752 :                 if (oc.exists(paramName)) {
      48           51 :                     return oc.getValueString(paramName);
      49              :                 }
      50              :                 return deflt;
      51              :             }
      52              :         }
      53              :     }
      54              : }
      55              : 
      56              : 
      57              : double
      58     53664336 : SUMOTrafficObject::getFloatParam(const std::string& paramName, const bool required, const double deflt) const {
      59     53664336 :     const std::string val = getStringParam(paramName, required, toString(deflt));
      60              :     try {
      61     53664336 :         Distribution_Parameterized dist(val);
      62     53664336 :         const std::string& error = dist.isValid();
      63     53664336 :         if (error != "") {
      64           24 :             throw ProcessError(error);
      65              :         }
      66     53664324 :         return dist.sample();
      67     53664348 :     } 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      1514433 : SUMOTrafficObject::getBoolParam(const std::string& paramName, const bool required, const bool deflt) const {
      77      1514433 :     const std::string val = getStringParam(paramName, required, toString(deflt));
      78              :     try {
      79      1514433 :         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      3249723 : SUMOTrafficObject::getTimeParam(const std::string& paramName, const bool required, const SUMOTime deflt) const {
      90      3249723 :     const std::string val = getStringParam(paramName, required, time2string(deflt));
      91              :     try {
      92      3249723 :         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