LCOV - code coverage report
Current view: top level - src/netimport/vissim/tempstructs - NIVissimTrafficDescription.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 10.0 % 30 3
Test Date: 2024-11-22 15:46:21 Functions: 12.5 % 8 1

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-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    NIVissimTrafficDescription.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @date    Sept 2002
      17              : ///
      18              : // -------------------
      19              : /****************************************************************************/
      20              : #include <config.h>
      21              : 
      22              : #include <string>
      23              : #include <map>
      24              : #include <cassert>
      25              : #include "NIVissimVehicleClassVector.h"
      26              : #include "NIVissimTrafficDescription.h"
      27              : 
      28              : 
      29              : // ===========================================================================
      30              : // member function definitions
      31              : // ===========================================================================
      32              : NIVissimTrafficDescription::DictType NIVissimTrafficDescription::myDict;
      33              : 
      34              : 
      35              : // ===========================================================================
      36              : // member method definitions
      37              : // ===========================================================================
      38            0 : NIVissimTrafficDescription::NIVissimTrafficDescription(
      39              :     const std::string& name,
      40            0 :     const NIVissimVehicleClassVector& vehicleTypes)
      41            0 :     : myName(name), myVehicleTypes(vehicleTypes) {}
      42              : 
      43              : 
      44            0 : NIVissimTrafficDescription::~NIVissimTrafficDescription() {
      45            0 :     for (NIVissimVehicleClassVector::iterator i = myVehicleTypes.begin(); i != myVehicleTypes.end(); i++) {
      46            0 :         delete *i;
      47              :     }
      48              :     myVehicleTypes.clear();
      49            0 : }
      50              : 
      51              : 
      52              : bool
      53            0 : NIVissimTrafficDescription::dictionary(int id,
      54              :                                        const std::string& name,
      55              :                                        const NIVissimVehicleClassVector& vehicleTypes) {
      56            0 :     NIVissimTrafficDescription* o = new NIVissimTrafficDescription(name, vehicleTypes);
      57            0 :     if (!dictionary(id, o)) {
      58            0 :         delete o;
      59            0 :         return false;
      60              :     }
      61              :     return true;
      62              : }
      63              : 
      64              : 
      65              : bool
      66            0 : NIVissimTrafficDescription::dictionary(int id, NIVissimTrafficDescription* o) {
      67              :     DictType::iterator i = myDict.find(id);
      68            0 :     if (i == myDict.end()) {
      69            0 :         myDict[id] = o;
      70            0 :         return true;
      71              :     }
      72              :     return false;
      73              : }
      74              : 
      75              : 
      76              : NIVissimTrafficDescription*
      77            0 : NIVissimTrafficDescription::dictionary(int id) {
      78              :     DictType::iterator i = myDict.find(id);
      79            0 :     if (i == myDict.end()) {
      80              :         return nullptr;
      81              :     }
      82            0 :     return (*i).second;
      83              : }
      84              : 
      85              : 
      86              : void
      87            9 : NIVissimTrafficDescription::clearDict() {
      88            9 :     for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
      89            0 :         delete (*i).second;
      90              :     }
      91              :     myDict.clear();
      92            9 : }
      93              : 
      94              : 
      95              : 
      96              : 
      97              : double
      98            0 : NIVissimTrafficDescription::meanSpeed(int id) {
      99            0 :     NIVissimTrafficDescription* i = dictionary(id);
     100              :     assert(i != 0);
     101            0 :     return i->meanSpeed();
     102              : }
     103              : 
     104              : 
     105              : double
     106            0 : NIVissimTrafficDescription::meanSpeed() const {
     107              :     double speed = 0;
     108            0 :     for (NIVissimVehicleClassVector::const_iterator i = myVehicleTypes.begin(); i != myVehicleTypes.end(); i++) {
     109            0 :         speed += (*i)->getSpeed();
     110              :     }
     111            0 :     return speed / (double) myVehicleTypes.size();
     112              : }
     113              : 
     114              : 
     115              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1