#include <ODDistrictHandler.h>

This SUMOSAXHandler parses districts and their sinks and sources from and stores them into a the district container given at initialisation.
Definition at line 54 of file ODDistrictHandler.h.
Public Member Functions | |
| void | characters (const XMLCh *const chars, const XERCES3_SIZE_t length) |
| The inherited method called when characters occured. | |
| void | endElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname) |
| The inherited method called when a tag is being closed. | |
| const std::string & | getFileName () const throw () |
| returns the current file name | |
| ODDistrictHandler (ODDistrictCont &cont, const std::string &file) throw () | |
| Constructor. | |
| void | registerParent (const SumoXMLTag tag, GenericSAXHandler *handler) |
| Assigning a parent handler which is enabled when the specified tag is closed. | |
| void | setFileName (const std::string &name) throw () |
| Sets the current file name. | |
| void | startElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs) |
| The inherited method called when a new tag opens. | |
| ~ODDistrictHandler () throw () | |
| Destructor. | |
SAX ErrorHandler callbacks | |
| void | error (const SAXParseException &exception) throw (ProcessError) |
| Handler for XML-errors. | |
| void | fatalError (const SAXParseException &exception) throw (ProcessError) |
| Handler for XML-errors. | |
| void | warning (const SAXParseException &exception) throw () |
| Handler for XML-warnings. | |
Protected Member Functions | |
| std::string | buildErrorMessage (const SAXParseException &exception) throw () |
| Builds an error message. | |
| virtual void | myCharacters (SumoXMLTag element, const std::string &chars) throw (ProcessError) |
| Callback method for characters to implement by derived classes. | |
inherited from GenericSAXHandler | |
| void | myEndElement (SumoXMLTag element) throw (ProcessError) |
| Called when a closing tag occurs. | |
| void | myStartElement (SumoXMLTag element, const SUMOSAXAttributes &attrs) throw (ProcessError) |
| Called when an opening-tag occurs. | |
Private Member Functions | |
| void | addSink (const SUMOSAXAttributes &attrs) throw () |
| Adds a read sink to the current district. | |
| void | addSource (const SUMOSAXAttributes &attrs) throw () |
| Adds a read source to the current district. | |
| void | closeDistrict () throw () |
| Closes the processing of the current district. | |
| ODDistrictHandler (const ODDistrictHandler &s) | |
| invalidated copy constructor | |
| void | openDistrict (const SUMOSAXAttributes &attrs) throw () |
| Begins the parsing of a district. | |
| ODDistrictHandler & | operator= (const ODDistrictHandler &s) |
| invalidated assignment operator | |
| std::pair< std::string, SUMOReal > | parseConnection (const SUMOSAXAttributes &attrs, const std::string &type) throw () |
| Returns the id and weight for a sink/source. | |
Private Attributes | |
| ODDistrictCont & | myContainer |
| The container to add read districts to. | |
| ODDistrict * | myCurrentDistrict |
| The currently parsed district. | |
| ODDistrictHandler::ODDistrictHandler | ( | ODDistrictCont & | cont, | |
| const std::string & | file | |||
| ) | throw () |
Constructor.
Saves the given district containe in order to fill it.
| [in] | cont | The container of districts to fill |
| [in] | file | The file that will be processed |
Definition at line 49 of file ODDistrictHandler.cpp.
00051 : SUMOSAXHandler(file), myContainer(cont), myCurrentDistrict(0) {}
| ODDistrictHandler::~ODDistrictHandler | ( | ) | throw () |
| ODDistrictHandler::ODDistrictHandler | ( | const ODDistrictHandler & | s | ) | [private] |
invalidated copy constructor
| void ODDistrictHandler::addSink | ( | const SUMOSAXAttributes & | attrs | ) | throw () [private] |
Adds a read sink to the current district.
Tries to get the id and the weight of the currently parsed sink from the attributes using getValues. If the retrieval could be done without errors (weight>=0), the so retrieved weighted sink is added to myCurrentDistrict using addSink. (getValues checks whether myCurrentDistrict is valid)
| [in] | attrs | Attributes of the currently opened element |
Definition at line 106 of file ODDistrictHandler.cpp.
References ODDistrict::addSink(), myCurrentDistrict, and parseConnection().
Referenced by myStartElement().
00106 { 00107 std::pair<std::string, SUMOReal> vals = parseConnection(attrs, "sink"); 00108 if (vals.second>=0) { 00109 myCurrentDistrict->addSink(vals.first, vals.second); 00110 } 00111 }
| void ODDistrictHandler::addSource | ( | const SUMOSAXAttributes & | attrs | ) | throw () [private] |
Adds a read source to the current district.
Tries to get the id and the weight of the currently parsed source from the attributes using getValues. If the retrieval could be done without errors (weight>=0), the so retrieved weighted source is added to myCurrentDistrict using addSource. (getValues checks whether myCurrentDistrict is valid)
| [in] | attrs | Attributes of the currently opened element |
Definition at line 97 of file ODDistrictHandler.cpp.
References ODDistrict::addSource(), myCurrentDistrict, and parseConnection().
Referenced by myStartElement().
00097 { 00098 std::pair<std::string, SUMOReal> vals = parseConnection(attrs, "source"); 00099 if (vals.second>=0) { 00100 myCurrentDistrict->addSource(vals.first, vals.second); 00101 } 00102 }
| std::string SUMOSAXHandler::buildErrorMessage | ( | const SAXParseException & | exception | ) | throw () [protected, inherited] |
Builds an error message.
The error message includes the file name and the line/column information as supported by the given SAXParseException
| [in] | exception | The name of the currently processed file |
Definition at line 55 of file SUMOSAXHandler.cpp.
References GenericSAXHandler::getFileName().
Referenced by SUMOSAXHandler::error(), SUMOSAXHandler::fatalError(), and SUMOSAXHandler::warning().
00055 { 00056 std::ostringstream buf; 00057 char *pMsg = XMLString::transcode(exception.getMessage()); 00058 buf << pMsg << std::endl; 00059 buf << " In file '" << getFileName() << "'" << std::endl; 00060 buf << " At line/column " << exception.getLineNumber()+1 00061 << '/' << exception.getColumnNumber() << "." << std::endl; 00062 XMLString::release(&pMsg); 00063 return buf.str(); 00064 }
| void GenericSAXHandler::characters | ( | const XMLCh *const | chars, | |
| const XERCES3_SIZE_t | length | |||
| ) | [inherited] |
The inherited method called when characters occured.
The retrieved characters are converted into a string and appended into a private buffer. They are reported as soon as the element ends.
Definition at line 168 of file GenericSAXHandler.cpp.
References GenericSAXHandler::myCharactersVector.
00169 { 00170 myCharactersVector.push_back(TplConvert<XMLCh>::_2str(chars, length)); 00171 }
| void ODDistrictHandler::closeDistrict | ( | ) | throw () [private] |
Closes the processing of the current district.
Adds myCurrentDistrict to myContainer.
Definition at line 141 of file ODDistrictHandler.cpp.
References NamedObjectCont< T >::add(), Named::getID(), myContainer, and myCurrentDistrict.
Referenced by myEndElement().
00141 { 00142 if (myCurrentDistrict!=0) { 00143 myContainer.add(myCurrentDistrict->getID(), myCurrentDistrict); 00144 } 00145 }
| void GenericSAXHandler::endElement | ( | const XMLCh *const | uri, | |
| const XMLCh *const | localname, | |||
| const XMLCh *const | qname | |||
| ) | [inherited] |
The inherited method called when a tag is being closed.
This method calls the user-implemented methods myCharacters with the previously collected and converted characters.
Then, myEndElement is called, supplying it the qname converted to its enum- and string-representations.
Definition at line 118 of file GenericSAXHandler.cpp.
References TplConvert< E >::_2str(), GenericSAXHandler::convertTag(), GenericSAXHandler::myCharacters(), GenericSAXHandler::myCharactersVector, GenericSAXHandler::myEndElement(), GenericSAXHandler::myParentHandler, GenericSAXHandler::myParentIndicator, XMLSubSys::setHandler(), SUMO_TAG_INCLUDE, and SUMO_TAG_NOTHING.
00120 { 00121 std::string name = TplConvert<XMLCh>::_2str(qname); 00122 SumoXMLTag element = convertTag(name); 00123 // collect characters 00124 if (myCharactersVector.size()!=0) { 00125 size_t len = 0; 00126 unsigned i; 00127 for (i=0; i<myCharactersVector.size(); ++i) { 00128 len += myCharactersVector[i].length(); 00129 } 00130 char *buf = new char[len+1]; 00131 size_t pos = 0; 00132 for (i=0; i<myCharactersVector.size(); ++i) { 00133 memcpy((unsigned char*) buf+pos, (unsigned char*) myCharactersVector[i].c_str(), 00134 sizeof(char)*myCharactersVector[i].length()); 00135 pos += myCharactersVector[i].length(); 00136 } 00137 buf[pos] = 0; 00138 00139 // call user handler 00140 try { 00141 myCharacters(element, buf); 00142 } catch (std::runtime_error &) { 00143 delete[] buf; 00144 throw; 00145 } 00146 delete[] buf; 00147 } 00148 if (element != SUMO_TAG_INCLUDE) { 00149 myEndElement(element); 00150 if (myParentHandler && myParentIndicator == element) { 00151 XMLSubSys::setHandler(*myParentHandler); 00152 myParentIndicator = SUMO_TAG_NOTHING; 00153 myParentHandler = 0; 00154 } 00155 } 00156 }
| void SUMOSAXHandler::error | ( | const SAXParseException & | exception | ) | throw (ProcessError) [inherited] |
Handler for XML-errors.
The message is built using buildErrorMessage and thrown within a ProcessError.
| [in] | exception | The occured exception to process |
| ProcessError | On any call |
Definition at line 74 of file SUMOSAXHandler.cpp.
References SUMOSAXHandler::buildErrorMessage().
00074 { 00075 throw ProcessError(buildErrorMessage(exception)); 00076 }
| void SUMOSAXHandler::fatalError | ( | const SAXParseException & | exception | ) | throw (ProcessError) [inherited] |
Handler for XML-errors.
The message is built using buildErrorMessage and thrown within a ProcessError.
| ProcessError | On any call |
| [in] | exception | The occured exception to process |
Definition at line 80 of file SUMOSAXHandler.cpp.
References SUMOSAXHandler::buildErrorMessage().
00080 { 00081 throw ProcessError(buildErrorMessage(exception)); 00082 }
| const std::string & GenericSAXHandler::getFileName | ( | ) | const throw () [inherited] |
returns the current file name
Definition at line 78 of file GenericSAXHandler.cpp.
References GenericSAXHandler::myFileName.
Referenced by NLHandler::addE1Detector(), NLHandler::addE2Detector(), NLHandler::addEdgeLaneMeanData(), NLHandler::addRouteProbeDetector(), NLHandler::addSource(), NLHandler::addTrigger(), NLHandler::addVTypeProbeDetector(), NLHandler::beginE3Detector(), SUMOSAXHandler::buildErrorMessage(), MSRouteLoader::init(), PCNetProjectionLoader::loadIfSet(), NILoader::loadXMLType(), MSTriggeredXMLReader::myInit(), RODFDetectorHandler::myStartElement(), NLHandler::myStartElement(), NIImporter_OpenDrive::myStartElement(), MSLaneSpeedTrigger::myStartElement(), GUISettingsHandler::myStartElement(), RORDGenerator_ODAmounts::RORDGenerator_ODAmounts(), and GenericSAXHandler::startElement().
00078 { 00079 return myFileName; 00080 }
| void GenericSAXHandler::myCharacters | ( | SumoXMLTag | element, | |
| const std::string & | chars | |||
| ) | throw (ProcessError) [protected, virtual, inherited] |
Callback method for characters to implement by derived classes.
Called by "endElement" (see there).
| [in] | element | The opened element, given as a SumoXMLTag |
| [in] | chars | The complete embedded character string ProcessError These method may throw a ProcessError if something fails |
Reimplemented in ROJTRTurnDefLoader, MSRouteHandler, NIImporter_OpenDrive, NIImporter_SUMO, NLHandler, PCLoaderXML, PCNetProjectionLoader, and RORDLoader_SUMOBase.
Definition at line 189 of file GenericSAXHandler.cpp.
Referenced by GenericSAXHandler::endElement().
| void ODDistrictHandler::myEndElement | ( | SumoXMLTag | element | ) | throw (ProcessError) [protected, virtual] |
Called when a closing tag occurs.
Processes district elements via closeDistrict.
| [in] | element | ID of the currently opened element |
| ProcessError | If an error within the parsed file occurs |
Reimplemented from GenericSAXHandler.
Definition at line 77 of file ODDistrictHandler.cpp.
References closeDistrict(), and SUMO_TAG_DISTRICT.
00077 { 00078 if (element==SUMO_TAG_DISTRICT) { 00079 closeDistrict(); 00080 } 00081 }
| void ODDistrictHandler::myStartElement | ( | SumoXMLTag | element, | |
| const SUMOSAXAttributes & | attrs | |||
| ) | throw (ProcessError) [protected, virtual] |
Called when an opening-tag occurs.
Processes district elements via openDistrict, their sinks (via addSink) and sources (via addSource).
| [in] | element | The enum of the currently opened element |
| [in] | attrs | Attributes of the currently opened element |
| ProcessError | If an error within the parsed file occurs |
Reimplemented from GenericSAXHandler.
Definition at line 58 of file ODDistrictHandler.cpp.
References addSink(), addSource(), openDistrict(), SUMO_TAG_DISTRICT, SUMO_TAG_DSINK, and SUMO_TAG_DSOURCE.
00059 { 00060 switch (element) { 00061 case SUMO_TAG_DISTRICT: 00062 openDistrict(attrs); 00063 break; 00064 case SUMO_TAG_DSOURCE: 00065 addSource(attrs); 00066 break; 00067 case SUMO_TAG_DSINK: 00068 addSink(attrs); 00069 break; 00070 default: 00071 break; 00072 } 00073 }
| void ODDistrictHandler::openDistrict | ( | const SUMOSAXAttributes & | attrs | ) | throw () [private] |
Begins the parsing of a district.
Tries to retrieve the id of a district, adds a message to the error handler if this fails. Otherwise builds a new district with this id at myCurrentDistrict.
| [in] | attrs | Attributes of the currently opened element |
Definition at line 85 of file ODDistrictHandler.cpp.
References myCurrentDistrict.
Referenced by myStartElement().
00085 { 00086 myCurrentDistrict = 0; 00087 // get the id, report an error if not given or empty... 00088 std::string id; 00089 if (!attrs.setIDFromAttributes("district", id)) { 00090 return; 00091 } 00092 myCurrentDistrict = new ODDistrict(id); 00093 }
| ODDistrictHandler& ODDistrictHandler::operator= | ( | const ODDistrictHandler & | s | ) | [private] |
invalidated assignment operator
| std::pair< std::string, SUMOReal > ODDistrictHandler::parseConnection | ( | const SUMOSAXAttributes & | attrs, | |
| const std::string & | type | |||
| ) | throw () [private] |
Returns the id and weight for a sink/source.
Checks whether myCurrentDistrict (the currently processed district) is !=0; in this case, both the id and the weight are parsed. If one of them is missing or the weight is not numerical, an error is generated and reported to MsgHandler. The "type"-parameter is used in order to inform the user whether a source or a sink was processed. In the case of an error, the returned weight is -1.
If no error occurs, the correct id and weight are returned.
| [in] | attrs | Attributes of the currently opened element |
| [in] | type | The type of the currntly processed connection (sink/source) |
Definition at line 116 of file ODDistrictHandler.cpp.
References MsgHandler::getErrorInstance(), MsgHandler::inform(), myCurrentDistrict, SUMO_ATTR_WEIGHT, and SUMOReal.
Referenced by addSink(), and addSource().
00116 { 00117 // check the current district first 00118 if (myCurrentDistrict==0) { 00119 return std::pair<std::string, SUMOReal>("", -1); 00120 } 00121 // get the id, report an error if not given or empty... 00122 std::string id; 00123 if (!attrs.setIDFromAttributes(type.c_str(), id)) { 00124 return std::pair<std::string, SUMOReal>("", -1); 00125 } 00126 // get the weight 00127 bool ok = true; 00128 SUMOReal weight = attrs.getSUMORealReporting(SUMO_ATTR_WEIGHT, type.c_str(), id.c_str(), ok); 00129 if (ok) { 00130 if (weight<0) { 00131 MsgHandler::getErrorInstance()->inform("'probability' must be positive (in definition of " + type + " '" + id + "')."); 00132 } else { 00133 return std::pair<std::string, SUMOReal>(id, weight); 00134 } 00135 } 00136 return std::pair<std::string, SUMOReal>("", -1); 00137 }
| void GenericSAXHandler::registerParent | ( | const SumoXMLTag | tag, | |
| GenericSAXHandler * | handler | |||
| ) | [inherited] |
Assigning a parent handler which is enabled when the specified tag is closed.
Definition at line 160 of file GenericSAXHandler.cpp.
References GenericSAXHandler::myParentHandler, GenericSAXHandler::myParentIndicator, and XMLSubSys::setHandler().
Referenced by NLTriggerBuilder::parseAndBuildLaneSpeedTrigger().
00160 { 00161 myParentHandler = handler; 00162 myParentIndicator = tag; 00163 XMLSubSys::setHandler(*this); 00164 }
| void GenericSAXHandler::setFileName | ( | const std::string & | name | ) | throw () [inherited] |
Sets the current file name.
| [in] | name | The name of the currently processed file |
Definition at line 72 of file GenericSAXHandler.cpp.
References GenericSAXHandler::myFileName.
Referenced by PCNetProjectionLoader::loadIfSet(), ROLoader::loadNet(), NIImporter_OpenStreetMap::loadNetwork(), NILoader::loadXMLType(), and traci::TraCIServer::TraCIServer().
00072 { 00073 myFileName = name; 00074 }
| void GenericSAXHandler::startElement | ( | const XMLCh *const | uri, | |
| const XMLCh *const | localname, | |||
| const XMLCh *const | qname, | |||
| const Attributes & | attrs | |||
| ) | [inherited] |
The inherited method called when a new tag opens.
The method parses the supplied XMLCh*-qname using the internal name/enum-map to obtain the enum representation of the attribute name.
Then, "myStartElement" is called supplying the enumeration value, the string-representation of the name and the attributes.
Definition at line 97 of file GenericSAXHandler.cpp.
References TplConvert< E >::_2str(), GenericSAXHandler::convertTag(), FileHelpers::getConfigurationRelative(), GenericSAXHandler::getFileName(), SUMOSAXAttributesImpl_Xerces::getString(), FileHelpers::isAbsolute(), GenericSAXHandler::myCharactersVector, GenericSAXHandler::myPredefinedTags, GenericSAXHandler::myPredefinedTagsMML, GenericSAXHandler::myStartElement(), XMLSubSys::runParser(), SUMO_ATTR_HREF, and SUMO_TAG_INCLUDE.
00100 { 00101 std::string name = TplConvert<XMLCh>::_2str(qname); 00102 SumoXMLTag element = convertTag(name); 00103 myCharactersVector.clear(); 00104 SUMOSAXAttributesImpl_Xerces na(attrs, myPredefinedTags, myPredefinedTagsMML); 00105 if (element == SUMO_TAG_INCLUDE) { 00106 std::string file = na.getString(SUMO_ATTR_HREF); 00107 if (!FileHelpers::isAbsolute(file)) { 00108 file = FileHelpers::getConfigurationRelative(getFileName(), file); 00109 } 00110 XMLSubSys::runParser(*this, file); 00111 } else { 00112 myStartElement(element, na); 00113 } 00114 }
| void SUMOSAXHandler::warning | ( | const SAXParseException & | exception | ) | throw () [inherited] |
Handler for XML-warnings.
The message is built using buildErrorMessage and reported to the warning-instance of the MsgHandler.
| [in] | exception | The occured exception to process |
Definition at line 68 of file SUMOSAXHandler.cpp.
References SUMOSAXHandler::buildErrorMessage(), MsgHandler::getWarningInstance(), and MsgHandler::inform().
00068 { 00069 MsgHandler::getWarningInstance()->inform(buildErrorMessage(exception)); 00070 }
ODDistrictCont& ODDistrictHandler::myContainer [private] |
The container to add read districts to.
Definition at line 165 of file ODDistrictHandler.h.
Referenced by closeDistrict().
ODDistrict* ODDistrictHandler::myCurrentDistrict [private] |
The currently parsed district.
Definition at line 168 of file ODDistrictHandler.h.
Referenced by addSink(), addSource(), closeDistrict(), openDistrict(), and parseConnection().
1.5.6