#include <MSTriggeredXMLReader.h>

Definition at line 51 of file MSTriggeredXMLReader.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 | |
| void | init () |
| bool | isInitialised () const |
| 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. | |
| SUMOTime | wrappedExecute (SUMOTime current) throw (ProcessError) |
| virtual | ~MSTriggeredXMLReader () 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 | inputEndReached ()=0 |
| MSTriggeredXMLReader (MSNet &net, const std::string &filename) | |
| Constructor (for derived classes). | |
| virtual void | myCharacters (SumoXMLTag element, const std::string &chars) throw (ProcessError) |
| Callback method for characters to implement by derived classes. | |
| virtual void | myEndElement (SumoXMLTag element) throw (ProcessError) |
| Callback method for a closing tag to implement by derived classes. | |
| void | myInit () |
| virtual void | myStartElement (SumoXMLTag element, const SUMOSAXAttributes &attrs) throw (ProcessError) |
| Callback method for an opening tag to implement by derived classes. | |
| virtual bool | nextRead ()=0 |
| virtual bool | processNextEntryReaderTriggered ()=0 |
| Processes the next event Returns true if the next element shall be read (a new timestemp is then available also) Returns false if the action could not be accomplished; this method is then called in the next step again. | |
| bool | readNextTriggered () |
| reads from the XML-file (parses from file) | |
| SUMOTime | warppedExecute (SUMOTime currentTime) throw (ProcessError) |
Protected Attributes | |
| bool | myHaveMore |
| SUMOTime | myOffset |
| The offset to the next event. | |
| SAX2XMLReader * | myParser |
| The used SAX-parser. | |
| XMLPScanToken | myToken |
| Position within the XML-file. | |
| bool | myWasInitialised |
Private Member Functions | |
| MSTriggeredXMLReader (const MSTriggeredXMLReader &) | |
| Invalidated copy constructor. | |
| MSTriggeredXMLReader & | operator= (const MSTriggeredXMLReader &) |
| Invalidated assignment operator. | |
| MSTriggeredXMLReader::~MSTriggeredXMLReader | ( | ) | throw () [virtual] |
| MSTriggeredXMLReader::MSTriggeredXMLReader | ( | MSNet & | net, | |
| const std::string & | filename | |||
| ) | [protected] |
Constructor (for derived classes).
Definition at line 51 of file MSTriggeredXMLReader.cpp.
References MSEventControl::addEvent(), MSNet::getCurrentTimeStep(), MSNet::getEmissionEvents(), MSNet::getInstance(), MSEventControl::NO_CHANGE, and MSTriggeredReader::wrappedExecute().
00053 : MSTriggeredReader(net), 00054 SUMOSAXHandler(filename), 00055 myParser(0), myHaveMore(true) { 00056 Command* c = new WrappingCommand< MSTriggeredReader >(this, &MSTriggeredReader::wrappedExecute); 00057 MSNet::getInstance()->getEmissionEvents().addEvent( 00058 c, net.getCurrentTimeStep(), MSEventControl::NO_CHANGE); 00059 }
| MSTriggeredXMLReader::MSTriggeredXMLReader | ( | const MSTriggeredXMLReader & | ) | [private] |
Invalidated copy constructor.
| 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 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(), 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 MSTriggeredReader::init | ( | ) | [inherited] |
Definition at line 49 of file MSTriggeredReader.cpp.
References MSTriggeredReader::myInit(), and MSTriggeredReader::myWasInitialised.
Referenced by MSTriggeredReader::wrappedExecute(), and GUIEmitter::GUIEmitterChild_UserTriggeredChild::wrappedExecute().
00049 { 00050 myInit(); 00051 myWasInitialised = true; 00052 }
| virtual void MSTriggeredReader::inputEndReached | ( | ) | [protected, pure virtual, inherited] |
Implemented in MSCalibrator::MSCalibrator_FileTriggeredChild, and MSEmitter::MSEmitter_FileTriggeredChild.
| bool MSTriggeredReader::isInitialised | ( | ) | const [inherited] |
Definition at line 56 of file MSTriggeredReader.cpp.
References MSTriggeredReader::myWasInitialised.
Referenced by MSTriggeredReader::wrappedExecute(), and GUIEmitter::GUIEmitterChild_UserTriggeredChild::wrappedExecute().
00056 { 00057 return myWasInitialised; 00058 }
| 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 GenericSAXHandler::myEndElement | ( | SumoXMLTag | element | ) | throw (ProcessError) [protected, virtual, inherited] |
Callback method for a closing tag to implement by derived classes.
Called by "endElement" (see there).
| [in] | element | The closed element, given as a SumoXMLTag ProcessError These method may throw a ProcessError if something fails |
Reimplemented in MSRouteHandler, MSLaneSpeedTrigger, MSTriggeredRerouter, NIImporter_OpenDrive, NIImporter_OpenStreetMap::NodesHandler, NIImporter_OpenStreetMap::EdgesHandler, NIImporter_SUMO, NIXMLEdgesHandler, NLHandler, ODDistrictHandler, PCLoaderOSM::NodesHandler, PCLoaderOSM::EdgesHandler, RORDGenerator_ODAmounts, RORDLoader_SUMOBase, RORDLoader_TripDefs, traci::TraCIHandler, and SAXWeightsHandler.
Definition at line 193 of file GenericSAXHandler.cpp.
Referenced by GenericSAXHandler::endElement().
| void MSTriggeredXMLReader::myInit | ( | ) | [protected, virtual] |
Implements MSTriggeredReader.
Definition at line 78 of file MSTriggeredXMLReader.cpp.
References MSNet::getCurrentTimeStep(), GenericSAXHandler::getFileName(), MSNet::getInstance(), XMLSubSys::getSAXReader(), myHaveMore, MSTriggeredReader::myOffset, myParser, myToken, and readNextTriggered().
00078 { 00079 try { 00080 myParser = XMLSubSys::getSAXReader(*this); 00081 if (!myParser->parseFirst(getFileName().c_str(), myToken)) { 00082 throw ProcessError("Can not read XML-file '" + getFileName() + "'."); 00083 00084 } 00085 } catch (SAXException &e) { 00086 throw ProcessError(TplConvert<XMLCh>::_2str(e.getMessage())); 00087 00088 } catch (XMLException &e) { 00089 throw ProcessError(TplConvert<XMLCh>::_2str(e.getMessage())); 00090 00091 } 00092 00093 if (readNextTriggered()) { 00094 if (myOffset<MSNet::getInstance()->getCurrentTimeStep()) { 00095 myOffset = MSNet::getInstance()->getCurrentTimeStep() + 1; 00096 // !!! Warning? 00097 } 00098 } else { 00099 myHaveMore = false; 00100 } 00101 }
| void GenericSAXHandler::myStartElement | ( | SumoXMLTag | element, | |
| const SUMOSAXAttributes & | attrs | |||
| ) | throw (ProcessError) [protected, virtual, inherited] |
Callback method for an opening tag to implement by derived classes.
Called by "startElement" (see there).
| [in] | element | The element that contains the characters, given as a SumoXMLTag |
| [in] | attrs | The SAX-attributes, wrapped as SUMOSAXAttributes ProcessError These method may throw a ProcessError if something fails |
Reimplemented in RODFDetectorHandler, ROJTRTurnDefLoader, MSRouteHandler, MSCalibrator::MSCalibrator_FileTriggeredChild, MSEmitter::MSEmitter_FileTriggeredChild, MSLaneSpeedTrigger, MSTriggeredRerouter, NIImporter_OpenDrive, NIImporter_OpenStreetMap::NodesHandler, NIImporter_OpenStreetMap::EdgesHandler, NIImporter_SUMO, NIXMLConnectionsHandler, NIXMLEdgesHandler, NIXMLNodesHandler, NIXMLTypesHandler, NLHandler, ODDistrictHandler, PCLoaderOSM::NodesHandler, PCLoaderOSM::EdgesHandler, PCLoaderXML, PCNetProjectionLoader, PCTypeDefHandler, RONetHandler, RORDGenerator_ODAmounts, RORDLoader_SUMOBase, RORDLoader_TripDefs, traci::TraCIHandler, GUISettingsHandler, and SAXWeightsHandler.
Definition at line 185 of file GenericSAXHandler.cpp.
Referenced by GenericSAXHandler::startElement().
| virtual bool MSTriggeredXMLReader::nextRead | ( | ) | [protected, pure virtual] |
Implemented in MSCalibrator::MSCalibrator_FileTriggeredChild, and MSEmitter::MSEmitter_FileTriggeredChild.
Referenced by readNextTriggered().
| MSTriggeredXMLReader& MSTriggeredXMLReader::operator= | ( | const MSTriggeredXMLReader & | ) | [private] |
Invalidated assignment operator.
| virtual bool MSTriggeredReader::processNextEntryReaderTriggered | ( | ) | [protected, pure virtual, inherited] |
Processes the next event Returns true if the next element shall be read (a new timestemp is then available also) Returns false if the action could not be accomplished; this method is then called in the next step again.
Implemented in MSCalibrator::MSCalibrator_FileTriggeredChild, and MSEmitter::MSEmitter_FileTriggeredChild.
Referenced by MSTriggeredReader::wrappedExecute().
| bool MSTriggeredXMLReader::readNextTriggered | ( | ) | [protected, virtual] |
reads from the XML-file (parses from file)
Implements MSTriggeredReader.
Definition at line 66 of file MSTriggeredXMLReader.cpp.
References myHaveMore, myParser, myToken, and nextRead().
Referenced by myInit().
00066 { 00067 while (myHaveMore&&myParser->parseNext(myToken)) { 00068 if (nextRead()) { 00069 return true; 00070 } 00071 } 00072 myHaveMore = false; 00073 return false; 00074 }
| 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 }
| SUMOTime MSTriggeredReader::warppedExecute | ( | SUMOTime | currentTime | ) | throw (ProcessError) [protected, inherited] |
| SUMOTime MSTriggeredReader::wrappedExecute | ( | SUMOTime | current | ) | throw (ProcessError) [inherited] |
Definition at line 62 of file MSTriggeredReader.cpp.
References DELTA_T, MSTriggeredReader::init(), MSTriggeredReader::isInitialised(), MSTriggeredReader::myOffset, MSTriggeredReader::processNextEntryReaderTriggered(), and MSTriggeredReader::readNextTriggered().
Referenced by MSTriggeredXMLReader().
00062 { 00063 if (!isInitialised()) { 00064 init(); 00065 } 00066 SUMOTime next = current; 00067 // loop until the next action lies in the future 00068 while (current==next) { 00069 // run the next action 00070 // if it could be accomplished... 00071 if (processNextEntryReaderTriggered()) { 00072 // read the next one 00073 if (readNextTriggered()) { 00074 // set the time for comparison if a next one exists 00075 next = myOffset; 00076 } else { 00077 // leave if no further exists 00078 return 0; 00079 } 00080 } else { 00081 // action could not been accomplished; try next time step 00082 return DELTA_T; 00083 } 00084 } 00085 // come back if the next action shall be executed 00086 if (myOffset - current<=0) { 00087 // current is delayed; 00088 return DELTA_T; 00089 } 00090 return myOffset - current; 00091 }
bool MSTriggeredXMLReader::myHaveMore [protected] |
Definition at line 76 of file MSTriggeredXMLReader.h.
Referenced by myInit(), and readNextTriggered().
SUMOTime MSTriggeredReader::myOffset [protected, inherited] |
The offset to the next event.
Definition at line 73 of file MSTriggeredReader.h.
Referenced by MSEmitter::MSEmitter_FileTriggeredChild::buildAndScheduleFlowVehicle(), MSCalibrator::MSCalibrator_FileTriggeredChild::buildAndScheduleFlowVehicle(), myInit(), MSEmitter::MSEmitter_FileTriggeredChild::myStartElement(), MSCalibrator::MSCalibrator_FileTriggeredChild::myStartElement(), and MSTriggeredReader::wrappedExecute().
SAX2XMLReader* MSTriggeredXMLReader::myParser [protected] |
The used SAX-parser.
Definition at line 71 of file MSTriggeredXMLReader.h.
Referenced by myInit(), and readNextTriggered().
XMLPScanToken MSTriggeredXMLReader::myToken [protected] |
Position within the XML-file.
Definition at line 74 of file MSTriggeredXMLReader.h.
Referenced by myInit(), and readNextTriggered().
bool MSTriggeredReader::myWasInitialised [protected, inherited] |
Definition at line 74 of file MSTriggeredReader.h.
Referenced by MSTriggeredReader::init(), and MSTriggeredReader::isInitialised().
1.5.6