SUMO - Simulation of Urban MObility
MSBitSetLogic.h
Go to the documentation of this file.
1 /****************************************************************************/
10 // Container for holding a right-of-way matrix
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 #ifndef MSBitSetLogic_h
24 #define MSBitSetLogic_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <bitset>
37 #include <vector>
38 #include "MSJunctionLogic.h"
39 #include "MSLogicJunction.h"
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
50 template< size_t N >
52 public:
59  typedef std::vector< std::bitset< N > > Logic;
60 
63  typedef std::vector< std::bitset< N > > Foes;
64 
65 
66 public:
68  MSBitSetLogic(unsigned int nLinks,
69  Logic* logic,
70  Foes* foes,
71  std::bitset<SUMO_MAX_CONNECTIONS> conts)
72  : MSJunctionLogic(nLinks), myLogic(logic),
73  myInternalLinksFoes(foes), myConts(conts) {}
74 
75 
78  delete myLogic;
79  delete myInternalLinksFoes;
80  }
81 
82 
84  const MSLogicJunction::LinkBits& getResponseFor(unsigned int linkIndex) const {
85  return (*myLogic)[linkIndex];
86  }
87 
89  const MSLogicJunction::LinkBits& getFoesFor(unsigned int linkIndex) const {
90  return (*myInternalLinksFoes)[linkIndex];
91  }
92 
93  bool getIsCont(unsigned int linkIndex) const {
94  return myConts.test(linkIndex);
95  }
96 
97  virtual bool hasFoes() const {
98  for (typename Logic::const_iterator i = myLogic->begin(); i != myLogic->end(); ++i) {
99  if ((*i).any()) {
100  return true;
101  }
102  }
103  return false;
104  }
105 
106 private:
108  Logic* myLogic;
109 
112 
113  std::bitset<SUMO_MAX_CONNECTIONS> myConts;
114 
115 private:
118 
121 
122 };
123 
124 
129 
130 
131 #endif
132 
133 /****************************************************************************/
134 
unsigned int nLinks()
Returns the logic&#39;s number of links.
virtual bool hasFoes() const
Definition: MSBitSetLogic.h:97
Logic * myLogic
junctions logic based on std::bitset
const MSLogicJunction::LinkBits & getResponseFor(unsigned int linkIndex) const
Returns the response for the given link.
Definition: MSBitSetLogic.h:84
bool getIsCont(unsigned int linkIndex) const
Definition: MSBitSetLogic.h:93
MSBitSetLogic< SUMO_MAX_CONNECTIONS > MSBitsetLogic
~MSBitSetLogic()
Destructor.
Definition: MSBitSetLogic.h:77
MSBitSetLogic & operator=(const MSBitSetLogic &)
Invalidated assignment operator.
const MSLogicJunction::LinkBits & getFoesFor(unsigned int linkIndex) const
Returns the foes for the given link.
Definition: MSBitSetLogic.h:89
std::vector< std::bitset< N > > Foes
Container holding the information which internal lanes prohibt which links Build the same way as Logi...
Definition: MSBitSetLogic.h:63
std::bitset< SUMO_MAX_CONNECTIONS > myConts
std::vector< std::bitset< N > > Logic
Container that holds the right of way bitsets. Each link has it&#39;s own bitset. The bits in the bitsets...
Definition: MSBitSetLogic.h:59
Foes * myInternalLinksFoes
internal lanes logic
MSBitSetLogic(unsigned int nLinks, Logic *logic, Foes *foes, std::bitset< SUMO_MAX_CONNECTIONS > conts)
Use this constructor only.
Definition: MSBitSetLogic.h:68
std::bitset< SUMO_MAX_CONNECTIONS > LinkBits
Container for link response and foes.