#include <PCNetProjectionLoader.h>

Definition at line 51 of file PCNetProjectionLoader.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 | 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. | |
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. | |
Static Public Member Functions | |
| static void | loadIfSet (OptionsCont &oc, Position2D &netOffset, Boundary &origNetBoundary, Boundary &convNetBoundary, std::string &projParameter) throw (ProcessError) |
| Loads network projection if wished. | |
Protected Member Functions | |
| std::string | buildErrorMessage (const SAXParseException &exception) throw () |
| Builds an error message. | |
| bool | hasReadAll () const throw () |
| Returns whether all needed values were read. | |
| virtual void | myEndElement (SumoXMLTag element) throw (ProcessError) |
| Callback method for a closing tag to implement by derived classes. | |
| PCNetProjectionLoader (Position2D &netOffset, Boundary &origNetBoundary, Boundary &convNetBoundary, std::string &projParameter) throw () | |
| Constructor. | |
| ~PCNetProjectionLoader () throw () | |
| Destructor. | |
inherited from GenericSAXHandler | |
| void | myCharacters (SumoXMLTag element, const std::string &chars) throw (ProcessError) |
| Called when characters occure. | |
| virtual void | myStartElement (SumoXMLTag element, const SUMOSAXAttributes &attrs) throw (ProcessError) |
| Called on the opening of a tag;. | |
Private Attributes | |
| Boundary & | myConvNetBoundary |
| The converted network boundary to fill from values read from the network. | |
| bool | myFoundConvNetBoundary |
| bool | myFoundOffset |
| Information whether the parameter was read. | |
| bool | myFoundOrigNetBoundary |
| bool | myFoundProj |
| Position2D & | myNetOffset |
| The network offset to fill from values read from the network. | |
| Boundary & | myOrigNetBoundary |
| The original network boundary to fill from values read from the network. | |
| std::string & | myProjParameter |
| The projection parameter to fill from values read from the network. | |
| PCNetProjectionLoader::PCNetProjectionLoader | ( | Position2D & | netOffset, | |
| Boundary & | origNetBoundary, | |||
| Boundary & | convNetBoundary, | |||
| std::string & | projParameter | |||
| ) | throw () [protected] |
Constructor.
| [out] | netOffset | The network offset to fill from values read from the network |
| [out] | origNetBoundary | The original network boundary to fill from values read from the network |
| [out] | convNetBoundary | The converted network boundary to fill from values read from the network |
| [out] | projParameter | The projection parameter to fill from values read from the network |
Definition at line 97 of file PCNetProjectionLoader.cpp.
00100 : SUMOSAXHandler("sumo-network"), myNetOffset(netOffset), 00101 myOrigNetBoundary(origNetBoundary), myConvNetBoundary(convNetBoundary), 00102 myProjParameter(projParameter), 00103 myFoundOffset(false), myFoundOrigNetBoundary(false), 00104 myFoundConvNetBoundary(false), myFoundProj(false) {}
| PCNetProjectionLoader::~PCNetProjectionLoader | ( | ) | throw () [protected] |
| 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(), 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 }
| bool PCNetProjectionLoader::hasReadAll | ( | ) | const throw () [protected] |
Returns whether all needed values were read.
Definition at line 160 of file PCNetProjectionLoader.cpp.
References myFoundConvNetBoundary, myFoundOffset, myFoundOrigNetBoundary, and myFoundProj.
Referenced by loadIfSet().
00160 { 00161 return myFoundOffset&&myFoundOrigNetBoundary&&myFoundConvNetBoundary&&myFoundProj; 00162 }
| void PCNetProjectionLoader::loadIfSet | ( | OptionsCont & | oc, | |
| Position2D & | netOffset, | |||
| Boundary & | origNetBoundary, | |||
| Boundary & | convNetBoundary, | |||
| std::string & | projParameter | |||
| ) | throw (ProcessError) [static] |
Loads network projection if wished.
If the option "net" is set within the given options container, an instance of PCNetProjectionLoader is built and used as a handler for the file given in this option.
| [in] | oc | The options container to get further options from |
| [out] | netOffset | The network offset to fill from values read from the network |
| [out] | origNetBoundary | The original network boundary to fill from values read from the network |
| [out] | convNetBoundary | The converted network boundary to fill from values read from the network |
| [out] | projParameter | The projection parameter to fill from values read from the network |
| ProcessError | if something fails |
Definition at line 60 of file PCNetProjectionLoader.cpp.
References MsgHandler::beginProcessMsg(), MsgHandler::endProcessMsg(), FileHelpers::exists(), GenericSAXHandler::getFileName(), MsgHandler::getMessageInstance(), XMLSubSys::getSAXReader(), hasReadAll(), and GenericSAXHandler::setFileName().
Referenced by main().
00063 { 00064 if (!oc.isSet("net")) { 00065 return; 00066 } 00067 // check file 00068 std::string file = oc.getString("net"); 00069 if (!FileHelpers::exists(file)) { 00070 throw ProcessError("Could not open net-file '" + file + "'."); 00071 } 00072 // build handler and parser 00073 PCNetProjectionLoader handler(netOffset, origNetBoundary, convNetBoundary, projParameter); 00074 handler.setFileName(file); 00075 XMLPScanToken token; 00076 XERCES_CPP_NAMESPACE_QUALIFIER SAX2XMLReader *parser = XMLSubSys::getSAXReader(handler); 00077 MsgHandler::getMessageInstance()->beginProcessMsg("Parsing network projection from '" + file + "'..."); 00078 if (!parser->parseFirst(file.c_str(), token)) { 00079 delete parser; 00080 throw ProcessError("Can not read XML-file '" + handler.getFileName() + "'."); 00081 } 00082 // parse 00083 while (parser->parseNext(token) && !handler.hasReadAll()); 00084 // clean up 00085 MsgHandler::getMessageInstance()->endProcessMsg("done."); 00086 if (!handler.hasReadAll()) { 00087 throw ProcessError("Could not find projection parameter in net."); 00088 } 00089 delete parser; 00090 }
| void PCNetProjectionLoader::myCharacters | ( | SumoXMLTag | element, | |
| const std::string & | chars | |||
| ) | throw (ProcessError) [protected, virtual] |
Called when characters occure.
| [in] | element | ID of the last opened element |
| [in] | chars | The read characters (complete) |
| ProcessError | If something fails |
Reimplemented from GenericSAXHandler.
Definition at line 129 of file PCNetProjectionLoader.cpp.
References myConvNetBoundary, myFoundConvNetBoundary, myFoundOffset, myFoundOrigNetBoundary, myFoundProj, myNetOffset, myOrigNetBoundary, myProjParameter, GeomConvHelper::parseBoundaryReporting(), GeomConvHelper::parseShapeReporting(), SUMO_TAG_CONV_BOUNDARY, SUMO_TAG_NET_OFFSET, SUMO_TAG_ORIG_BOUNDARY, and SUMO_TAG_ORIG_PROJ.
00130 { 00131 bool ok = true; 00132 switch (element) { 00133 case SUMO_TAG_ORIG_BOUNDARY: 00134 myOrigNetBoundary = GeomConvHelper::parseBoundaryReporting(chars, "net", 0, ok); 00135 myFoundOrigNetBoundary = ok; 00136 break; 00137 case SUMO_TAG_CONV_BOUNDARY: 00138 myConvNetBoundary = GeomConvHelper::parseBoundaryReporting(chars, "net", 0, ok); 00139 myFoundConvNetBoundary = ok; 00140 break; 00141 case SUMO_TAG_NET_OFFSET: { 00142 Position2DVector tmp = GeomConvHelper::parseShapeReporting(chars, "net", 0, ok, false); 00143 if (ok) { 00144 myNetOffset = tmp[0]; 00145 } 00146 myFoundOffset = ok; 00147 } 00148 break; 00149 case SUMO_TAG_ORIG_PROJ: 00150 myProjParameter = chars; 00151 myFoundProj = true; 00152 break; 00153 default: 00154 break; 00155 } 00156 }
| 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 PCNetProjectionLoader::myStartElement | ( | SumoXMLTag | element, | |
| const SUMOSAXAttributes & | attrs | |||
| ) | throw (ProcessError) [protected, virtual] |
Called on the opening of a tag;.
| [in] | element | ID of the currently opened element |
| [in] | attrs | Attributes within the currently opened element |
| ProcessError | If something fails |
Reimplemented from GenericSAXHandler.
Definition at line 111 of file PCNetProjectionLoader.cpp.
References myConvNetBoundary, myFoundConvNetBoundary, myFoundOffset, myFoundOrigNetBoundary, myFoundProj, myNetOffset, myOrigNetBoundary, myProjParameter, GeomConvHelper::parseBoundaryReporting(), GeomConvHelper::parseShapeReporting(), SUMO_ATTR_CONV_BOUNDARY, SUMO_ATTR_NET_OFFSET, SUMO_ATTR_ORIG_BOUNDARY, SUMO_ATTR_ORIG_PROJ, and SUMO_TAG_LOCATION.
00112 { 00113 if (element!=SUMO_TAG_LOCATION) { 00114 return; 00115 } 00116 bool ok = true; 00117 Position2DVector tmp = GeomConvHelper::parseShapeReporting(attrs.getOptStringReporting(SUMO_ATTR_NET_OFFSET, "net", 0, ok, ""), "net", 0, ok, false); 00118 if (ok) { 00119 myNetOffset = tmp[0]; 00120 } 00121 myOrigNetBoundary = GeomConvHelper::parseBoundaryReporting(attrs.getOptStringReporting(SUMO_ATTR_ORIG_BOUNDARY, "net", 0, ok, ""), "net", 0, ok); 00122 myConvNetBoundary = GeomConvHelper::parseBoundaryReporting(attrs.getOptStringReporting(SUMO_ATTR_CONV_BOUNDARY, "net", 0, ok, ""), "net", 0, ok); 00123 myProjParameter = attrs.getOptStringReporting(SUMO_ATTR_ORIG_PROJ, "net", 0, ok, ""); 00124 myFoundOffset = myFoundOrigNetBoundary = myFoundConvNetBoundary = myFoundProj = ok; 00125 }
| 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 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 }
Boundary& PCNetProjectionLoader::myConvNetBoundary [private] |
The converted network boundary to fill from values read from the network.
Definition at line 126 of file PCNetProjectionLoader.h.
Referenced by myCharacters(), and myStartElement().
Definition at line 132 of file PCNetProjectionLoader.h.
Referenced by hasReadAll(), myCharacters(), and myStartElement().
bool PCNetProjectionLoader::myFoundOffset [private] |
Information whether the parameter was read.
Definition at line 132 of file PCNetProjectionLoader.h.
Referenced by hasReadAll(), myCharacters(), and myStartElement().
Definition at line 132 of file PCNetProjectionLoader.h.
Referenced by hasReadAll(), myCharacters(), and myStartElement().
bool PCNetProjectionLoader::myFoundProj [private] |
Definition at line 132 of file PCNetProjectionLoader.h.
Referenced by hasReadAll(), myCharacters(), and myStartElement().
Position2D& PCNetProjectionLoader::myNetOffset [private] |
The network offset to fill from values read from the network.
Definition at line 120 of file PCNetProjectionLoader.h.
Referenced by myCharacters(), and myStartElement().
Boundary& PCNetProjectionLoader::myOrigNetBoundary [private] |
The original network boundary to fill from values read from the network.
Definition at line 123 of file PCNetProjectionLoader.h.
Referenced by myCharacters(), and myStartElement().
std::string& PCNetProjectionLoader::myProjParameter [private] |
The projection parameter to fill from values read from the network.
Definition at line 129 of file PCNetProjectionLoader.h.
Referenced by myCharacters(), and myStartElement().
1.5.6