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 /****************************************************************************/
17 // The class holds a description of a connection between two edges
18 /****************************************************************************/
19 #ifndef NBConnection_h
20 #define NBConnection_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <string>
29 #include "NBEdge.h"
30 
31 
32 // ===========================================================================
33 // class declarations
34 // ===========================================================================
35 class NBNode;
36 
37 
38 // ===========================================================================
39 // class definitions
40 // ===========================================================================
44 class NBConnection {
45 public:
47  NBConnection(NBEdge* from, NBEdge* to);
48 
50  NBConnection(NBEdge* from, int fromLane, NBEdge* to, int toLane, int tlIndex = InvalidTlIndex);
51 
53  NBConnection(const std::string& fromID, NBEdge* from,
54  const std::string& toID, NBEdge* to);
55 
57  NBConnection(const NBConnection& c);
58 
60  virtual ~NBConnection();
61 
63  NBEdge* getFrom() const;
64 
66  NBEdge* getTo() const;
67 
69  bool replaceFrom(NBEdge* which, NBEdge* by);
70 
72  bool replaceFrom(NBEdge* which, int whichLane, NBEdge* by, int byLane);
73 
75  bool replaceTo(NBEdge* which, NBEdge* by);
76 
78  bool replaceTo(NBEdge* which, int whichLane, NBEdge* by, int byLane);
79 
82  void shiftLaneIndex(NBEdge* edge, int offset, int threshold = -1);
83 
85  bool check(const NBEdgeCont& ec);
86 
88  int getFromLane() const;
89 
91  int getToLane() const;
92 
94  int getTLIndex() const {
95  return myTlIndex;
96  }
97 
98  // @brief reset the tlIndex
99  void setTLIndex(int tlIndex) {
100  myTlIndex = tlIndex;
101  }
102 
104  std::string getID() const;
105 
107  friend bool operator<(const NBConnection& c1, const NBConnection& c2);
108 
110  bool operator==(const NBConnection& c) const;
111 
113  bool operator!=(const NBConnection& c) const {
114  return !(*this == c);
115  }
116 
118  friend std::ostream& operator<<(std::ostream& os, const NBConnection& c);
119 
120  const static int InvalidTlIndex;
122 
123 private:
125  NBEdge* checkFrom(const NBEdgeCont& ec);
126 
128  NBEdge* checkTo(const NBEdgeCont& ec);
129 
130 private:
133 
135  std::string myFromID, myToID;
136 
139 
140  // @brief the index within the controlling tls if this connection is tls-controlled
142 };
143 
144 
145 #endif
146 
147 /****************************************************************************/
148 
NBConnection::operator==
bool operator==(const NBConnection &c) const
Comparison operator.
Definition: NBConnection.cpp:181
NBConnection::InvalidConnection
const static NBConnection InvalidConnection
Definition: NBConnection.h:121
NBConnection::getTLIndex
int getTLIndex() const
returns the index within the controlling tls or InvalidTLIndex if this link is unontrolled
Definition: NBConnection.h:94
NBEdgeCont
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:61
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:242
NBConnection::myToID
std::string myToID
Definition: NBConnection.h:135
NBConnection::operator!=
bool operator!=(const NBConnection &c) const
Comparison operator.
Definition: NBConnection.h:113
NBConnection::getFrom
NBEdge * getFrom() const
returns the from-edge (start of the connection)
Definition: NBConnection.cpp:86
NBConnection::InvalidTlIndex
const static int InvalidTlIndex
Definition: NBConnection.h:120
NBConnection::getTo
NBEdge * getTo() const
returns the to-edge (end of the connection)
Definition: NBConnection.cpp:92
NBConnection::checkTo
NBEdge * checkTo(const NBEdgeCont &ec)
Checks whether the to-edge is still valid.
Definition: NBConnection.cpp:210
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:86
NBConnection::myFromID
std::string myFromID
The names of both edges, needed for verification of validity.
Definition: NBConnection.h:135
NBConnection::myFrom
NBEdge * myFrom
The from- and the to-edges.
Definition: NBConnection.h:132
NBConnection::getID
std::string getID() const
returns the id of the connection (!!! not really pretty)
Definition: NBConnection.cpp:222
NBConnection::setTLIndex
void setTLIndex(int tlIndex)
Definition: NBConnection.h:99
NBConnection::~NBConnection
virtual ~NBConnection()
Destructor.
Definition: NBConnection.cpp:74
NBConnection::getToLane
int getToLane() const
returns the to-lane
Definition: NBConnection.cpp:236
NBConnection::operator<<
friend std::ostream & operator<<(std::ostream &os, const NBConnection &c)
Output operator.
Definition: NBConnection.cpp:252
NBConnection::operator<
friend bool operator<(const NBConnection &c1, const NBConnection &c2)
Compares both connections in order to allow sorting.
Definition: NBConnection.cpp:166
NBConnection
Definition: NBConnection.h:44
NBConnection::myFromLane
int myFromLane
The lanes; may be -1 if no certain lane was specified.
Definition: NBConnection.h:138
NBConnection::replaceFrom
bool replaceFrom(NBEdge *which, NBEdge *by)
replaces the from-edge by the one given
Definition: NBConnection.cpp:98
NBConnection::myTo
NBEdge * myTo
Definition: NBConnection.h:132
NBConnection::NBConnection
NBConnection(NBEdge *from, NBEdge *to)
Constructor.
Definition: NBConnection.cpp:43
NBConnection::checkFrom
NBEdge * checkFrom(const NBEdgeCont &ec)
Checks whether the from-edge is still valid.
Definition: NBConnection.cpp:198
NBConnection::check
bool check(const NBEdgeCont &ec)
checks whether the edges are still valid
Definition: NBConnection.cpp:190
NBConnection::replaceTo
bool replaceTo(NBEdge *which, NBEdge *by)
replaces the to-edge by the one given
Definition: NBConnection.cpp:132
config.h
NBNode
Represents a single node (junction) during network building.
Definition: NBNode.h:68
NBConnection::getFromLane
int getFromLane() const
returns the from-lane
Definition: NBConnection.cpp:230
NBConnection::myToLane
int myToLane
Definition: NBConnection.h:138
NBEdge.h
NBConnection::myTlIndex
int myTlIndex
Definition: NBConnection.h:141