SUMO - Simulation of Urban MObility
Named.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // Base class for objects which have an id.
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 #ifndef Named_h
22 #define Named_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <set>
36 
37 
38 // ===========================================================================
39 // class definitions
40 // ===========================================================================
45 class Named {
46 public:
50  Named(const std::string& id) : myID(id) { }
51 
52 
54  virtual ~Named() { }
55 
56 
60  const std::string& getID() const {
61  return myID;
62  }
63 
64 
68  void setID(const std::string& newID) {
69  myID = newID;
70  }
71 
72 
75  bool operator()(Named* const a, Named* const b) const {
76  return a->getID() < b->getID();
77  }
78  };
79 
81  template <class NamedLike>
83  bool operator()(const NamedLike* const a, const NamedLike* const b) const {
84  return a->getID() < b->getID();
85  }
86  };
87 
88 
93  public:
95  StoringVisitor(std::set<std::string>& ids) : myIDs(ids) {}
96 
99 
101  void add(const Named* const o) const {
102  myIDs.insert(o->getID());
103  }
104 
106  std::set<std::string>& myIDs;
107 
108  private:
110  StoringVisitor(const StoringVisitor& src);
111 
114  };
115 
116 
117 
121  void addTo(const StoringVisitor& cont) const {
122  cont.add(this);
123  }
124 
125 
126 protected:
128  std::string myID;
129 
130 };
131 
132 
133 #endif
134 
135 /****************************************************************************/
136 
virtual ~Named()
Destructor.
Definition: Named.h:54
Function-object for stable sorting of objects acting like Named without being derived (SUMOVehicle) ...
Definition: Named.h:82
bool operator()(const NamedLike *const a, const NamedLike *const b) const
Definition: Named.h:83
~StoringVisitor()
Destructor.
Definition: Named.h:98
StoringVisitor & operator=(const StoringVisitor &src)
invalidated assignment operator
const std::string & getID() const
Returns the id.
Definition: Named.h:60
StoringVisitor(std::set< std::string > &ids)
Contructor.
Definition: Named.h:95
void addTo(const StoringVisitor &cont) const
Adds this object to the given container.
Definition: Named.h:121
Named(const std::string &id)
Constructor.
Definition: Named.h:50
void add(const Named *const o) const
Adds the given object to the container.
Definition: Named.h:101
Base class for objects which have an id.
Definition: Named.h:45
bool operator()(Named *const a, Named *const b) const
Definition: Named.h:75
Allows to store the object; used as context while traveling the rtree in TraCI.
Definition: Named.h:92
std::string myID
The name of the object.
Definition: Named.h:128
void setID(const std::string &newID)
resets the id
Definition: Named.h:68
std::set< std::string > & myIDs
The container.
Definition: Named.h:106
Function-object for stable sorting in containers.
Definition: Named.h:74