LCOV - code coverage report
Current view: top level - src/od - ODDistrictCont.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 90.0 % 30 27
Test Date: 2024-11-21 15:56:26 Functions: 85.7 % 7 6

            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    ODDistrictCont.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @author  Yun-Pang Floetteroed
      18              : /// @date    Sept 2002
      19              : ///
      20              : // A container for districts
      21              : /****************************************************************************/
      22              : #include <config.h>
      23              : 
      24              : #include <string>
      25              : #include <utils/common/MsgHandler.h>
      26              : #include <utils/common/UtilExceptions.h>
      27              : #include <utils/common/NamedObjectCont.h>
      28              : #include <utils/xml/XMLSubSys.h>
      29              : #include <utils/common/RandHelper.h>
      30              : #include <utils/common/FileHelpers.h>
      31              : #include <utils/options/OptionsCont.h>
      32              : #include "ODDistrict.h"
      33              : #include "ODDistrictHandler.h"
      34              : #include "ODDistrictCont.h"
      35              : 
      36              : 
      37              : 
      38              : // ===========================================================================
      39              : // method definitions
      40              : // ===========================================================================
      41          233 : ODDistrictCont::ODDistrictCont() {}
      42              : 
      43              : 
      44          233 : ODDistrictCont::~ODDistrictCont() {}
      45              : 
      46              : 
      47              : std::string
      48        15963 : ODDistrictCont::getRandomSourceFromDistrict(const std::string& name) const {
      49              :     ODDistrict* district = get(name);
      50        15963 :     if (district == nullptr) {
      51            0 :         throw InvalidArgument("There is no district '" + name + "'.");
      52              :     }
      53        15963 :     return district->getRandomSource();
      54              : }
      55              : 
      56              : 
      57              : std::string
      58        15963 : ODDistrictCont::getRandomSinkFromDistrict(const std::string& name) const {
      59              :     ODDistrict* district = get(name);
      60        15963 :     if (district == nullptr) {
      61            0 :         throw InvalidArgument("There is no district '" + name + "'.");
      62              :     }
      63        15963 :     return district->getRandomSink();
      64              : }
      65              : 
      66              : 
      67              : void
      68          143 : ODDistrictCont::loadDistricts(std::vector<std::string> files) {
      69          285 :     for (std::vector<std::string>::iterator i = files.begin(); i != files.end(); ++i) {
      70              :         const std::string& districtfile = *i;
      71          286 :         if (!FileHelpers::isReadable(districtfile)) {
      72            3 :             throw ProcessError(TLF("Could not access network file '%' to load.", districtfile));
      73              :         }
      74          426 :         PROGRESS_BEGIN_MESSAGE("Loading districts from '" + districtfile + "'");
      75              :         // build the xml-parser and handler
      76          142 :         ODDistrictHandler handler(*this, districtfile);
      77          142 :         if (!XMLSubSys::runParser(handler, districtfile, true)) {
      78            0 :             PROGRESS_FAILED_MESSAGE();
      79              :         } else {
      80          142 :             PROGRESS_DONE_MESSAGE();
      81              :         }
      82          142 :     }
      83          142 : }
      84              : 
      85              : 
      86              : void
      87           90 : ODDistrictCont::makeDistricts(const std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > >& districts) {
      88          335 :     for (std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > >::const_iterator it = districts.begin(); it != districts.end(); ++it) {
      89          245 :         ODDistrict* current = new ODDistrict(it->first);
      90              :         const std::vector<std::string>& sources = it->second.first;
      91          679 :         for (std::vector<std::string>::const_iterator i = sources.begin(); i != sources.end(); ++i) {
      92          434 :             current->addSource(*i, 1.);
      93              :         }
      94              :         const std::vector<std::string>& sinks = it->second.second;
      95          672 :         for (std::vector<std::string>::const_iterator i = sinks.begin(); i != sinks.end(); ++i) {
      96          427 :             current->addSink(*i, 1.);
      97              :         }
      98          245 :         add(current->getID(), current);
      99              :     }
     100           90 : }
     101              : 
     102              : 
     103              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1