LCOV - code coverage report
Current view: top level - src/utils/common - StdDefs.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 4 4
Test Date: 2024-11-22 15:46:21 Functions: - 0 0

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2005-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    StdDefs.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Laura Bieker
      17              : /// @author  Michael Behrisch
      18              : /// @author  Jakob Erdmann
      19              : /// @date    Fri, 29.04.2005
      20              : ///
      21              : //
      22              : /****************************************************************************/
      23              : #pragma once
      24              : #include <config.h>
      25              : #include <string>
      26              : #include <cmath>
      27              : #include <limits>
      28              : 
      29              : /* avoiding compiler warning unreferenced parameter */
      30              : #define UNUSED_PARAMETER(x)  ((void)(x))
      31              : 
      32              : #ifdef _MSC_VER
      33              : #define FALLTHROUGH /* do nothing */
      34              : #elif __GNUC__ < 7
      35              : #define FALLTHROUGH /* do nothing */
      36              : #else
      37              : #define FALLTHROUGH __attribute__((fallthrough))
      38              : #endif
      39              : 
      40              : /// @brief the maximum number of connections across an intersection
      41              : #define  SUMO_MAX_CONNECTIONS 256
      42              : 
      43              : class RGBColor;
      44              : 
      45              : /* -------------------------------------------------------------------------
      46              :  * some constant defaults used by SUMO
      47              :  * ----------------------------------------------------------------------- */
      48              : const double SUMO_const_laneWidth = 3.2;
      49              : const double SUMO_const_halfLaneWidth = SUMO_const_laneWidth / 2;
      50              : const double SUMO_const_quarterLaneWidth = SUMO_const_laneWidth / 4;
      51              : const double SUMO_const_laneMarkWidth = 0.1;
      52              : const double SUMO_const_waitingPersonWidth = 0.8;
      53              : const double SUMO_const_waitingPersonDepth = 0.67;
      54              : const double SUMO_const_waitingContainerWidth = 2.5;
      55              : const double SUMO_const_waitingContainerDepth = 6.2;
      56              : 
      57              : /// @brief the speed threshold at which vehicles are considered as halting
      58              : const double SUMO_const_haltingSpeed = (double) 0.1;
      59              : 
      60              : /// @brief invalid int
      61              : const int INVALID_INT = std::numeric_limits<int>::max();
      62              : 
      63              : /// @brief invalid double
      64              : const double INVALID_DOUBLE = std::numeric_limits<double>::max();
      65              : 
      66              : /// @brief (M)ajor/(M)inor version for written networks and default version for loading
      67              : typedef std::pair<int, double> MMVersion;
      68              : const MMVersion NETWORK_VERSION(1, 20);
      69              : 
      70              : /* -------------------------------------------------------------------------
      71              :  * templates for mathematical functions missing in some c++-implementations
      72              :  * ----------------------------------------------------------------------- */
      73              : 
      74              : template<typename T>
      75              : inline T
      76              : MIN2(T a, T b) {
      77  75630344415 :     return a < b ? a : b;
      78              : }
      79              : 
      80              : template<typename T>
      81              : inline T
      82              : MAX2(T a, T b) {
      83  55255419774 :     return a > b ? a : b;
      84              : }
      85              : 
      86              : 
      87              : template<typename T>
      88              : inline T
      89              : MIN3(T a, T b, T c) {
      90    806276299 :     return MIN2(c, a < b ? a : b);
      91              : }
      92              : 
      93              : 
      94              : template<typename T>
      95              : inline T
      96              : MAX3(T a, T b, T c) {
      97    913672290 :     return MAX2(c, a > b ? a : b);
      98              : }
      99              : 
     100              : 
     101              : template<typename T>
     102              : inline T
     103              : MIN4(T a, T b, T c, T d) {
     104              :     return MIN2(MIN2(a, b), MIN2(c, d));
     105              : }
     106              : 
     107              : 
     108              : template<typename T>
     109              : inline T
     110              : MAX4(T a, T b, T c, T d) {
     111              :     return MAX2(MAX2(a, b), MAX2(c, d));
     112              : }
     113              : 
     114              : 
     115              : /// the precision for floating point outputs
     116              : extern int gPrecision;
     117              : extern int gPrecisionGeo; // for lon,lat
     118              : extern int gPrecisionRandom; // for randomized values (i.e. speedFactor)
     119              : extern bool gHumanReadableTime;
     120              : extern bool gSimulation; // whether the current application is sumo or sumo-gui (as opposed to a router)
     121              : extern bool gIgnoreUnknownVClass; // whether the unknown vehicle classes shall be ignored on loading (for upward compatibility)
     122              : extern double gWeightsRandomFactor; // randomization for edge weights
     123              : extern double gWeightsWalkOppositeFactor; // factor for walking against flow of traffic
     124              : 
     125              : /// the language for GUI elements and messages
     126              : extern std::string gLanguage;
     127              : 
     128              : /// the default size for GUI elements
     129              : extern int GUIDesignHeight;
     130              : 
     131              : 
     132              : /// @brief global utility flags for debugging
     133              : extern bool gDebugFlag1;
     134              : extern bool gDebugFlag2;
     135              : extern bool gDebugFlag3;
     136              : extern bool gDebugFlag4;
     137              : extern bool gDebugFlag5;
     138              : extern bool gDebugFlag6;
     139              : 
     140              : // synchronized output to stdout with << (i.e. DEBUGOUT(gDebugFlag1, SIMTIME << " var=" << var << "\n")
     141              : #define DEBUGOUT(cond, msg) if (cond) {std::ostringstream oss; oss << msg; std::cout << oss.str();}
     142              : 
     143              : /// @brief discrds mantissa bits beyond the given number
     144              : double truncate(double x, int fractionBits);
     145              : 
     146              : /// @brief round to the given number of mantissa bits beyond the given number
     147              : double roundBits(double x, int fractionBits);
     148              : 
     149              : /// @brief round to the given number of decimal digits
     150              : double roundDecimal(double x, int precision);
     151              : 
     152              : /** @brief Returns the number of instances of the current object that shall be emitted
     153              :  * given the number of loaded objects
     154              :  * considering that "frac" of all objects shall be emitted overall
     155              :  * @return the number of objects to create (something between 0 and ceil(frac))
     156              :  */
     157              : int getScalingQuota(double frac, int loaded);
        

Generated by: LCOV version 2.0-1