#include <MSTLLogicControl.h>
This class joins all programs of a single tls.
Definition at line 83 of file MSTLLogicControl.h.
Public Member Functions | |
| void | addLink (MSLink *link, MSLane *lane, unsigned int pos) throw () |
| bool | addLogic (const std::string &subID, MSTrafficLightLogic *logic, bool netWasLoaded, bool isNewDefault=true) throw (ProcessError) |
| Adds a logic (program). | |
| void | addSwitchCommand (OnSwitchAction *c) |
| bool | checkOriginalTLS () const throw () |
| Verifies traffic lights loaded from the network. | |
| void | executeOnSwitchActions () const |
| MSTrafficLightLogic * | getActive () const |
| std::vector < MSTrafficLightLogic * > | getAllLogics () const |
| MSTrafficLightLogic * | getLogic (const std::string &subid) const |
| MSTrafficLightLogic * | getLogicInstantiatingOff (MSTLLogicControl &tlc, const std::string &subid) |
| bool | isActive (const MSTrafficLightLogic *tl) const |
| void | saveInitialStates () |
| bool | setTrafficLightSignals () |
| bool | switchTo (MSTLLogicControl &tlc, const std::string &subid) |
| TLSLogicVariants () throw () | |
| Constructor. | |
| ~TLSLogicVariants () throw () | |
| Destructor. | |
Private Member Functions | |
| TLSLogicVariants & | operator= (const TLSLogicVariants &) |
| Invalidated assignment operator. | |
| TLSLogicVariants (const TLSLogicVariants &) | |
| Invalidated copy constructor. | |
Private Attributes | |
| MSTrafficLightLogic * | myCurrentProgram |
| The currently used program. | |
| std::map< MSLink *, std::pair < MSLink::LinkState, bool > > | myOriginalLinkStates |
| Originally loaded link states. | |
| std::vector< OnSwitchAction * > | mySwitchActions |
| The list of actions/commands to execute on switch. | |
| std::map< std::string, MSTrafficLightLogic * > | myVariants |
| A map of subkeys to programs. | |
| MSTLLogicControl::TLSLogicVariants::TLSLogicVariants | ( | ) | throw () |
Constructor.
Definition at line 52 of file MSTLLogicControl.cpp.
00053 : myCurrentProgram(0) { 00054 }
| MSTLLogicControl::TLSLogicVariants::~TLSLogicVariants | ( | ) | throw () |
Destructor.
Definition at line 57 of file MSTLLogicControl.cpp.
References mySwitchActions, and myVariants.
00057 { 00058 std::map<std::string, MSTrafficLightLogic *>::const_iterator j; 00059 for (std::map<std::string, MSTrafficLightLogic *>::iterator j=myVariants.begin(); j!=myVariants.end(); ++j) { 00060 delete(*j).second; 00061 } 00062 for (std::vector<OnSwitchAction*>::iterator i=mySwitchActions.begin(); i!=mySwitchActions.end(); ++i) { 00063 delete *i; 00064 } 00065 }
| MSTLLogicControl::TLSLogicVariants::TLSLogicVariants | ( | const TLSLogicVariants & | ) | [private] |
Invalidated copy constructor.
| void MSTLLogicControl::TLSLogicVariants::addLink | ( | MSLink * | link, | |
| MSLane * | lane, | |||
| unsigned int | pos | |||
| ) | throw () |
Definition at line 211 of file MSTLLogicControl.cpp.
References myVariants.
Referenced by NLSucceedingLaneBuilder::addSuccLane().
00211 { 00212 for (std::map<std::string, MSTrafficLightLogic *>::iterator i=myVariants.begin(); i!=myVariants.end(); ++i) { 00213 (*i).second->addLink(link, lane, pos); 00214 } 00215 }
| bool MSTLLogicControl::TLSLogicVariants::addLogic | ( | const std::string & | subID, | |
| MSTrafficLightLogic * | logic, | |||
| bool | netWasLoaded, | |||
| bool | isNewDefault = true | |||
| ) | throw (ProcessError) |
Adds a logic (program).
| [in] | subID | The sub-id of this program |
| [in] | logic | The logic to add |
| [in] | netWasLoaded | Whether the network has already been loaded (the links have been assigned) |
| [in] | isNewDefault | Whether this logic shall be treated as the currently active logic |
Definition at line 96 of file MSTLLogicControl.cpp.
References myCurrentProgram, and myVariants.
Referenced by MSTLLogicControl::add(), getLogicInstantiatingOff(), and TraCIServerAPI_TLS::processSet().
00099 { 00100 if (myVariants.find(subID)!=myVariants.end()) { 00101 return false; 00102 } 00103 // assert the links are set 00104 if (netWasLoaded) { 00105 // this one has not yet its links set 00106 if (myCurrentProgram==0) { 00107 throw ProcessError("No initial signal plan loaded for tls '" + logic->getID() + "'."); 00108 } 00109 logic->adaptLinkInformationFrom(*myCurrentProgram); 00110 if (logic->getLinks().size()!=logic->getPhase(0).getState().size()) { 00111 throw ProcessError("Mismatching phase size in tls '" + logic->getID() + "', program '" + subID + "'."); 00112 } 00113 } 00114 // add to the list of active 00115 if (myVariants.size()==0||isNewDefault) { 00116 myCurrentProgram = logic; 00117 } 00118 // add to the list of logic 00119 myVariants[subID] = logic; 00120 logic->setLinkPriorities(); 00121 return true; 00122 }
| void MSTLLogicControl::TLSLogicVariants::addSwitchCommand | ( | OnSwitchAction * | c | ) |
Definition at line 154 of file MSTLLogicControl.cpp.
References mySwitchActions.
00154 { 00155 mySwitchActions.push_back(c); 00156 }
| bool MSTLLogicControl::TLSLogicVariants::checkOriginalTLS | ( | ) | const throw () |
Verifies traffic lights loaded from the network.
Comparse the phase state sizes of each phase with the accoring tls' number of controlled links.
Definition at line 69 of file MSTLLogicControl.cpp.
References MsgHandler::getErrorInstance(), MsgHandler::inform(), and myVariants.
00069 { 00070 bool hadErrors = false; 00071 for (std::map<std::string, MSTrafficLightLogic *>::const_iterator j=myVariants.begin(); j!=myVariants.end(); ++j) { 00072 const MSTrafficLightLogic::Phases &phases = (*j).second->getPhases(); 00073 unsigned int linkNo = (unsigned int)(*j).second->getLinks().size(); 00074 bool hadProgramErrors = false; 00075 for (MSTrafficLightLogic::Phases::const_iterator i=phases.begin(); i!=phases.end(); ++i) { 00076 if ((*i)->getState().length()!=linkNo) { 00077 hadProgramErrors = true; 00078 } 00079 } 00080 if (hadProgramErrors) { 00081 MsgHandler::getErrorInstance()->inform("Mismatching phase size in tls '" + (*j).second->getID() + "', program '" + (*j).first + "'."); 00082 hadErrors = true; 00083 } 00084 } 00085 return !hadErrors; 00086 }
| void MSTLLogicControl::TLSLogicVariants::executeOnSwitchActions | ( | ) | const |
Definition at line 202 of file MSTLLogicControl.cpp.
References mySwitchActions.
Referenced by MSTrafficLightLogic::SwitchCommand::execute().
00202 { 00203 for (std::vector<OnSwitchAction*>::const_iterator i=mySwitchActions.begin(); i!=mySwitchActions.end();) { 00204 (*i)->execute(); 00205 ++i; 00206 } 00207 }
| MSTrafficLightLogic * MSTLLogicControl::TLSLogicVariants::getActive | ( | ) | const |
Definition at line 177 of file MSTLLogicControl.cpp.
References myCurrentProgram.
Referenced by Command_SaveTLSSwitchStates::execute(), Command_SaveTLSSwitches::execute(), Command_SaveTLSState::execute(), MSTLLogicControl::initWautSwitch(), TraCIServerAPI_TLS::processGet(), and TraCIServerAPI_TLS::processSet().
00177 { 00178 return myCurrentProgram; 00179 }
| std::vector< MSTrafficLightLogic * > MSTLLogicControl::TLSLogicVariants::getAllLogics | ( | ) | const |
Definition at line 160 of file MSTLLogicControl.cpp.
References myVariants.
Referenced by GUITrafficLightLogicWrapper::getPopUpMenu(), GUIViewTraffic::onGamingClick(), TraCIServerAPI_TLS::processGet(), and GUITrafficLightLogicWrapper::switchTLSLogic().
00160 { 00161 std::vector<MSTrafficLightLogic*> ret; 00162 std::map<std::string, MSTrafficLightLogic*>::const_iterator i; 00163 for (i=myVariants.begin(); i!=myVariants.end(); ++i) { 00164 ret.push_back((*i).second); 00165 } 00166 return ret; 00167 }
| MSTrafficLightLogic * MSTLLogicControl::TLSLogicVariants::getLogic | ( | const std::string & | subid | ) | const |
Definition at line 126 of file MSTLLogicControl.cpp.
References myVariants.
Referenced by getLogicInstantiatingOff(), and TraCIServerAPI_TLS::processSet().
00126 { 00127 if (myVariants.find(subid)==myVariants.end()) { 00128 return 0; 00129 } 00130 return myVariants.find(subid)->second; 00131 }
| MSTrafficLightLogic * MSTLLogicControl::TLSLogicVariants::getLogicInstantiatingOff | ( | MSTLLogicControl & | tlc, | |
| const std::string & | subid | |||
| ) |
Definition at line 135 of file MSTLLogicControl.cpp.
References addLogic(), MSTrafficLightLogic::getID(), getLogic(), myCurrentProgram, and myVariants.
Referenced by MSTLLogicControl::initWautSwitch(), and switchTo().
00136 { 00137 if (myVariants.find(subid)==myVariants.end()) { 00138 if (subid=="off") { 00139 // build an off-tll if this switch indicates it 00140 if (!addLogic("off", new MSOffTrafficLightLogic(tlc, myCurrentProgram->getID()), true, false)) { 00141 // inform the user if this fails 00142 throw ProcessError("Could not build an off-state for tls '" + myCurrentProgram->getID() + "'."); 00143 } 00144 } else { 00145 // inform the user about a missing logic 00146 throw ProcessError("Can not switch tls '" + myCurrentProgram->getID() + "' to program '" + subid + "';\n The program is not known."); 00147 } 00148 } 00149 return getLogic(subid); 00150 }
| bool MSTLLogicControl::TLSLogicVariants::isActive | ( | const MSTrafficLightLogic * | tl | ) | const |
Definition at line 171 of file MSTLLogicControl.cpp.
References myCurrentProgram.
Referenced by GUITrafficLightLogicWrapper::getPopUpMenu().
00171 { 00172 return tl==myCurrentProgram; 00173 }
| TLSLogicVariants& MSTLLogicControl::TLSLogicVariants::operator= | ( | const TLSLogicVariants & | ) | [private] |
Invalidated assignment operator.
| void MSTLLogicControl::TLSLogicVariants::saveInitialStates | ( | ) |
Definition at line 90 of file MSTLLogicControl.cpp.
References MSTrafficLightLogic::collectLinkStates(), myCurrentProgram, and myOriginalLinkStates.
00090 { 00091 myOriginalLinkStates = myCurrentProgram->collectLinkStates(); 00092 }
| bool MSTLLogicControl::TLSLogicVariants::setTrafficLightSignals | ( | ) |
Definition at line 195 of file MSTLLogicControl.cpp.
References myCurrentProgram, and MSTrafficLightLogic::setTrafficLightSignals().
00195 { 00196 myCurrentProgram->setTrafficLightSignals(); 00197 return true; 00198 }
| bool MSTLLogicControl::TLSLogicVariants::switchTo | ( | MSTLLogicControl & | tlc, | |
| const std::string & | subid | |||
| ) |
Definition at line 183 of file MSTLLogicControl.cpp.
References getLogicInstantiatingOff(), myCurrentProgram, myOriginalLinkStates, and MSTrafficLightLogic::resetLinkStates().
Referenced by TraCIServerAPI_TLS::processSet().
00183 { 00184 // set the found wished sub-program as this tls' current one 00185 myCurrentProgram = getLogicInstantiatingOff(tlc, subid); 00186 // in the case we have switched to an off-state, we'll reset the links 00187 if (subid=="off") { 00188 myCurrentProgram->resetLinkStates(myOriginalLinkStates); 00189 } 00190 return true; 00191 }
The currently used program.
Definition at line 131 of file MSTLLogicControl.h.
Referenced by addLogic(), getActive(), getLogicInstantiatingOff(), isActive(), saveInitialStates(), setTrafficLightSignals(), and switchTo().
std::map<MSLink*, std::pair<MSLink::LinkState, bool> > MSTLLogicControl::TLSLogicVariants::myOriginalLinkStates [private] |
Originally loaded link states.
Definition at line 137 of file MSTLLogicControl.h.
Referenced by saveInitialStates(), and switchTo().
std::vector<OnSwitchAction*> MSTLLogicControl::TLSLogicVariants::mySwitchActions [private] |
The list of actions/commands to execute on switch.
Definition at line 140 of file MSTLLogicControl.h.
Referenced by addSwitchCommand(), executeOnSwitchActions(), and ~TLSLogicVariants().
std::map<std::string, MSTrafficLightLogic*> MSTLLogicControl::TLSLogicVariants::myVariants [private] |
A map of subkeys to programs.
Definition at line 134 of file MSTLLogicControl.h.
Referenced by addLink(), addLogic(), checkOriginalTLS(), getAllLogics(), getLogic(), getLogicInstantiatingOff(), and ~TLSLogicVariants().
1.5.6