/****************************************************************************/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 Named.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @date Sept 200217///18// Base class for objects which have an id.19/****************************************************************************/20#pragma once21#include <config.h>22#include <iostream>23#include <string>24#include <set>252627/// @brief Function-object for stable sorting of objects acting like Named without being derived (SUMOVehicle)28// @note Numbers of different lengths will not be ordered by alphanumerical sorting29struct ComparatorIdLess {30template<class T>31bool operator()(const T* const a, const T* const b) const {32return a->getID() < b->getID();33}34};353637/// @brief Function-object for stable sorting of objects with numerical ids38struct ComparatorNumericalIdLess {39template<class T>40bool operator()(const T* const a, const T* const b) const {41return a->getNumericalID() < b->getNumericalID();42}43};444546// ===========================================================================47// class definitions48// ===========================================================================49/**50* @class Named51* @brief Base class for objects which have an id.52*/53class Named {54public:55/** @brief Constructor56* @param[in] id The id of the object57*/58Named(const std::string& id) : myID(id) { }596061/// @brief Destructor62virtual ~Named() { }6364/// @brief get an identifier for Named-like object which may be Null65template<class T>66static std::string getIDSecure(const T* obj, const std::string& fallBack = "NULL") {67return obj == 0 ? fallBack : obj->getID();68}6970/** @brief Returns the id71* @return The stored id72*/73const std::string& getID() const {74return myID;75}767778/** @brief resets the id79* @param[in] newID The new id of this object80*/81virtual void setID(const std::string& newID) {82myID = newID;83}848586/** @class StoringVisitor87* @brief Allows to store the object; used as context while traveling the rtree in TraCI88*/89class StoringVisitor {90public:91/// @brief Constructor92StoringVisitor(std::set<const Named*>& objects) : myObjects(objects) {}9394/// @brief Destructor95~StoringVisitor() {}9697/// @brief Adds the given object to the container98void add(const Named* const o) const {99myObjects.insert(o);100}101102/// @brief The container103std::set<const Named*>& myObjects;104105private:106/// @brief invalidated copy constructor107StoringVisitor(const StoringVisitor& src);108109/// @brief invalidated assignment operator110StoringVisitor& operator=(const StoringVisitor& src);111};112113114/** @brief Adds this object to the given container115* @param[in, filled] cont The container to add this item to116*/117void addTo(const StoringVisitor& cont) const {118cont.add(this);119}120121122protected:123/// @brief The name of the object124std::string myID;125126};127128129