LCOV - code coverage report
Current view: top level - src/marouter - ROMARouteHandler.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 97.8 % 46 45
Test Date: 2024-11-20 15:55:46 Functions: 80.0 % 5 4

            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    ROMARouteHandler.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Sascha Krieg
      18              : /// @author  Michael Behrisch
      19              : /// @date    Mon, 9 Jul 2001
      20              : ///
      21              : // Parser and container for routes during their loading
      22              : /****************************************************************************/
      23              : #include <config.h>
      24              : 
      25              : #include <utils/common/MsgHandler.h>
      26              : #include <utils/options/OptionsCont.h>
      27              : #include <utils/vehicle/SUMOVehicleParameter.h>
      28              : #include <utils/vehicle/SUMOVehicleParserHelper.h>
      29              : #include <od/ODMatrix.h>
      30              : #include "ROMARouteHandler.h"
      31              : 
      32              : 
      33              : // ===========================================================================
      34              : // method definitions
      35              : // ===========================================================================
      36           72 : ROMARouteHandler::ROMARouteHandler(ODMatrix& matrix) :
      37           72 :     SUMOSAXHandler(""), myMatrix(matrix),
      38           72 :     myIgnoreTaz(OptionsCont::getOptions().getBool("ignore-taz")),
      39           72 :     myScale(OptionsCont::getOptions().getFloat("scale")),
      40          144 :     myNumLoaded(0) {
      41          144 :     if (OptionsCont::getOptions().isSet("taz-param")) {
      42            2 :         myTazParamKeys = OptionsCont::getOptions().getStringVector("taz-param");
      43              :     }
      44           72 : }
      45              : 
      46              : 
      47           72 : ROMARouteHandler::~ROMARouteHandler() {
      48           72 : }
      49              : 
      50              : 
      51              : void
      52         1322 : ROMARouteHandler::myStartElement(int element, const SUMOSAXAttributes& attrs) {
      53         1322 :     if (element == SUMO_TAG_TRIP || element == SUMO_TAG_VEHICLE) {
      54         1081 :         myVehicleParameter = SUMOVehicleParserHelper::parseVehicleAttributes(element, attrs, true);
      55         1081 :         if (!myVehicleParameter->wasSet(VEHPARS_FROM_TAZ_SET) || myIgnoreTaz) {
      56           55 :             if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
      57           44 :                 myVehicleParameter->fromTaz = attrs.getString(SUMO_ATTR_FROM);
      58           33 :             } else if (attrs.hasAttribute(SUMO_ATTR_FROM_JUNCTION)) {
      59           66 :                 myVehicleParameter->fromTaz = attrs.getString(SUMO_ATTR_FROM_JUNCTION) + "-source";
      60              :             }
      61              : 
      62              :         }
      63         1081 :         if (!myVehicleParameter->wasSet(VEHPARS_TO_TAZ_SET) || myIgnoreTaz) {
      64           55 :             if (attrs.hasAttribute(SUMO_ATTR_TO)) {
      65           44 :                 myVehicleParameter->toTaz = attrs.getString(SUMO_ATTR_TO);
      66           33 :             } else if (attrs.hasAttribute(SUMO_ATTR_TO_JUNCTION)) {
      67           66 :                 myVehicleParameter->toTaz = attrs.getString(SUMO_ATTR_TO_JUNCTION) + "-sink";
      68              :             }
      69              :         }
      70          241 :     } else if (element == SUMO_TAG_PARAM && !myTazParamKeys.empty()) {
      71           22 :         if (attrs.getString(SUMO_ATTR_KEY) == myTazParamKeys[0]) {
      72           11 :             myVehicleParameter->fromTaz = attrs.getString(SUMO_ATTR_VALUE);
      73           11 :             myVehicleParameter->parametersSet |= VEHPARS_FROM_TAZ_SET;
      74              :         }
      75           44 :         if (myTazParamKeys.size() > 1 && attrs.getString(SUMO_ATTR_KEY) == myTazParamKeys[1]) {
      76           11 :             myVehicleParameter->toTaz = attrs.getString(SUMO_ATTR_VALUE);
      77           11 :             myVehicleParameter->parametersSet |= VEHPARS_TO_TAZ_SET;
      78              :         }
      79              :     }
      80         1322 : }
      81              : 
      82              : 
      83              : void
      84         1322 : ROMARouteHandler::myEndElement(int element) {
      85         1322 :     if (element == SUMO_TAG_TRIP || element == SUMO_TAG_VEHICLE) {
      86         1081 :         if (myVehicleParameter->fromTaz == "" || myVehicleParameter->toTaz == "") {
      87            0 :             WRITE_WARNINGF(TL("No origin or no destination given, ignoring '%'!"), myVehicleParameter->id);
      88              :         } else {
      89         1081 :             int quota = getScalingQuota(myScale, myNumLoaded);
      90         2112 :             for (int i = 0; i < quota; i++) {
      91         1031 :                 SUMOVehicleParameter veh = *myVehicleParameter;
      92         3093 :                 veh.id = i == 0 ? myVehicleParameter->id : myVehicleParameter->id + "." + toString(i);
      93         2040 :                 myMatrix.add(veh,
      94         1031 :                              !myVehicleParameter->wasSet(VEHPARS_FROM_TAZ_SET) || myIgnoreTaz,
      95         1031 :                              !myVehicleParameter->wasSet(VEHPARS_TO_TAZ_SET) || myIgnoreTaz);
      96         1031 :             }
      97         1081 :             myNumLoaded += 1;
      98              :         }
      99         1081 :         delete myVehicleParameter;
     100              :     }
     101         1322 : }
     102              : 
     103              : 
     104              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1