LCOV - code coverage report
Current view: top level - src/libsumo - ParkingArea.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 45 58 77.6 %
Date: 2024-04-27 15:34:54 Functions: 14 23 60.9 %

          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    ParkingArea.cpp
      15             : /// @author  Jakob Erdmann
      16             : /// @date    16.03.2020
      17             : ///
      18             : // C++ TraCI client API implementation
      19             : /****************************************************************************/
      20             : #include <config.h>
      21             : 
      22             : #include <microsim/MSNet.h>
      23             : #include <microsim/MSLane.h>
      24             : #include <microsim/MSStoppingPlace.h>
      25             : #include <libsumo/TraCIConstants.h>
      26             : #include "Helper.h"
      27             : #include "ParkingArea.h"
      28             : 
      29             : 
      30             : namespace libsumo {
      31             : // ===========================================================================
      32             : // static member initializations
      33             : // ===========================================================================
      34             : SubscriptionResults ParkingArea::mySubscriptionResults;
      35             : ContextSubscriptionResults ParkingArea::myContextSubscriptionResults;
      36             : 
      37             : 
      38             : // ===========================================================================
      39             : // static member definitions
      40             : // ===========================================================================
      41             : std::vector<std::string>
      42         206 : ParkingArea::getIDList() {
      43             :     std::vector<std::string> ids;
      44         722 :     for (auto& item : MSNet::getInstance()->getStoppingPlaces(SUMO_TAG_PARKING_AREA)) {
      45         516 :         ids.push_back(item.first);
      46             :     }
      47         204 :     std::sort(ids.begin(), ids.end());
      48         204 :     return ids;
      49           2 : }
      50             : 
      51             : int
      52           6 : ParkingArea::getIDCount() {
      53           6 :     return (int)getIDList().size();
      54             : }
      55             : 
      56             : 
      57             : std::string
      58          12 : ParkingArea::getLaneID(const std::string& stopID) {
      59          12 :     return getParkingArea(stopID)->getLane().getID();
      60             : }
      61             : 
      62             : double
      63          12 : ParkingArea::getStartPos(const std::string& stopID) {
      64          12 :     return getParkingArea(stopID)->getBeginLanePosition();
      65             : }
      66             : 
      67             : double
      68          12 : ParkingArea::getEndPos(const std::string& stopID) {
      69          12 :     return getParkingArea(stopID)->getEndLanePosition();
      70             : }
      71             : 
      72             : std::string
      73          12 : ParkingArea::getName(const std::string& stopID) {
      74          12 :     return getParkingArea(stopID)->getMyName();
      75             : }
      76             : 
      77             : int
      78         120 : ParkingArea::getVehicleCount(const std::string& stopID) {
      79         120 :     return (int)getParkingArea(stopID)->getStoppedVehicles().size();
      80             : }
      81             : 
      82             : std::vector<std::string>
      83         120 : ParkingArea::getVehicleIDs(const std::string& stopID) {
      84             :     std::vector<std::string> result;
      85         186 :     for (const SUMOVehicle* veh : getParkingArea(stopID)->getStoppedVehicles()) {
      86          66 :         result.push_back(veh->getID());
      87             :     }
      88         120 :     return result;
      89           0 : }
      90             : 
      91             : 
      92             : std::string
      93           0 : ParkingArea::getParameter(const std::string& stopID, const std::string& param) {
      94           0 :     return getParkingArea(stopID)->getParameter(param, "");
      95             : }
      96             : 
      97             : 
      98           0 : LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(ParkingArea)
      99             : 
     100             : 
     101             : void
     102           0 : ParkingArea::setParameter(const std::string& stopID, const std::string& key, const std::string& value) {
     103           0 :     getParkingArea(stopID)->setParameter(key, value);
     104           0 : }
     105             : 
     106             : 
     107         152 : LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(ParkingArea, PARKINGAREA)
     108             : 
     109             : 
     110             : MSStoppingPlace*
     111         288 : ParkingArea::getParkingArea(const std::string& id) {
     112         288 :     return Helper::getStoppingPlace(id, SUMO_TAG_PARKING_AREA);
     113             : }
     114             : 
     115             : 
     116             : std::shared_ptr<VariableWrapper>
     117         267 : ParkingArea::makeWrapper() {
     118         267 :     return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
     119             : }
     120             : 
     121             : 
     122             : bool
     123         320 : ParkingArea::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
     124         320 :     switch (variable) {
     125         124 :         case TRACI_ID_LIST:
     126         124 :             return wrapper->wrapStringList(objID, variable, getIDList());
     127           4 :         case ID_COUNT:
     128           4 :             return wrapper->wrapInt(objID, variable, getIDCount());
     129           8 :         case VAR_LANE_ID:
     130          16 :             return wrapper->wrapString(objID, variable, getLaneID(objID));
     131           8 :         case VAR_POSITION:
     132           8 :             return wrapper->wrapDouble(objID, variable, getStartPos(objID));
     133           8 :         case VAR_LANEPOSITION:
     134           8 :             return wrapper->wrapDouble(objID, variable, getEndPos(objID));
     135           8 :         case VAR_NAME:
     136          16 :             return wrapper->wrapString(objID, variable, getName(objID));
     137          80 :         case VAR_STOP_STARTING_VEHICLES_NUMBER:
     138          80 :             return wrapper->wrapInt(objID, variable, getVehicleCount(objID));
     139          80 :         case VAR_STOP_STARTING_VEHICLES_IDS:
     140          80 :             return wrapper->wrapStringList(objID, variable, getVehicleIDs(objID));
     141           0 :         case libsumo::VAR_PARAMETER:
     142           0 :             paramData->readUnsignedByte();
     143           0 :             return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
     144           0 :         case libsumo::VAR_PARAMETER_WITH_KEY:
     145           0 :             paramData->readUnsignedByte();
     146           0 :             return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
     147             :         default:
     148             :             return false;
     149             :     }
     150             : }
     151             : 
     152             : }
     153             : 
     154             : 
     155             : /****************************************************************************/

Generated by: LCOV version 1.14