Path: blob/main/src/utils/gui/globjects/GUIGlObjectStorage.h
169684 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GUIGlObjectStorage.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @date Oct 200218///19// A storage for displayed objects via their numerical id20/****************************************************************************/21#pragma once22#include <config.h>2324#include <map>25#include <string>26#include <set>27#include <utils/foxtools/fxheader.h>28#include "GUIGlObject.h"293031// ===========================================================================32// class definitions33// ===========================================================================34/**35* @class GUIGlObjectStorage36* @brief A storage for of displayed objects via their numerical id37*38* This is a container for GUIGlObject - objects, which may be displayed39* and due to this may generate tooltips or be grapped in other ways.40*41* As in case of vehicles (other, later implemented objects may have this42* property, too) they may be deleted by the simulation while being accessed43* - for example using a property window or something like that - this44* container posesses three storages: one containing all objects that are not45* accessed at all, one for objects currently accessed and one for objects that46* are accessed but shall be deleted.47*/48class GUIGlObjectStorage {49public:50/// @brief Constructor51GUIGlObjectStorage();525354/// @brief Destructor55~GUIGlObjectStorage();565758/** @brief Registers an object59*60* This is done within the constructor of the GUIGlObject.61* The next free id is calculated as well.62*63* @param[in] object The object to register64*/65GUIGlID registerObject(GUIGlObject* object);6667void changeName(GUIGlObject* object, const std::string& fullName);6869/** @brief Returns the object from the container locking it70*71* The lock prevents the object from being deleted while it is accessed.72*73* @param[in] id The id of the object to return74* @return The object with the given id or nullptr if no such object is known75*/76GUIGlObject* getObjectBlocking(GUIGlID id) const;7778/** @brief Returns the object from the container locking it79*80* The lock prevents the object from being deleted while it is accessed.81*82* @param[in] id The id of the object to return83* @return The object with the given id or nullptr if no such object is known84*/85GUIGlObject* getObjectBlocking(const std::string& fullName) const;8687/** @brief Removes the named object from this container88*89* This function returns true if the object may be deleted;90* otherwise it's kept in an internal storage (for visualisation etc.)91* and will be removed by this class92*93* @param[in] id The id of the object to remove94* @return Whether the object could be removed (and may be deleted)95*/96bool remove(GUIGlID id);9798/** @brief Clears this container99*100* The objects are not deleted.101*/102void clear();103104105/** @brief Marks an object as unblocked106*107* The object is moved from "myBlocked" to "myMap".108* @param[in] id The id of the object to unblock109*/110void unblockObject(GUIGlID id);111112113/** @brief Sets the given object as the "network" object114* @param[in] object The object to set as network object115*/116void setNetObject(GUIGlObject* object) {117myNetObject = object;118}119120/** @brief Returns the network object121* @return The network object122*/123GUIGlObject* getNetObject() const {124return myNetObject;125}126127/// @brief A single static instance of this class128static GUIGlObjectStorage gIDStorage;129130/// @brief Returns the set of all known objects131const std::vector<GUIGlObject*>& getAllGLObjects() const;132133private:134/// @brief The known objects135std::vector<GUIGlObject*> myObjects;136137/// @brief The known objects by their full name138std::map<std::string, GUIGlObject*> myFullNameMap;139140/// @brief The next id to give; initially one, increased by one with each object registration141GUIGlID myNextID;142143/// @brief A lock to avoid parallel access on the storages144mutable FXMutex myLock;145146/// @brief The network object147GUIGlObject* myNetObject;148149private:150/// @brief invalidated copy constructor151GUIGlObjectStorage(const GUIGlObjectStorage& s) = delete;152153/// @brief invalidate assignment operator154GUIGlObjectStorage& operator=(const GUIGlObjectStorage& s) = delete;155};156157158