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 MSBitSetLogic.h 11 /// @author Christian Roessel 12 /// @author Daniel Krajzewicz 13 /// @author Sascha Krieg 14 /// @author Michael Behrisch 15 /// @date Wed, 12 Dez 2001 16 /// @version $Id$ 17 /// 18 // Container for holding a right-of-way matrix 19 /****************************************************************************/ 20 #ifndef MSBitSetLogic_h 21 #define MSBitSetLogic_h 22 23 24 // =========================================================================== 25 // included modules 26 // =========================================================================== 27 #include <config.h> 28 29 #include <bitset> 30 #include <vector> 31 #include "MSJunctionLogic.h" 32 #include "MSLogicJunction.h" 33 34 35 // =========================================================================== 36 // class definitions 37 // =========================================================================== 38 /** 39 * @class MSBitSetLogic 40 * 41 * N is sum of the number of links of the junction's inLanes. 42 */ 43 template< int N > 44 class MSBitSetLogic : public MSJunctionLogic { 45 public: 46 /** @brief Container that holds the right of way bitsets. 47 Each link has it's own 48 bitset. The bits in the bitsets correspond to the links. To create 49 a bitset for a particular link, set the bits to true that correspond 50 to links that have the right of way. All others set to false, 51 including the link's "own" link-bit. */ 52 typedef std::vector< std::bitset< N > > Logic; 53 54 /** @brief Container holding the information which internal lanes prohibt which links 55 Build the same way as Logic */ 56 typedef std::vector< std::bitset< N > > Foes; 57 58 59 public: 60 /// Use this constructor only. MSBitSetLogic(int nLinks,Logic * logic,Foes * foes,std::bitset<SUMO_MAX_CONNECTIONS> conts)61 MSBitSetLogic(int nLinks, 62 Logic* logic, 63 Foes* foes, 64 std::bitset<SUMO_MAX_CONNECTIONS> conts) 65 : MSJunctionLogic(nLinks), myLogic(logic), 66 myInternalLinksFoes(foes), myConts(conts) {} 67 68 69 /// Destructor. ~MSBitSetLogic()70 ~MSBitSetLogic() { 71 delete myLogic; 72 delete myInternalLinksFoes; 73 } 74 75 76 /// @brief Returns the response for the given link getResponseFor(int linkIndex)77 const MSLogicJunction::LinkBits& getResponseFor(int linkIndex) const { 78 return (*myLogic)[linkIndex]; 79 } 80 81 /// @brief Returns the foes for the given link getFoesFor(int linkIndex)82 const MSLogicJunction::LinkBits& getFoesFor(int linkIndex) const { 83 return (*myInternalLinksFoes)[linkIndex]; 84 } 85 getIsCont(int linkIndex)86 bool getIsCont(int linkIndex) const { 87 return myConts.test(linkIndex); 88 } 89 hasFoes()90 virtual bool hasFoes() const { 91 for (typename Logic::const_iterator i = myLogic->begin(); i != myLogic->end(); ++i) { 92 if ((*i).any()) { 93 return true; 94 } 95 } 96 return false; 97 } 98 99 private: 100 /// junctions logic based on std::bitset 101 Logic* myLogic; 102 103 /// internal lanes logic 104 Foes* myInternalLinksFoes; 105 106 std::bitset<SUMO_MAX_CONNECTIONS> myConts; 107 108 private: 109 /// @brief Invalidated copy constructor. 110 MSBitSetLogic(const MSBitSetLogic&); 111 112 /// @brief Invalidated assignment operator. 113 MSBitSetLogic& operator=(const MSBitSetLogic&); 114 115 }; 116 117 118 /** To make things easier we use a fixed size. SUMO_MAX_CONNECTIONS will hopefully be sufficient even for 119 large asian junctions. 120 So, here comes the type which should be used by the netbuilder. */ 121 typedef MSBitSetLogic<SUMO_MAX_CONNECTIONS> MSBitsetLogic; 122 123 124 #endif 125 126 /****************************************************************************/ 127 128