35 #include <xercesc/sax/HandlerBase.hpp> 36 #include <xercesc/sax/AttributeList.hpp> 37 #include <xercesc/sax/SAXParseException.hpp> 38 #include <xercesc/sax/SAXException.hpp> 56 #ifdef CHECK_MEMORY_LEAKS 58 #endif // CHECK_MEMORY_LEAKS 70 myResetPhases(false) {
124 WRITE_ERROR(
"Definition of tlLogic '" + currentTL->
getID() +
"' was not finished.");
137 WRITE_ERROR(
"Unknown traffic light type '" + typeS +
"' for tlLogic '" +
id +
"'.");
148 if (programs.size() == 0) {
149 WRITE_ERROR(
"Cannot load traffic light program for unknown id '" +
id +
"', programID '" + programID +
"'.");
152 const std::string existingProgram = programs.begin()->first;
154 if (loadedDef == 0) {
165 WRITE_ERROR(
"Cannot load traffic light program for unknown id '" +
id +
"', programID '" + programID +
"'.");
172 std::vector<NBNode*> nodes = newDef->
getNodes();
173 for (std::vector<NBNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
179 std::vector<NBNode*> nodes = newDef->
getNodes();
180 for (std::vector<NBNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
181 (*it)->removeTrafficLight(newDef);
193 std::vector<NBNode*> nodes = oldDef->
getNodes();
194 for (std::vector<NBNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
195 loadedDef->addNode(*it);
228 const std::vector<NBEdge::Connection>& connections = from->
getConnections();
229 std::vector<NBEdge::Connection>::const_iterator con_it;
230 con_it = find_if(connections.begin(), connections.end(),
232 if (con_it == connections.end()) {
234 " fromLane=" +
toString(fromLane) +
" toLane=" +
toString(toLane) +
" not found");
253 if (programs.size() > 0) {
254 std::map<std::string, NBTrafficLightDefinition*>::const_iterator it;
255 for (it = programs.begin(); it != programs.end(); it++) {
261 + tlID +
"' (program '" + it->first +
"')");
265 WRITE_ERROR(
"The traffic light '" + tlID +
"' is not known.");
276 if (programs.size() > 0) {
292 std::map<std::string, NBTrafficLightDefinition*>::const_iterator it;
293 for (it = programs.begin(); it != programs.end(); it++) {
299 + tlID +
"' (program '" + it->first +
"')");
309 std::string edgeID = attrs.
get<std::string>(attr, 0, ok);
312 WRITE_ERROR(
"Unknown edge '" + edgeID +
"' given in connection.");
322 int laneIndex = attrs.
get<
int>(attr, 0, ok);
int tlLinkNo
The index of this connection within the controlling traffic light.
const std::map< std::string, NBTrafficLightDefinition * > & getPrograms(const std::string &id) const
Returns all programs for the given tl-id.
void removeConnection(const NBConnection &conn, bool reconstruct=true)
removes the given connection from the traffic light if recontruct=true, reconstructs the logic and in...
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
A structure which describes a connection between edges or lanes.
int toLane
The lane the connections yields in.
static void addPhase(const SUMOSAXAttributes &attrs, NBLoadedSUMOTLDef *currentTL)
adds a phase to the traffic lights logic currently build
bool removeProgram(const std::string id, const std::string programID, bool del=true)
Removes a program of a logic definition from the dictionary.
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
NBEdge * toEdge
The edge the connections yields in.
void setOffset(SUMOTime offset)
Sets the offset of this tls.
int getNumLinks()
Returns the number of participating links.
A loaded (complete) traffic light logic.
NBEdgeCont & myEdgeCont
The edge container for retrieving edges.
A container for traffic light definitions and built programs.
A SUMO-compliant built logic for a traffic light.
NBEdge * retrieveEdge(const SUMOSAXAttributes &attrs, SumoXMLAttr attr, bool &ok)
parses and edge id an returns an existing edge
The representation of a single edge during network building.
The base class for traffic light logic definitions.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
const std::string & getID() const
Returns the id.
NBLoadedSUMOTLDef * initTrafficLightLogic(const SUMOSAXAttributes &attrs, NBLoadedSUMOTLDef *currentTL)
SAX-handler base for SUMO-files.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
static OptionsCont & getOptions()
Retrieves the options.
NBTrafficLightLogicCont & myTLLCont
The traffic light container to fill.
int retrieveLaneIndex(const SUMOSAXAttributes &attrs, SumoXMLAttr attr, NBEdge *edge, bool &ok)
parses a lane index and verifies its correctness
NBTrafficLightDefinition * getDefinition(const std::string &id, const std::string &programID) const
Returns the named definition.
Encapsulated SAX-Attributes.
std::string tlID
The id of the traffic light that controls this connection.
void addTlConnection(const SUMOSAXAttributes &attrs)
reads and adds tl-controlled connection
static StringBijection< TrafficLightType > TrafficLightTypes
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
int getNumLanes() const
Returns the number of lanes.
int fromLane
The lane the connections starts at.
T get(const std::string &str) const
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
NBLoadedSUMOTLDef * myCurrentTL
The currently parsed traffic light.
Storage for edges, including some functionality operating on multiple edges.
void removeTlConnection(const SUMOSAXAttributes &attrs)
reads and removes tl-controlled connection
NBTrafficLightLogic * getLogic()
Returns the internal logic.
static const std::string DefaultProgramID
void addControlledInnerEdges(const std::vector< std::string > &edges)
Adds the given ids into the list of inner edges controlled by the tls.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
bool myResetPhases
whether phases of a previously loaded traffic light must be reset
~NIXMLTrafficLightsHandler()
Destructor.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
void myEndElement(int element)
Called when a closing tag occurs.
const std::vector< Connection > & getConnections() const
Returns the connections.
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
const std::vector< NBNode * > & getNodes() const
Returns the list of controlled nodes.
NIXMLTrafficLightsHandler(NBTrafficLightLogicCont &tlCont, NBEdgeCont &ec)
Constructor.
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
void setType(TrafficLightType type)
Sets the algorithm type of this tls.
A traffic light logics which must be computed (only nodes/edges are given)
std::vector< std::string > getControlledInnerEdges() const
Retrieve the ids of edges explicitly controlled by the tls.
void addConnection(NBEdge *from, NBEdge *to, int fromLane, int toLane, int linkIndex)
Adds a connection and immediately informs the edges.