Eclipse SUMO - Simulation of Urban MObility
NBConnection.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // The class holds a description of a connection between two edges
17 /****************************************************************************/
18 #ifndef NBConnection_h
19 #define NBConnection_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <string>
28 #include "NBEdge.h"
29 
30 
31 // ===========================================================================
32 // class declarations
33 // ===========================================================================
34 class NBNode;
35 
36 
37 // ===========================================================================
38 // class definitions
39 // ===========================================================================
43 class NBConnection {
44 public:
46  NBConnection(NBEdge* from, NBEdge* to);
47 
49  NBConnection(NBEdge* from, int fromLane, NBEdge* to, int toLane, int tlIndex = InvalidTlIndex, int tlIndex2 = InvalidTlIndex);
50 
52  NBConnection(const std::string& fromID, NBEdge* from,
53  const std::string& toID, NBEdge* to);
54 
56  NBConnection(const NBConnection& c);
57 
59  virtual ~NBConnection();
60 
62  NBEdge* getFrom() const;
63 
65  NBEdge* getTo() const;
66 
68  bool replaceFrom(NBEdge* which, NBEdge* by);
69 
71  bool replaceFrom(NBEdge* which, int whichLane, NBEdge* by, int byLane);
72 
74  bool replaceTo(NBEdge* which, NBEdge* by);
75 
77  bool replaceTo(NBEdge* which, int whichLane, NBEdge* by, int byLane);
78 
81  void shiftLaneIndex(NBEdge* edge, int offset, int threshold = -1);
82 
84  bool check(const NBEdgeCont& ec);
85 
87  int getFromLane() const;
88 
90  int getToLane() const;
91 
93  int getTLIndex() const {
94  return myTlIndex;
95  }
96  int getTLIndex2() const {
97  return myTlIndex2;
98  }
99 
100  // @brief reset the tlIndex
101  void setTLIndex(int tlIndex) {
102  myTlIndex = tlIndex;
103  }
104  void setTLIndex2(int tlIndex) {
105  myTlIndex2 = tlIndex;
106  }
107 
109  std::string getID() const;
110 
112  friend bool operator<(const NBConnection& c1, const NBConnection& c2);
113 
115  bool operator==(const NBConnection& c) const;
116 
118  bool operator!=(const NBConnection& c) const {
119  return !(*this == c);
120  }
121 
123  friend std::ostream& operator<<(std::ostream& os, const NBConnection& c);
124 
125  const static int InvalidTlIndex;
127 
128 private:
130  NBEdge* checkFrom(const NBEdgeCont& ec);
131 
133  NBEdge* checkTo(const NBEdgeCont& ec);
134 
135 private:
138 
140  std::string myFromID, myToID;
141 
144 
145  // @brief the index within the controlling tls if this connection is tls-controlled
149 };
150 
151 
152 #endif
153 
154 /****************************************************************************/
155 
NBConnection::operator==
bool operator==(const NBConnection &c) const
Comparison operator.
Definition: NBConnection.cpp:184
NBConnection::InvalidConnection
static const NBConnection InvalidConnection
Definition: NBConnection.h:126
NBConnection::getTLIndex
int getTLIndex() const
returns the index within the controlling tls or InvalidTLIndex if this link is unontrolled
Definition: NBConnection.h:93
NBEdgeCont
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:60
NBConnection::shiftLaneIndex
void shiftLaneIndex(NBEdge *edge, int offset, int threshold=-1)
patches lane indices refering to the given edge and above the threshold by the given offset
Definition: NBConnection.cpp:246
NBConnection::myToID
std::string myToID
Definition: NBConnection.h:140
NBConnection::operator!=
bool operator!=(const NBConnection &c) const
Comparison operator.
Definition: NBConnection.h:118
NBConnection::getTLIndex2
int getTLIndex2() const
Definition: NBConnection.h:96
NBConnection::getFrom
NBEdge * getFrom() const
returns the from-edge (start of the connection)
Definition: NBConnection.cpp:89
NBConnection::InvalidTlIndex
static const int InvalidTlIndex
Definition: NBConnection.h:125
NBConnection::getTo
NBEdge * getTo() const
returns the to-edge (end of the connection)
Definition: NBConnection.cpp:95
NBConnection::checkTo
NBEdge * checkTo(const NBEdgeCont &ec)
Checks whether the to-edge is still valid.
Definition: NBConnection.cpp:214
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
NBConnection::myFromID
std::string myFromID
The names of both edges, needed for verification of validity.
Definition: NBConnection.h:140
NBConnection::myFrom
NBEdge * myFrom
The from- and the to-edges.
Definition: NBConnection.h:137
NBConnection::getID
std::string getID() const
returns the id of the connection (!!! not really pretty)
Definition: NBConnection.cpp:226
NBConnection::setTLIndex
void setTLIndex(int tlIndex)
Definition: NBConnection.h:101
NBConnection::~NBConnection
virtual ~NBConnection()
Destructor.
Definition: NBConnection.cpp:76
NBConnection::getToLane
int getToLane() const
returns the to-lane
Definition: NBConnection.cpp:240
NBConnection::myTlIndex2
int myTlIndex2
The index of the internal junction within the controlling traffic light (optional)
Definition: NBConnection.h:148
NBConnection::operator<<
friend std::ostream & operator<<(std::ostream &os, const NBConnection &c)
Output operator.
Definition: NBConnection.cpp:256
NBConnection::operator<
friend bool operator<(const NBConnection &c1, const NBConnection &c2)
Compares both connections in order to allow sorting.
Definition: NBConnection.cpp:169
NBConnection
Definition: NBConnection.h:43
NBConnection::myFromLane
int myFromLane
The lanes; may be -1 if no certain lane was specified.
Definition: NBConnection.h:143
NBConnection::replaceFrom
bool replaceFrom(NBEdge *which, NBEdge *by)
replaces the from-edge by the one given
Definition: NBConnection.cpp:101
NBConnection::myTo
NBEdge * myTo
Definition: NBConnection.h:137
NBConnection::NBConnection
NBConnection(NBEdge *from, NBEdge *to)
Constructor.
Definition: NBConnection.cpp:42
NBConnection::checkFrom
NBEdge * checkFrom(const NBEdgeCont &ec)
Checks whether the from-edge is still valid.
Definition: NBConnection.cpp:202
NBConnection::check
bool check(const NBEdgeCont &ec)
checks whether the edges are still valid
Definition: NBConnection.cpp:194
NBConnection::replaceTo
bool replaceTo(NBEdge *which, NBEdge *by)
replaces the to-edge by the one given
Definition: NBConnection.cpp:135
config.h
NBConnection::setTLIndex2
void setTLIndex2(int tlIndex)
Definition: NBConnection.h:104
NBNode
Represents a single node (junction) during network building.
Definition: NBNode.h:67
NBConnection::getFromLane
int getFromLane() const
returns the from-lane
Definition: NBConnection.cpp:234
NBConnection::myToLane
int myToLane
Definition: NBConnection.h:143
NBEdge.h
NBConnection::myTlIndex
int myTlIndex
Definition: NBConnection.h:146