LCOV - code coverage report
Current view: top level - src/libtraci - Lane.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 93.0 % 128 119
Test Date: 2024-10-24 15:46:30 Functions: 90.7 % 54 49

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2017-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    Lane.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Mario Krumnow
      17              : /// @author  Jakob Erdmann
      18              : /// @author  Michael Behrisch
      19              : /// @author  Robert Hilbrich
      20              : /// @author  Leonhard Luecken
      21              : /// @author  Mirko Barthauer
      22              : /// @date    30.05.2012
      23              : ///
      24              : // C++ TraCI client API implementation
      25              : /****************************************************************************/
      26              : #include <config.h>
      27              : 
      28              : #define LIBTRACI 1
      29              : #include <libsumo/Lane.h>
      30              : #include <libsumo/TraCIConstants.h>
      31              : #include "Domain.h"
      32              : 
      33              : 
      34              : namespace libtraci {
      35              : 
      36              : typedef Domain<libsumo::CMD_GET_LANE_VARIABLE, libsumo::CMD_SET_LANE_VARIABLE> Dom;
      37              : 
      38              : 
      39              : 
      40              : // ===========================================================================
      41              : // static member definitions
      42              : // ===========================================================================
      43              : std::vector<std::string>
      44           29 : Lane::getIDList() {
      45           57 :     return Dom::getStringVector(libsumo::TRACI_ID_LIST, "");
      46              : }
      47              : 
      48              : 
      49              : int
      50            2 : Lane::getIDCount() {
      51            4 :     return Dom::getInt(libsumo::ID_COUNT, "");
      52              : }
      53              : 
      54              : 
      55              : std::string
      56            3 : Lane::getEdgeID(const std::string& laneID) {
      57            3 :     return Dom::getString(libsumo::LANE_EDGE_ID, laneID);
      58              : }
      59              : 
      60              : 
      61              : double
      62         2200 : Lane::getLength(const std::string& laneID) {
      63         2200 :     return Dom::getDouble(libsumo::VAR_LENGTH, laneID);
      64              : }
      65              : 
      66              : 
      67              : double
      68            7 : Lane::getMaxSpeed(const std::string& laneID) {
      69            7 :     return Dom::getDouble(libsumo::VAR_MAXSPEED, laneID);
      70              : }
      71              : 
      72              : 
      73              : double
      74            0 : Lane::getFriction(const std::string& laneID) {
      75            0 :     return Dom::getDouble(libsumo::VAR_FRICTION, laneID);
      76              : }
      77              : 
      78              : 
      79              : int
      80            3 : Lane::getLinkNumber(const std::string& laneID) {
      81            3 :     return Dom::getInt(libsumo::LANE_LINK_NUMBER, laneID);
      82              : }
      83              : 
      84              : 
      85              : std::vector<libsumo::TraCIConnection>
      86            8 : Lane::getLinks(const std::string& laneID) {
      87            8 :     std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
      88              :     std::vector<libsumo::TraCIConnection> ret;
      89              :     tcpip::Storage& sto = Dom::get(libsumo::LANE_LINKS, laneID);
      90            8 :     sto.readUnsignedByte();
      91            8 :     sto.readInt();
      92              : 
      93            8 :     int linkNo = sto.readInt();
      94           25 :     for (int i = 0; i < linkNo; ++i) {
      95              : 
      96           17 :         sto.readUnsignedByte();
      97           17 :         std::string approachedLane = sto.readString();
      98              : 
      99           17 :         sto.readUnsignedByte();
     100           17 :         std::string approachedLaneInternal = sto.readString();
     101              : 
     102           17 :         sto.readUnsignedByte();
     103           17 :         bool hasPrio = sto.readUnsignedByte() != 0;
     104              : 
     105           17 :         sto.readUnsignedByte();
     106           17 :         bool isOpen = sto.readUnsignedByte() != 0;
     107              : 
     108           17 :         sto.readUnsignedByte();
     109           17 :         bool hasFoe = sto.readUnsignedByte() != 0;
     110              : 
     111           17 :         sto.readUnsignedByte();
     112           17 :         std::string state = sto.readString();
     113              : 
     114           17 :         sto.readUnsignedByte();
     115           17 :         std::string direction = sto.readString();
     116              : 
     117           17 :         sto.readUnsignedByte();
     118           17 :         double length = sto.readDouble();
     119              : 
     120           51 :         ret.push_back(libsumo::TraCIConnection(approachedLane,
     121              :                                                hasPrio,
     122              :                                                isOpen,
     123              :                                                hasFoe,
     124              :                                                approachedLaneInternal,
     125              :                                                state,
     126              :                                                direction,
     127              :                                                length));
     128              : 
     129              :     }
     130            8 :     return ret;
     131            0 : }
     132              : 
     133              : 
     134              : std::vector<std::string>
     135           14 : Lane::getAllowed(const std::string& laneID) {
     136           14 :     return Dom::getStringVector(libsumo::LANE_ALLOWED, laneID);
     137              : }
     138              : 
     139              : 
     140              : std::vector<std::string>
     141           11 : Lane::getDisallowed(const std::string& laneID) {
     142           11 :     return Dom::getStringVector(libsumo::LANE_DISALLOWED, laneID); // negation yields disallowed
     143              : }
     144              : 
     145              : 
     146              : std::vector<std::string>
     147            8 : Lane::getChangePermissions(const std::string& laneID, const int direction) {
     148            8 :     tcpip::Storage content;
     149              :     StoHelp::writeTypedByte(content, direction);
     150           16 :     return Dom::getStringVector(libsumo::LANE_CHANGES, laneID, &content);
     151            8 : }
     152              : 
     153              : 
     154              : libsumo::TraCIPositionVector
     155         4007 : Lane::getShape(const std::string& laneID) {
     156         4007 :     return Dom::getPolygon(libsumo::VAR_SHAPE, laneID);
     157              : }
     158              : 
     159              : 
     160              : double
     161            3 : Lane::getWidth(const std::string& laneID) {
     162            3 :     return Dom::getDouble(libsumo::VAR_WIDTH, laneID);
     163              : }
     164              : 
     165              : 
     166              : double
     167            3 : Lane::getCO2Emission(const std::string& laneID) {
     168            3 :     return Dom::getDouble(libsumo::VAR_CO2EMISSION, laneID);
     169              : }
     170              : 
     171              : 
     172              : double
     173            3 : Lane::getCOEmission(const std::string& laneID) {
     174            3 :     return Dom::getDouble(libsumo::VAR_COEMISSION, laneID);
     175              : }
     176              : 
     177              : 
     178              : double
     179            3 : Lane::getHCEmission(const std::string& laneID) {
     180            3 :     return Dom::getDouble(libsumo::VAR_HCEMISSION, laneID);
     181              : }
     182              : 
     183              : 
     184              : double
     185            3 : Lane::getPMxEmission(const std::string& laneID) {
     186            3 :     return Dom::getDouble(libsumo::VAR_PMXEMISSION, laneID);
     187              : }
     188              : 
     189              : 
     190              : double
     191            3 : Lane::getNOxEmission(const std::string& laneID) {
     192            3 :     return Dom::getDouble(libsumo::VAR_NOXEMISSION, laneID);
     193              : }
     194              : 
     195              : 
     196              : double
     197            3 : Lane::getFuelConsumption(const std::string& laneID) {
     198            3 :     return Dom::getDouble(libsumo::VAR_FUELCONSUMPTION, laneID);
     199              : }
     200              : 
     201              : 
     202              : double
     203            3 : Lane::getNoiseEmission(const std::string& laneID) {
     204            3 :     return Dom::getDouble(libsumo::VAR_NOISEEMISSION, laneID);
     205              : }
     206              : 
     207              : 
     208              : double
     209            3 : Lane::getElectricityConsumption(const std::string& laneID) {
     210            3 :     return Dom::getDouble(libsumo::VAR_ELECTRICITYCONSUMPTION, laneID);
     211              : }
     212              : 
     213              : 
     214              : double
     215            3 : Lane::getLastStepMeanSpeed(const std::string& laneID) {
     216            3 :     return Dom::getDouble(libsumo::LAST_STEP_MEAN_SPEED, laneID);
     217              : }
     218              : 
     219              : 
     220              : double
     221            3 : Lane::getLastStepOccupancy(const std::string& laneID) {
     222            3 :     return Dom::getDouble(libsumo::LAST_STEP_OCCUPANCY, laneID);
     223              : }
     224              : 
     225              : 
     226              : double
     227            3 : Lane::getLastStepLength(const std::string& laneID) {
     228            3 :     return Dom::getDouble(libsumo::LAST_STEP_LENGTH, laneID);
     229              : }
     230              : 
     231              : 
     232              : double
     233            3 : Lane::getWaitingTime(const std::string& laneID) {
     234            3 :     return Dom::getDouble(libsumo::VAR_WAITING_TIME, laneID);
     235              : }
     236              : 
     237              : 
     238              : double
     239            3 : Lane::getTraveltime(const std::string& laneID) {
     240            3 :     return Dom::getDouble(libsumo::VAR_CURRENT_TRAVELTIME, laneID);
     241              : }
     242              : 
     243              : 
     244              : int
     245            3 : Lane::getLastStepVehicleNumber(const std::string& laneID) {
     246            3 :     return Dom::getInt(libsumo::LAST_STEP_VEHICLE_NUMBER, laneID);
     247              : }
     248              : 
     249              : 
     250              : int
     251            3 : Lane::getLastStepHaltingNumber(const std::string& laneID) {
     252            3 :     return Dom::getInt(libsumo::LAST_STEP_VEHICLE_HALTING_NUMBER, laneID);
     253              : }
     254              : 
     255              : 
     256              : std::vector<std::string>
     257          209 : Lane::getLastStepVehicleIDs(const std::string& laneID) {
     258          209 :     return Dom::getStringVector(libsumo::LAST_STEP_VEHICLE_ID_LIST, laneID);
     259              : }
     260              : 
     261              : 
     262              : std::vector<std::string>
     263            5 : Lane::getFoes(const std::string& laneID, const std::string& toLaneID) {
     264            5 :     tcpip::Storage content;
     265            5 :     content.writeUnsignedByte(libsumo::TYPE_STRING);
     266            5 :     content.writeString(toLaneID);
     267           10 :     return Dom::getStringVector(libsumo::VAR_FOES, laneID, &content);
     268            5 : }
     269              : 
     270              : 
     271              : // XXX: there seems to be no "Dom::getFoes"
     272              : std::vector<std::string>
     273            2 : Lane::getInternalFoes(const std::string& laneID) {
     274              :     //tcpip::Storage content;
     275              :     //content.writeUnsignedByte(libsumo::TYPE_STRING);
     276              :     //content.writeString("");
     277              :     //return Dom::getStringVector(libsumo::VAR_FOES, laneID, &content);
     278            4 :     return getFoes(laneID, "");
     279              :     //return Dom::getFoes(laneID, "");
     280              : }
     281              : 
     282              : 
     283              : const std::vector<std::string>
     284            9 : Lane::getPendingVehicles(const std::string& laneID) {
     285            9 :     return Dom::getStringVector(libsumo::VAR_PENDING_VEHICLES, laneID);
     286              : }
     287              : 
     288              : 
     289              : double
     290            4 : Lane::getAngle(const std::string& laneID, double relativePosition) {
     291            4 :     tcpip::Storage content;
     292            4 :     content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
     293            4 :     content.writeDouble(relativePosition);
     294            8 :     return Dom::getDouble(libsumo::VAR_ANGLE, laneID, &content);
     295            4 : }
     296              : 
     297              : std::string
     298           18 : Lane::getBidiLane(const std::string& laneID) {
     299           18 :     return Dom::getString(libsumo::VAR_BIDI, laneID);
     300              : }
     301              : 
     302              : void
     303            4 : Lane::setAllowed(const std::string& laneID, std::string allowedClass) {
     304            8 :     setAllowed(laneID, std::vector<std::string>({allowedClass}));
     305            4 : }
     306              : 
     307              : 
     308              : void
     309            7 : Lane::setAllowed(const std::string& laneID, std::vector<std::string> allowedClasses) {
     310            7 :     Dom::setStringVector(libsumo::LANE_ALLOWED, laneID, allowedClasses);
     311            7 : }
     312              : 
     313              : 
     314              : void
     315            0 : Lane::setDisallowed(const std::string& laneID, std::string disallowedClasses) {
     316            0 :     setDisallowed(laneID, std::vector<std::string>({disallowedClasses}));
     317            0 : }
     318              : 
     319              : 
     320              : void
     321            4 : Lane::setDisallowed(const std::string& laneID, std::vector<std::string> disallowedClasses) {
     322            4 :     Dom::setStringVector(libsumo::LANE_DISALLOWED, laneID, disallowedClasses);
     323            4 : }
     324              : 
     325              : 
     326              : void
     327            4 : Lane::setChangePermissions(const std::string& laneID, std::vector<std::string> allowedClasses, const int direction) {
     328            4 :     tcpip::Storage content;
     329              :     StoHelp::writeCompound(content, 2);
     330              :     StoHelp::writeTypedStringList(content, allowedClasses);
     331              :     StoHelp::writeTypedByte(content, direction);
     332            4 :     Dom::set(libsumo::LANE_CHANGES, laneID, &content);
     333            4 : }
     334              : 
     335              : 
     336              : void
     337            7 : Lane::setMaxSpeed(const std::string& laneID, double speed) {
     338            7 :     Dom::setDouble(libsumo::VAR_MAXSPEED, laneID, speed);
     339            7 : }
     340              : 
     341              : 
     342              : void
     343            0 : Lane::setFriction(const std::string& laneID, double friction) {
     344            0 :     Dom::setDouble(libsumo::VAR_FRICTION, laneID, friction);
     345            0 : }
     346              : 
     347              : 
     348              : void
     349            3 : Lane::setLength(const std::string& laneID, double length) {
     350            3 :     Dom::setDouble(libsumo::VAR_LENGTH, laneID, length);
     351            3 : }
     352              : 
     353              : 
     354         8160 : LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(Lane, LANE)
     355           30 : LIBTRACI_PARAMETER_IMPLEMENTATION(Lane, LANE)
     356              : 
     357              : }
     358              : 
     359              : 
     360              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1