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 /****************************************************************************/ 10 /// @file NBConnection.h 11 /// @author Daniel Krajzewicz 12 /// @author Jakob Erdmann 13 /// @author Sascha Krieg 14 /// @date Sept 2002 15 /// @version $Id$ 16 /// 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 // =========================================================================== 41 /** 42 * @class NBConnection 43 */ 44 class NBConnection { 45 public: 46 /// @brief Constructor 47 NBConnection(NBEdge* from, NBEdge* to); 48 49 /// @brief Constructor 50 NBConnection(NBEdge* from, int fromLane, NBEdge* to, int toLane, int tlIndex = InvalidTlIndex); 51 52 /// @brief Constructor 53 NBConnection(const std::string& fromID, NBEdge* from, 54 const std::string& toID, NBEdge* to); 55 56 /// @brief Constructor 57 NBConnection(const NBConnection& c); 58 59 /// @brief Destructor 60 virtual ~NBConnection(); 61 62 /// @brief returns the from-edge (start of the connection) 63 NBEdge* getFrom() const; 64 65 /// @brief returns the to-edge (end of the connection) 66 NBEdge* getTo() const; 67 68 /// @brief replaces the from-edge by the one given 69 bool replaceFrom(NBEdge* which, NBEdge* by); 70 71 /// @brief replaces the from-edge by the one given 72 bool replaceFrom(NBEdge* which, int whichLane, NBEdge* by, int byLane); 73 74 /// @brief replaces the to-edge by the one given 75 bool replaceTo(NBEdge* which, NBEdge* by); 76 77 /// @brief replaces the to-edge by the one given 78 bool replaceTo(NBEdge* which, int whichLane, NBEdge* by, int byLane); 79 80 /** @brief patches lane indices refering to the given edge and above the 81 * threshold by the given offset */ 82 void shiftLaneIndex(NBEdge* edge, int offset, int threshold = -1); 83 84 /// @brief checks whether the edges are still valid 85 bool check(const NBEdgeCont& ec); 86 87 /// @brief returns the from-lane 88 int getFromLane() const; 89 90 /// @brief returns the to-lane 91 int getToLane() const; 92 93 /// @brief returns the index within the controlling tls or InvalidTLIndex if this link is unontrolled getTLIndex()94 int getTLIndex() const { 95 return myTlIndex; 96 } 97 98 // @brief reset the tlIndex setTLIndex(int tlIndex)99 void setTLIndex(int tlIndex) { 100 myTlIndex = tlIndex; 101 } 102 103 /// @brief returns the id of the connection (!!! not really pretty) 104 std::string getID() const; 105 106 /// @brief Compares both connections in order to allow sorting 107 friend bool operator<(const NBConnection& c1, const NBConnection& c2); 108 109 /// @brief Comparison operator 110 bool operator==(const NBConnection& c) const; 111 112 /// @brief Comparison operator 113 bool operator!=(const NBConnection& c) const { 114 return !(*this == c); 115 } 116 117 /// @brief Output operator 118 friend std::ostream& operator<<(std::ostream& os, const NBConnection& c); 119 120 const static int InvalidTlIndex; 121 const static NBConnection InvalidConnection; 122 123 private: 124 /// @brief Checks whether the from-edge is still valid 125 NBEdge* checkFrom(const NBEdgeCont& ec); 126 127 /// @brief Checks whether the to-edge is still valid 128 NBEdge* checkTo(const NBEdgeCont& ec); 129 130 private: 131 /// @brief The from- and the to-edges 132 NBEdge* myFrom, *myTo; 133 134 /// @brief The names of both edges, needed for verification of validity 135 std::string myFromID, myToID; 136 137 /// @brief The lanes; may be -1 if no certain lane was specified 138 int myFromLane, myToLane; 139 140 // @brief the index within the controlling tls if this connection is tls-controlled 141 int myTlIndex; 142 }; 143 144 145 #endif 146 147 /****************************************************************************/ 148 149