MSBitSetLogic.h
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef MSBitSetLogic_h
00020 #define MSBitSetLogic_h
00021
00022
00023
00024
00025
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031
00032 #include <bitset>
00033 #include <vector>
00034 #include <cassert>
00035 #include "MSJunctionLogic.h"
00036 #include "MSLogicJunction.h"
00037
00038
00039
00040
00041
00047 template< size_t N >
00048 class MSBitSetLogic : public MSJunctionLogic {
00049 public:
00056 typedef std::vector< std::bitset< N > > Logic;
00057
00060 typedef std::vector< std::bitset< N > > Foes;
00061
00062
00063 public:
00065 MSBitSetLogic(unsigned int nLinks,
00066 unsigned int nInLanes,
00067 Logic* logic,
00068 Foes *foes,
00069 std::bitset<64> conts)
00070 : MSJunctionLogic(nLinks, nInLanes), myLogic(logic),
00071 myInternalLinksFoes(foes), myConts(conts) {}
00072
00073
00075 ~MSBitSetLogic() {
00076 delete myLogic;
00077 delete myInternalLinksFoes;
00078 }
00079
00080
00082 void respond(const MSLogicJunction::Request& request,
00083 const MSLogicJunction::InnerState& innerState,
00084 MSLogicJunction::Respond& respond) const {
00085 size_t i;
00086
00087 for (i = 0; i < myNLinks; ++i) {
00088 if (myConts.test(i)) {
00089 respond.set(i, request.test(i));
00090 } else {
00091 bool linkPermit = request.test(i)
00092 &&
00093 ((request&(*myLogic)[i]).none() || myConts.test(i));
00094 #ifdef HAVE_INTERNAL_LANES
00095 linkPermit &= (innerState&(*myInternalLinksFoes)[i]).none();
00096 #endif
00097 respond.set(i, linkPermit);
00098 }
00099 }
00100 }
00101
00102
00104 const MSLogicJunction::LinkFoes &getFoesFor(unsigned int linkIndex) const throw() {
00105 return (*myLogic)[linkIndex];
00106 }
00107
00108 const std::bitset<64> &getInternalFoesFor(unsigned int linkIndex) const throw() {
00109 return (*myInternalLinksFoes)[linkIndex];
00110 }
00111
00112 bool getIsCont(unsigned int linkIndex) const throw() {
00113 return myConts.test(linkIndex);
00114 }
00115
00116 virtual bool isCrossing() const throw() {
00117 for (typename Logic::const_iterator i=myLogic->begin(); i!=myLogic->end(); ++i) {
00118 if ((*i).any()) {
00119 return true;
00120 }
00121 }
00122 return false;
00123 }
00124
00125 private:
00127 Logic* myLogic;
00128
00130 Foes *myInternalLinksFoes;
00131
00132 std::bitset<64> myConts;
00133
00134 private:
00136 MSBitSetLogic(const MSBitSetLogic&);
00137
00139 MSBitSetLogic& operator=(const MSBitSetLogic&);
00140
00141 };
00142
00143
00147 typedef MSBitSetLogic< 64 > MSBitsetLogic;
00148
00149
00150 #endif
00151
00152
00153