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-12-21 15:45:41 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           74 : ROMARouteHandler::ROMARouteHandler(ODMatrix& matrix) :
      37           74 :     SUMOSAXHandler(""), myMatrix(matrix),
      38           74 :     myIgnoreTaz(OptionsCont::getOptions().getBool("ignore-taz")),
      39           74 :     myScale(OptionsCont::getOptions().getFloat("scale")),
      40          148 :     myNumLoaded(0) {
      41          148 :     if (OptionsCont::getOptions().isSet("taz-param")) {
      42            2 :         myTazParamKeys = OptionsCont::getOptions().getStringVector("taz-param");
      43              :     }
      44           74 : }
      45              : 
      46              : 
      47           74 : ROMARouteHandler::~ROMARouteHandler() {
      48           74 : }
      49              : 
      50              : 
      51              : void
      52         1335 : ROMARouteHandler::myStartElement(int element, const SUMOSAXAttributes& attrs) {
      53         1335 :     if (element == SUMO_TAG_TRIP || element == SUMO_TAG_VEHICLE) {
      54         1092 :         myVehicleParameter = SUMOVehicleParserHelper::parseVehicleAttributes(element, attrs, true);
      55         1092 :         if (!myVehicleParameter->wasSet(VEHPARS_FROM_TAZ_SET) || myIgnoreTaz) {
      56           66 :             if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
      57           66 :                 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         1092 :         if (!myVehicleParameter->wasSet(VEHPARS_TO_TAZ_SET) || myIgnoreTaz) {
      64           66 :             if (attrs.hasAttribute(SUMO_ATTR_TO)) {
      65           66 :                 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          243 :     } 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         1335 : }
      81              : 
      82              : 
      83              : void
      84         1335 : ROMARouteHandler::myEndElement(int element) {
      85         1335 :     if (element == SUMO_TAG_TRIP || element == SUMO_TAG_VEHICLE) {
      86         1092 :         if (myVehicleParameter->fromTaz == "" || myVehicleParameter->toTaz == "") {
      87            0 :             WRITE_WARNINGF(TL("No origin or no destination given, ignoring '%'!"), myVehicleParameter->id);
      88              :         } else {
      89         1092 :             int quota = getScalingQuota(myScale, myNumLoaded);
      90         2134 :             for (int i = 0; i < quota; i++) {
      91         1042 :                 SUMOVehicleParameter veh = *myVehicleParameter;
      92         3126 :                 veh.id = i == 0 ? myVehicleParameter->id : myVehicleParameter->id + "." + toString(i);
      93         2051 :                 myMatrix.add(veh,
      94         1042 :                              !myVehicleParameter->wasSet(VEHPARS_FROM_TAZ_SET) || myIgnoreTaz,
      95         1042 :                              !myVehicleParameter->wasSet(VEHPARS_TO_TAZ_SET) || myIgnoreTaz);
      96         1042 :             }
      97         1092 :             myNumLoaded += 1;
      98              :         }
      99         1092 :         delete myVehicleParameter;
     100              :     }
     101         1335 : }
     102              : 
     103              : 
     104              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1