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