LCOV - code coverage report
Current view: top level - src/netimport - NITypeLoader.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 10 23 43.5 %
Date: 2024-05-02 15:31:40 Functions: 1 1 100.0 %

          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    NITypeLoader.cpp
      15             : /// @author  Daniel Krajzewicz
      16             : /// @author  Jakob Erdmann
      17             : /// @author  Sascha Krieg
      18             : /// @author  Michael Behrisch
      19             : /// @author  Robert Hilbrich
      20             : /// @date    Tue, 20 Nov 2001
      21             : ///
      22             : // Perfoms network import
      23             : /****************************************************************************/
      24             : #include <config.h>
      25             : 
      26             : #include <string>
      27             : #include <utils/common/UtilExceptions.h>
      28             : #include <utils/common/MsgHandler.h>
      29             : #include <utils/options/OptionsCont.h>
      30             : #include <utils/options/Option.h>
      31             : #include <utils/common/FileHelpers.h>
      32             : #include <utils/common/StringUtils.h>
      33             : #include <utils/common/ToString.h>
      34             : #include <utils/common/StringUtils.h>
      35             : #include <utils/xml/SUMOSAXHandler.h>
      36             : #include <utils/xml/SUMOSAXReader.h>
      37             : #include <utils/xml/XMLSubSys.h>
      38             : #include "NITypeLoader.h"
      39             : 
      40             : 
      41             : bool
      42       17495 : NITypeLoader::load(SUMOSAXHandler& handler, const std::vector<std::string>& files,
      43             :                    const std::string& type, const bool stringParse) {
      44             :     // build parser
      45       17495 :     std::string exceptMsg = "";
      46       17495 :     std::string fileName = "";
      47             :     // start the parsing
      48             :     bool ok = true;
      49             :     bool raise = false;
      50             :     try {
      51       20240 :         for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
      52             :             fileName = *file;
      53        2750 :             if (stringParse) {
      54             :                 fileName = "built in type map";
      55           0 :                 handler.setFileName(fileName);
      56           0 :                 SUMOSAXReader* reader = XMLSubSys::getSAXReader(handler);
      57           0 :                 reader->parseString(*file);
      58           0 :                 delete reader;
      59           0 :                 continue;
      60           0 :             }
      61        5500 :             if (!FileHelpers::isReadable(fileName)) {
      62          17 :                 WRITE_ERRORF(TL("Could not open %-file '%'."), type, fileName);
      63             :                 return false;
      64             :             }
      65        5490 :             PROGRESS_BEGIN_MESSAGE("Parsing " + type + " from '" + fileName + "'");
      66        2745 :             ok &= XMLSubSys::runParser(handler, fileName);
      67        2745 :             PROGRESS_DONE_MESSAGE();
      68             :         }
      69           0 :     } catch (const XERCES_CPP_NAMESPACE::XMLException& toCatch) {
      70           0 :         exceptMsg = StringUtils::transcode(toCatch.getMessage()) + "\n  ";
      71             :         raise = true;
      72           0 :     } catch (const ProcessError& toCatch) {
      73           0 :         exceptMsg = std::string(toCatch.what()) + "\n  ";
      74             :         raise = true;
      75           0 :     } catch (...) {
      76             :         raise = true;
      77           0 :     }
      78             :     if (raise) {
      79           0 :         throw ProcessError(exceptMsg + "The " + type + " could not be loaded from '" + fileName + "'.");
      80             :     }
      81             :     return ok;
      82             : }
      83             : 
      84             : 
      85             : /****************************************************************************/

Generated by: LCOV version 1.14