LCOV - code coverage report
Current view: top level - src/utils/gui/globjects - GUIGlObjectStorage.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 95.7 % 47 45
Test Date: 2025-12-06 15:35:27 Functions: 90.0 % 10 9

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2025 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    GUIGlObjectStorage.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @date    Sept 2002
      19              : ///
      20              : // A storage for displayed objects via their numerical id
      21              : /****************************************************************************/
      22              : #include <config.h>
      23              : 
      24              : #include <cassert>
      25              : #include <utils/foxtools/fxheader.h>
      26              : #include "GUIGlObject.h"
      27              : #include "GUIGlObjectStorage.h"
      28              : 
      29              : 
      30              : // ===========================================================================
      31              : // static variables (instances in this case)
      32              : // ===========================================================================
      33              : GUIGlObjectStorage GUIGlObjectStorage::gIDStorage;
      34              : 
      35              : 
      36              : // ===========================================================================
      37              : // method definitions
      38              : // ===========================================================================
      39         8612 : GUIGlObjectStorage::GUIGlObjectStorage() :
      40         8612 :     myNextID(1),
      41         8612 :     myLock(true) {
      42         8612 :     myObjects.push_back(nullptr);
      43         8612 : }
      44              : 
      45              : 
      46        17224 : GUIGlObjectStorage::~GUIGlObjectStorage() {}
      47              : 
      48              : 
      49              : GUIGlID
      50      1682139 : GUIGlObjectStorage::registerObject(GUIGlObject* object) {
      51      1682139 :     FXMutexLock locker(myLock);
      52      1682139 :     const GUIGlID id = myNextID;
      53      1682139 :     if (id == myObjects.size()) {
      54      1136721 :         myObjects.push_back(object);
      55              :     } else {
      56       545418 :         myObjects[id] = object;
      57              :     }
      58     36303722 :     while (myNextID < myObjects.size() && myObjects[myNextID] != nullptr) {
      59     34621583 :         myNextID++;
      60              :     }
      61      1682139 :     return id;
      62              : }
      63              : 
      64              : 
      65              : void
      66      1682139 : GUIGlObjectStorage::changeName(GUIGlObject* object, const std::string& fullName) {
      67      1682139 :     FXMutexLock locker(myLock);
      68              :     myFullNameMap.erase(object->getFullName());
      69      1682139 :     myFullNameMap[fullName] = object;
      70      1682139 : }
      71              : 
      72              : 
      73              : GUIGlObject*
      74          530 : GUIGlObjectStorage::getObjectBlocking(GUIGlID id) const {
      75          530 :     FXMutexLock locker(myLock);
      76          530 :     if (id < myObjects.size() && myObjects[id] != nullptr) {
      77              :         GUIGlObject* const o = myObjects[id];
      78              :         o->setBlocked();
      79          530 :         return o;
      80              :     }
      81              :     return nullptr;
      82              : }
      83              : 
      84              : 
      85              : GUIGlObject*
      86        64240 : GUIGlObjectStorage::getObjectBlocking(const std::string& fullName) const {
      87        64240 :     FXMutexLock locker(myLock);
      88              :     auto findIt = myFullNameMap.find(fullName);
      89        64240 :     if (findIt != myFullNameMap.end()) {
      90        29330 :         GUIGlObject* const o = findIt->second;
      91              :         o->setBlocked();
      92        29330 :         return o;
      93              :     }
      94              :     return nullptr;
      95              : }
      96              : 
      97              : 
      98              : bool
      99      1679294 : GUIGlObjectStorage::remove(GUIGlID id) {
     100      1679294 :     FXMutexLock locker(myLock);
     101              :     assert(id < myObjects.size() && myObjects[id] != nullptr);
     102      1679294 :     myFullNameMap.erase(myObjects[id]->getFullName());
     103      1679294 :     const bool wasBlocked = myObjects[id]->isBlocked();
     104      1679294 :     myObjects[id] = nullptr;
     105      1679294 :     if (id < myNextID) {
     106       326023 :         myNextID = id;
     107              :     }
     108      1679294 :     return !wasBlocked;
     109              : }
     110              : 
     111              : 
     112              : void
     113        39550 : GUIGlObjectStorage::clear() {
     114        39550 :     FXMutexLock locker(myLock);
     115              :     myObjects.clear();
     116        39550 :     myObjects.push_back(nullptr);
     117              :     myFullNameMap.clear();
     118        39550 :     myNextID = 1;
     119        39550 : }
     120              : 
     121              : 
     122              : void
     123        29842 : GUIGlObjectStorage::unblockObject(GUIGlID id) {
     124        29842 :     FXMutexLock locker(myLock);
     125        29842 :     if (id < myObjects.size() && myObjects[id] != nullptr) {
     126              :         myObjects[id]->setBlocked(false);
     127              :     }
     128        29842 : }
     129              : 
     130              : 
     131              : const std::vector<GUIGlObject*>&
     132            0 : GUIGlObjectStorage::getAllGLObjects() const {
     133            0 :     return myObjects;
     134              : }
     135              : 
     136              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1