Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
Named.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-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/****************************************************************************/
19// Base class for objects which have an id.
20/****************************************************************************/
21#pragma once
22#include <config.h>
23#include <iostream>
24#include <string>
25#include <set>
26
27
29// @note Numbers of different lengths will not be ordered by alphanumerical sorting
31 template<class T>
32 bool operator()(const T* const a, const T* const b) const {
33 return a->getID() < b->getID();
34 }
35};
36
37
40 template<class T>
41 bool operator()(const T* const a, const T* const b) const {
42 return a->getNumericalID() < b->getNumericalID();
43 }
44};
45
46
47// ===========================================================================
48// class definitions
49// ===========================================================================
54class Named {
55public:
59 Named(const std::string& id) : myID(id) { }
60
61
63 virtual ~Named() { }
64
66 template<class T>
67 static std::string getIDSecure(const T* obj, const std::string& fallBack = "NULL") {
68 return obj == 0 ? fallBack : obj->getID();
69 }
70
74 const std::string& getID() const {
75 return myID;
76 }
77
78
82 virtual void setID(const std::string& newID) {
83 myID = newID;
84 }
85
86
91 public:
93 StoringVisitor(std::set<const Named*>& objects) : myObjects(objects) {}
94
97
99 void add(const Named* const o) const {
100 myObjects.insert(o);
101 }
102
104 std::set<const Named*>& myObjects;
105
106 private:
109
112 };
113
114
118 void addTo(const StoringVisitor& cont) const {
119 cont.add(this);
120 }
121
122
123protected:
125 std::string myID;
126
127};
Allows to store the object; used as context while traveling the rtree in TraCI.
Definition Named.h:90
std::set< const Named * > & myObjects
The container.
Definition Named.h:104
void add(const Named *const o) const
Adds the given object to the container.
Definition Named.h:99
StoringVisitor(std::set< const Named * > &objects)
Constructor.
Definition Named.h:93
StoringVisitor & operator=(const StoringVisitor &src)
invalidated assignment operator
StoringVisitor(const StoringVisitor &src)
invalidated copy constructor
~StoringVisitor()
Destructor.
Definition Named.h:96
Base class for objects which have an id.
Definition Named.h:54
Named(const std::string &id)
Constructor.
Definition Named.h:59
std::string myID
The name of the object.
Definition Named.h:125
void addTo(const StoringVisitor &cont) const
Adds this object to the given container.
Definition Named.h:118
virtual void setID(const std::string &newID)
resets the id
Definition Named.h:82
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
Definition Named.h:67
const std::string & getID() const
Returns the id.
Definition Named.h:74
virtual ~Named()
Destructor.
Definition Named.h:63
Function-object for stable sorting of objects acting like Named without being derived (SUMOVehicle)
Definition Named.h:30
bool operator()(const T *const a, const T *const b) const
Definition Named.h:32
Function-object for stable sorting of objects with numerical ids.
Definition Named.h:39
bool operator()(const T *const a, const T *const b) const
Definition Named.h:41