/****************************************************************************/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 GNEReferenceCounter.h14/// @author Jakob Erdmann15/// @date Mar 201116///17// A class that counts references to itself18// We may wish to keep references to junctions/nodes either in the network or in the undoList19// to clean up properly we have to resort to reference counting20/****************************************************************************/21#pragma once22#include <config.h>2324#include <utils/common/MsgHandler.h>25#include <utils/common/StdDefs.h>262728// ===========================================================================29// class definitions30// ===========================================================================31/**32* @class GNEReferenceCounter33*/34class GNEReferenceCounter {35public:36//// @brief constructor37GNEReferenceCounter() : myCount(0) {}3839/// @brief return ID of object40virtual const std::string getID() const = 0;4142//// @brief destructor43virtual ~GNEReferenceCounter() {44// If myCount is different of 0, means that references weren't removed correctly45if (myCount != 0) {46// cannot print id here, it already got destructed47WRITE_ERROR("Attempt to delete instance of GNEReferenceCounter with count " + toString(myCount));48}49}5051/// @brief Decrease reference52void decRef(const std::string& debugMsg = "") {53// debugMsg only used for print debugging54#ifdef _DEBUG_REFERENCECOUNTER55std::cout << "decRef (" + toString(myCount) + ") for " + getID() + ": " << debugMsg << "\n";56#else57UNUSED_PARAMETER(debugMsg);58#endif59// write error if decrement results into a negative count60if (myCount < 1) {61WRITE_ERROR("Attempt to decrement references below zero for instance of GNEReferenceCounter");62}63myCount--;64}6566/// @brief Increase reference67void incRef(const std::string& debugMsg = "") {68// debugMsg only used for print debugging69#ifdef _DEBUG_REFERENCECOUNTER70std::cout << "incRef (" + toString(myCount) + ") for " + getID() + ": " << debugMsg << "\n";71#else72UNUSED_PARAMETER(debugMsg);73#endif74myCount++;75}7677/// @brief check if object ins't referenced78bool unreferenced() {79return myCount == 0;80}8182private:83/// @brief reference counter84int myCount;85};868788