LCOV - code coverage report
Current view: top level - src/libsumo - OverheadWire.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 73.8 % 65 48
Test Date: 2024-12-21 15:45:41 Functions: 47.8 % 23 11

            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    OverheadWire.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 <microsim/trigger/MSOverheadWire.h>
      26              : #include <libsumo/TraCIConstants.h>
      27              : #include "Helper.h"
      28              : #include "OverheadWire.h"
      29              : 
      30              : 
      31              : namespace libsumo {
      32              : // ===========================================================================
      33              : // static member initializations
      34              : // ===========================================================================
      35              : SubscriptionResults OverheadWire::mySubscriptionResults;
      36              : ContextSubscriptionResults OverheadWire::myContextSubscriptionResults;
      37              : 
      38              : 
      39              : // ===========================================================================
      40              : // static member definitions
      41              : // ===========================================================================
      42              : std::vector<std::string>
      43          264 : OverheadWire::getIDList() {
      44              :     std::vector<std::string> ids;
      45          394 :     for (auto& item : MSNet::getInstance()->getStoppingPlaces(SUMO_TAG_OVERHEAD_WIRE_SEGMENT)) {
      46          130 :         ids.push_back(item.first);
      47              :     }
      48          262 :     std::sort(ids.begin(), ids.end());
      49          262 :     return ids;
      50            2 : }
      51              : 
      52              : int
      53            5 : OverheadWire::getIDCount() {
      54            5 :     return (int)getIDList().size();
      55              : }
      56              : 
      57              : 
      58              : std::string
      59           10 : OverheadWire::getLaneID(const std::string& stopID) {
      60           10 :     return getOverheadWire(stopID)->getLane().getID();
      61              : }
      62              : 
      63              : 
      64              : double
      65           10 : OverheadWire::getStartPos(const std::string& stopID) {
      66           10 :     return getOverheadWire(stopID)->getBeginLanePosition();
      67              : }
      68              : 
      69              : double
      70           10 : OverheadWire::getEndPos(const std::string& stopID) {
      71           10 :     return getOverheadWire(stopID)->getEndLanePosition();
      72              : }
      73              : 
      74              : std::string
      75           10 : OverheadWire::getName(const std::string& stopID) {
      76           10 :     return getOverheadWire(stopID)->getMyName();
      77              : }
      78              : 
      79              : int
      80          100 : OverheadWire::getVehicleCount(const std::string& stopID) {
      81          100 :     MSOverheadWire* wire = dynamic_cast<MSOverheadWire*>(getOverheadWire(stopID));
      82          100 :     return (int)wire->getChargingVehicles().size();
      83              : }
      84              : 
      85              : std::vector<std::string>
      86          100 : OverheadWire::getVehicleIDs(const std::string& stopID) {
      87          100 :     MSOverheadWire* wire = dynamic_cast<MSOverheadWire*>(getOverheadWire(stopID));
      88              :     std::vector<std::string> result;
      89          195 :     for (const SUMOVehicle* veh : wire->getChargingVehicles()) {
      90           95 :         result.push_back(veh->getID());
      91              :     }
      92          100 :     return result;
      93            0 : }
      94              : 
      95              : 
      96              : 
      97              : std::string
      98            0 : OverheadWire::getParameter(const std::string& stopID, const std::string& param) {
      99            0 :     const MSStoppingPlace* s = getOverheadWire(stopID);
     100            0 :     return s->getParameter(param, "");
     101              : }
     102              : 
     103            0 : LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(OverheadWire)
     104              : 
     105              : void
     106            0 : OverheadWire::setParameter(const std::string& stopID, const std::string& key, const std::string& value) {
     107            0 :     MSStoppingPlace* s = getOverheadWire(stopID);
     108            0 :     s->setParameter(key, value);
     109            0 : }
     110              : 
     111              : 
     112            0 : LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(OverheadWire, OVERHEADWIRE)
     113              : 
     114              : 
     115              : MSStoppingPlace*
     116          240 : OverheadWire::getOverheadWire(const std::string& id) {
     117          240 :     MSStoppingPlace* s = MSNet::getInstance()->getStoppingPlace(id, SUMO_TAG_OVERHEAD_WIRE_SEGMENT);
     118          240 :     if (s == nullptr) {
     119            0 :         throw TraCIException("OverheadWire '" + id + "' is not known");
     120              :     }
     121          240 :     return s;
     122              : }
     123              : 
     124              : 
     125              : std::shared_ptr<VariableWrapper>
     126          264 : OverheadWire::makeWrapper() {
     127          264 :     return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
     128              : }
     129              : 
     130              : 
     131              : bool
     132          282 : OverheadWire::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
     133          282 :     switch (variable) {
     134          135 :         case TRACI_ID_LIST:
     135          135 :             return wrapper->wrapStringList(objID, variable, getIDList());
     136            3 :         case ID_COUNT:
     137            3 :             return wrapper->wrapInt(objID, variable, getIDCount());
     138            6 :         case VAR_LANE_ID:
     139           12 :             return wrapper->wrapString(objID, variable, getLaneID(objID));
     140            6 :         case VAR_POSITION:
     141            6 :             return wrapper->wrapDouble(objID, variable, getStartPos(objID));
     142            6 :         case VAR_LANEPOSITION:
     143            6 :             return wrapper->wrapDouble(objID, variable, getEndPos(objID));
     144            6 :         case VAR_NAME:
     145           12 :             return wrapper->wrapString(objID, variable, getName(objID));
     146           60 :         case VAR_STOP_STARTING_VEHICLES_NUMBER:
     147           60 :             return wrapper->wrapInt(objID, variable, getVehicleCount(objID));
     148           60 :         case VAR_STOP_STARTING_VEHICLES_IDS:
     149           60 :             return wrapper->wrapStringList(objID, variable, getVehicleIDs(objID));
     150            0 :         case libsumo::VAR_PARAMETER:
     151            0 :             paramData->readUnsignedByte();
     152            0 :             return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
     153            0 :         case libsumo::VAR_PARAMETER_WITH_KEY:
     154            0 :             paramData->readUnsignedByte();
     155            0 :             return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
     156              :         default:
     157              :             return false;
     158              :     }
     159              : }
     160              : 
     161              : }
     162              : 
     163              : 
     164              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1