LCOV - code coverage report
Current view: top level - src/dfrouter - RODFDetectorHandler.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 91.2 % 34 31
Test Date: 2024-11-21 15:56:26 Functions: 75.0 % 4 3

            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    RODFDetectorHandler.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Eric Nicolay
      17              : /// @author  Jakob Erdmann
      18              : /// @author  Michael Behrisch
      19              : /// @date    Thu, 16.03.2006
      20              : ///
      21              : // A handler for loading detector descriptions
      22              : /****************************************************************************/
      23              : #include <config.h>
      24              : 
      25              : #include <string>
      26              : #include <utils/options/OptionsCont.h>
      27              : #include <utils/common/MsgHandler.h>
      28              : #include <utils/common/StringTokenizer.h>
      29              : #include <utils/common/UtilExceptions.h>
      30              : #include <utils/common/StringUtils.h>
      31              : #include <utils/common/ToString.h>
      32              : #include <utils/xml/SUMOSAXHandler.h>
      33              : #include <utils/xml/SUMOXMLDefinitions.h>
      34              : #include "RODFDetectorHandler.h"
      35              : #include "RODFNet.h"
      36              : 
      37              : 
      38              : // ===========================================================================
      39              : // method definitions
      40              : // ===========================================================================
      41          195 : RODFDetectorHandler::RODFDetectorHandler(RODFNet* optNet, bool ignoreErrors, RODFDetectorCon& con,
      42          195 :         const std::string& file)
      43              :     : SUMOSAXHandler(file),
      44          390 :       myNet(optNet), myIgnoreErrors(ignoreErrors), myContainer(con) {}
      45              : 
      46              : 
      47          195 : RODFDetectorHandler::~RODFDetectorHandler() {}
      48              : 
      49              : 
      50              : void
      51         1865 : RODFDetectorHandler::myStartElement(int element,
      52              :                                     const SUMOSAXAttributes& attrs) {
      53         1865 :     if (element == SUMO_TAG_DETECTOR_DEFINITION || element == SUMO_TAG_E1DETECTOR || element == SUMO_TAG_INDUCTION_LOOP) {
      54              :         try {
      55         1671 :             bool ok = true;
      56              :             // get the id, report an error if not given or empty...
      57         1671 :             std::string id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
      58         1671 :             if (!ok) {
      59            0 :                 throw ProcessError();
      60              :             }
      61         1671 :             std::string lane = attrs.get<std::string>(SUMO_ATTR_LANE, id.c_str(), ok);
      62         1671 :             if (!ok) {
      63            4 :                 throw ProcessError();
      64              :             }
      65         5001 :             ROEdge* edge = myNet->getEdge(SUMOXMLDefinitions::getEdgeIDFromLane(lane));
      66         1667 :             int laneIndex = SUMOXMLDefinitions::getIndexFromLane(lane);
      67         1667 :             if (edge == nullptr || laneIndex >= edge->getNumLanes()) {
      68            6 :                 throw ProcessError("Unknown lane '" + lane + "' for detector '" + id + "' in '" + getFileName() + "'.");
      69              :             }
      70         1664 :             double pos = attrs.get<double>(SUMO_ATTR_POSITION, id.c_str(), ok);
      71         1677 :             std::string mml_type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, id.c_str(), ok, "");
      72         1664 :             if (!ok) {
      73            6 :                 throw ProcessError();
      74              :             }
      75              :             RODFDetectorType type = TYPE_NOT_DEFINED;
      76         1658 :             if (mml_type == "between") {
      77              :                 type = BETWEEN_DETECTOR;
      78         1593 :             } else if (mml_type == "source" || mml_type == "highway_source") { // !!! highway-source is legacy (removed accoring output on 06.08.2007)
      79              :                 type = SOURCE_DETECTOR;
      80         1548 :             } else if (mml_type == "sink") {
      81              :                 type = SINK_DETECTOR;
      82              :             }
      83         1658 :             RODFDetector* detector = new RODFDetector(id, lane, pos, type);
      84         1658 :             if (!myContainer.addDetector(detector)) {
      85            0 :                 delete detector;
      86            0 :                 throw ProcessError(TLF("Could not add detector '%' (probably the id is already used).", id));
      87              :             }
      88           13 :         } catch (ProcessError& e) {
      89           13 :             if (myIgnoreErrors) {
      90            1 :                 WRITE_WARNING(e.what());
      91              :             } else {
      92           24 :                 throw e;
      93              :             }
      94           13 :         }
      95              :     }
      96         1853 : }
      97              : 
      98              : 
      99              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1