LCOV - code coverage report
Current view: top level - src/netbuild - NBDistrictCont.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 14 26 53.8 %
Date: 2024-05-07 15:28:01 Functions: 5 8 62.5 %

          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    NBDistrictCont.cpp
      15             : /// @author  Daniel Krajzewicz
      16             : /// @author  Michael Behrisch
      17             : /// @date    Tue, 20 Nov 2001
      18             : ///
      19             : // A container for districts
      20             : /****************************************************************************/
      21             : #include <config.h>
      22             : 
      23             : #include <string>
      24             : #include <iostream>
      25             : #include <utils/common/MsgHandler.h>
      26             : #include <utils/common/ToString.h>
      27             : #include <utils/iodevices/OutputDevice.h>
      28             : #include "NBDistrict.h"
      29             : #include "NBDistrictCont.h"
      30             : 
      31             : 
      32             : // ===========================================================================
      33             : // method definitions
      34             : // ===========================================================================
      35        2337 : NBDistrictCont::NBDistrictCont() {}
      36             : 
      37             : 
      38        2337 : NBDistrictCont::~NBDistrictCont() {
      39        2387 :     for (DistrictCont::iterator i = myDistricts.begin(); i != myDistricts.end(); i++) {
      40          50 :         delete ((*i).second);
      41             :     }
      42             :     myDistricts.clear();
      43        2337 : }
      44             : 
      45             : 
      46             : bool
      47          50 : NBDistrictCont::insert(NBDistrict* const district) {
      48             :     DistrictCont::const_iterator i = myDistricts.find(district->getID());
      49          50 :     if (i != myDistricts.end()) {
      50             :         return false;
      51             :     }
      52          50 :     myDistricts.insert(DistrictCont::value_type(district->getID(), district));
      53          50 :     return true;
      54             : }
      55             : 
      56             : 
      57             : NBDistrict*
      58           0 : NBDistrictCont::retrieve(const std::string& id) const {
      59             :     DistrictCont::const_iterator i = myDistricts.find(id);
      60           0 :     if (i == myDistricts.end()) {
      61             :         return nullptr;
      62             :     }
      63           0 :     return (*i).second;
      64             : }
      65             : 
      66             : 
      67             : int
      68        3718 : NBDistrictCont::size() const {
      69        3718 :     return (int)myDistricts.size();
      70             : }
      71             : 
      72             : 
      73             : bool
      74           0 : NBDistrictCont::addSource(const std::string& dist, NBEdge* const source,
      75             :                           double weight) {
      76           0 :     NBDistrict* o = retrieve(dist);
      77           0 :     if (o == nullptr) {
      78             :         return false;
      79             :     }
      80           0 :     return o->addSource(source, weight);
      81             : }
      82             : 
      83             : 
      84             : bool
      85           0 : NBDistrictCont::addSink(const std::string& dist, NBEdge* const destination,
      86             :                         double weight) {
      87           0 :     NBDistrict* o = retrieve(dist);
      88           0 :     if (o == nullptr) {
      89             :         return false;
      90             :     }
      91           0 :     return o->addSink(destination, weight);
      92             : }
      93             : 
      94             : 
      95             : void
      96       14779 : NBDistrictCont::removeFromSinksAndSources(NBEdge* const e) {
      97       14779 :     for (DistrictCont::iterator i = myDistricts.begin(); i != myDistricts.end(); i++) {
      98           0 :         (*i).second->removeFromSinksAndSources(e);
      99             :     }
     100       14779 : }
     101             : 
     102             : 
     103             : /****************************************************************************/

Generated by: LCOV version 1.14