|
SUMO - Simulation of Urban MObility
|
A handler which converts occuring elements and attributes into enums. More...
#include <GenericSAXHandler.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. | |
| GenericSAXHandler (StringBijection< int >::Entry *tags, int terminatorTag, StringBijection< int >::Entry *attrs, int terminatorAttr, const std::string &file) | |
| Constructor. | |
| const std::string & | getFileName () const throw () |
| returns the current file name | |
| void | registerParent (const int 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. | |
| virtual | ~GenericSAXHandler () |
| Destructor. | |
SAX ErrorHandler callbacks | |
| void | warning (const SAXParseException &exception) throw () |
| Handler for XML-warnings. | |
| void | error (const SAXParseException &exception) throw (ProcessError) |
| Handler for XML-errors. | |
| void | fatalError (const SAXParseException &exception) throw (ProcessError) |
| Handler for XML-errors. | |
Protected Member Functions | |
| std::string | buildErrorMessage (const SAXParseException &exception) throw () |
| Builds an error message. | |
| virtual void | myCharacters (int element, const std::string &chars) |
| Callback method for characters to implement by derived classes. | |
| virtual void | myEndElement (int element) |
| Callback method for a closing tag to implement by derived classes. | |
| virtual void | myStartElement (int element, const SUMOSAXAttributes &attrs) |
| Callback method for an opening tag to implement by derived classes. | |
Private Member Functions | |
| XMLCh * | convert (const std::string &name) const throw () |
| converts from c++-string into unicode | |
| int | convertTag (const std::string &tag) const throw () |
| Converts a tag from its string into its numerical representation. | |
Private Attributes | |
| std::vector< std::string > | myCharactersVector |
| A list of character strings obtained so far to build the complete characters string at the end. | |
| std::string | myFileName |
| The name of the currently parsed file. | |
| GenericSAXHandler * | myParentHandler |
| The handler to give control back to. | |
| int | myParentIndicator |
| The tag indicating that control should be given back. | |
attributes parsing | |
| typedef std::map< int, XMLCh * > | AttrMap |
| AttrMap | myPredefinedTags |
| std::map< int, std::string > | myPredefinedTagsMML |
| the map from ids to their string representation | |
elements parsing | |
| typedef std::map< std::string, int > | TagMap |
| TagMap | myTagMap |
A handler which converts occuring elements and attributes into enums.
Normally, when using a standard SAX-handler, we would have to compare the incoming XMLCh*-element names with the ones we can parse. The same applies to parsing the attributes. This was assumed to be very time consuming, that's why we derive our handlers from this class.
The idea behind this second handler layer was avoid repeated conversion from strings/whatever to XMLCh* and back again. The usage is quite straight forward, the only overhead is the need to define the enums - both elements and attributes within "SUMOXMLDefinitions". Still, it maybe helps to avoid typos.
This class implements the SAX-callback and offers a new set of callbacks which must be implemented by derived classes. Instead of XMLCh*-values, element names are supplied to the derived classes as enums (int).
Also, this class allows to retrieve attributes using enums (int) within the implemented "myStartElement" method.
Basically, GenericSAXHandler is not derived within SUMO directly, but via SUMOSAXHandler which knows all tags/attributes used by SUMO. It is still kept separate for an easier maintainability and later extensions.
Definition at line 80 of file GenericSAXHandler.h.
typedef std::map<int, XMLCh*> GenericSAXHandler::AttrMap [private] |
Definition at line 290 of file GenericSAXHandler.h.
typedef std::map<std::string, int> GenericSAXHandler::TagMap [private] |
Definition at line 304 of file GenericSAXHandler.h.
| GenericSAXHandler::GenericSAXHandler | ( | StringBijection< int >::Entry * | tags, |
| int | terminatorTag, | ||
| StringBijection< int >::Entry * | attrs, | ||
| int | terminatorAttr, | ||
| const std::string & | file | ||
| ) |
Constructor.
This constructor gets the lists of known tag and attribute names with their enums (sumotags and sumoattrs in most cases). The end of the list is signaled by terminatorTag/terminatorAttr respectively.
The attribute names are converted into XMLCh* and stored within an internal container. This container is cleared within the destructor.
| [in] | tags | The list of known tags |
| [in] | terminatorTag | The tag which signales the end of tags (usually the last entry) |
| [in] | attrs | The list of known attributes |
| [in] | terminatorAttr | The attr which signales the end of attrs (usually the last entry) |
| [in] | file | The name of the processed file |
Definition at line 48 of file GenericSAXHandler.cpp.
References convert(), myPredefinedTags, myPredefinedTagsMML, and myTagMap.
| GenericSAXHandler::~GenericSAXHandler | ( | ) | [virtual] |
| std::string GenericSAXHandler::buildErrorMessage | ( | const SAXParseException & | exception | ) | throw () [protected] |
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 189 of file GenericSAXHandler.cpp.
| void GenericSAXHandler::characters | ( | const XMLCh *const | chars, |
| const XERCES3_SIZE_t | length | ||
| ) |
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.
recheck/describe what happens with characters when a new element is opened
describe characters processing in the class' head
Definition at line 172 of file GenericSAXHandler.cpp.
References myCharactersVector.
| XMLCh * GenericSAXHandler::convert | ( | const std::string & | name | ) | const throw () [private] |
converts from c++-string into unicode
| [in] | name | The string to convert |
Definition at line 88 of file GenericSAXHandler.cpp.
Referenced by GenericSAXHandler().
| int GenericSAXHandler::convertTag | ( | const std::string & | tag | ) | const throw () [private] |
Converts a tag from its string into its numerical representation.
Returns the enum-representation stored for the given tag. If the tag is not known, SUMO_TAG_NOTHING is returned.
| [in] | tag | The string to convert |
Definition at line 179 of file GenericSAXHandler.cpp.
References SUMO_TAG_NOTHING.
Referenced by endElement(), and startElement().
| void GenericSAXHandler::endElement | ( | const XMLCh *const | uri, |
| const XMLCh *const | localname, | ||
| const XMLCh *const | qname | ||
| ) |
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.
recheck/describe encoding of the string-representation
do not generate and report the string-representation
Definition at line 122 of file GenericSAXHandler.cpp.
References convertTag(), myCharacters(), myCharactersVector, myEndElement(), myParentHandler, myParentIndicator, XMLSubSys::setHandler(), SUMO_TAG_INCLUDE, and SUMO_TAG_NOTHING.
| void GenericSAXHandler::error | ( | const SAXParseException & | exception | ) | throw (ProcessError) |
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 208 of file GenericSAXHandler.cpp.
Referenced by NLHandler::getLanesFromIndices().
| void GenericSAXHandler::fatalError | ( | const SAXParseException & | exception | ) | throw (ProcessError) |
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 214 of file GenericSAXHandler.cpp.
| const std::string & GenericSAXHandler::getFileName | ( | ) | const throw () |
returns the current file name
Definition at line 82 of file GenericSAXHandler.cpp.
References myFileName.
Referenced by NLHandler::addE1Detector(), NLHandler::addE2Detector(), NLHandler::addEdgeLaneMeanData(), NLHandler::addInstantE1Detector(), NLHandler::addRouteProbeDetector(), NLHandler::addVTypeProbeDetector(), NLHandler::beginE3Detector(), MSRouteLoader::init(), PCNetProjectionLoader::loadIfSet(), NILoader::loadXMLType(), MSTriggeredXMLReader::myInit(), RORDGenerator_ODAmounts::RORDGenerator_ODAmounts(), and startElement().
| void GenericSAXHandler::myCharacters | ( | int | element, |
| const std::string & | chars | ||
| ) | [protected, virtual] |
Callback method for characters to implement by derived classes.
Called by "endElement" (see there).
| [in] | element | The opened element, given as a int |
| [in] | chars | The complete embedded character string ProcessError These method may throw a ProcessError if something fails |
Reimplemented in ROJTRTurnDefLoader, NIImporter_ITSUMO::Handler, NIImporter_OpenDrive, NIImporter_SUMO, PCLoaderXML, PCNetProjectionLoader, and RORDLoader_SUMOBase.
Definition at line 224 of file GenericSAXHandler.cpp.
Referenced by endElement().
| void GenericSAXHandler::myEndElement | ( | int | element | ) | [protected, virtual] |
Callback method for a closing tag to implement by derived classes.
Called by "endElement" (see there).
| [in] | element | The closed element, given as a int ProcessError These method may throw a ProcessError if something fails |
Reimplemented in MSRouteHandler, MSLaneSpeedTrigger, MSTriggeredRerouter, NIImporter_ITSUMO::Handler, NIImporter_OpenDrive, NIImporter_OpenStreetMap::NodesHandler, NIImporter_OpenStreetMap::EdgesHandler, NIImporter_SUMO, NIXMLEdgesHandler, NIXMLTrafficLightsHandler, NLHandler, ODDistrictHandler, PCLoaderOSM::NodesHandler, PCLoaderOSM::EdgesHandler, RORDGenerator_ODAmounts, RORDLoader_SUMOBase, RORDLoader_TripDefs, and SAXWeightsHandler.
Definition at line 228 of file GenericSAXHandler.cpp.
Referenced by endElement().
| void GenericSAXHandler::myStartElement | ( | int | element, |
| const SUMOSAXAttributes & | attrs | ||
| ) | [protected, virtual] |
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 int |
| [in] | attrs | The SAX-attributes, wrapped as SUMOSAXAttributes ProcessError These method may throw a ProcessError if something fails |
Reimplemented in AGActivityGenHandler, RODFDetectorHandler, ROJTRTurnDefLoader, MSRouteHandler, MSLaneSpeedTrigger, MSTriggeredRerouter, NIImporter_ITSUMO::Handler, NIImporter_MATSim::NodesHandler, NIImporter_MATSim::EdgesHandler, NIImporter_OpenDrive, NIImporter_OpenStreetMap::NodesHandler, NIImporter_OpenStreetMap::EdgesHandler, NIImporter_SUMO, NIXMLConnectionsHandler, NIXMLEdgesHandler, NIXMLNodesHandler, NIXMLTrafficLightsHandler, NIXMLTypesHandler, NLHandler, ODDistrictHandler, PCLoaderOSM::NodesHandler, PCLoaderOSM::EdgesHandler, PCLoaderXML, PCNetProjectionLoader, PCTypeDefHandler, RONetHandler, RORDGenerator_ODAmounts, RORDLoader_SUMOBase, RORDLoader_TripDefs, GUISettingsHandler, and SAXWeightsHandler.
Definition at line 220 of file GenericSAXHandler.cpp.
Referenced by startElement().
| void GenericSAXHandler::registerParent | ( | const int | tag, |
| GenericSAXHandler * | handler | ||
| ) |
Assigning a parent handler which is enabled when the specified tag is closed.
Definition at line 164 of file GenericSAXHandler.cpp.
References myParentHandler, myParentIndicator, and XMLSubSys::setHandler().
Referenced by NLTriggerBuilder::parseAndBuildLaneSpeedTrigger().
| void GenericSAXHandler::setFileName | ( | const std::string & | name | ) | throw () |
Sets the current file name.
| [in] | name | The name of the currently processed file |
Definition at line 76 of file GenericSAXHandler.cpp.
Referenced by NIImporter_SUMO::_loadNetwork(), NIImporter_OpenStreetMap::_loadNetwork(), AGActivityGen::importInfoCity(), PCNetProjectionLoader::loadIfSet(), ROLoader::loadNet(), loadNet(), NIImporter_OpenDrive::loadNetwork(), NIImporter_MATSim::loadNetwork(), NIImporter_ITSUMO::loadNetwork(), and NILoader::loadXMLType().
| void GenericSAXHandler::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.
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.
recheck/describe encoding of the string-representation
do not generate and report the string-representation
Definition at line 101 of file GenericSAXHandler.cpp.
References convertTag(), FileHelpers::getConfigurationRelative(), getFileName(), SUMOSAXAttributesImpl_Xerces::getString(), FileHelpers::isAbsolute(), myCharactersVector, myPredefinedTags, myPredefinedTagsMML, myStartElement(), XMLSubSys::runParser(), SUMO_ATTR_HREF, and SUMO_TAG_INCLUDE.
| void GenericSAXHandler::warning | ( | const SAXParseException & | exception | ) | throw () |
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 202 of file GenericSAXHandler.cpp.
References WRITE_WARNING.
std::vector<std::string> GenericSAXHandler::myCharactersVector [private] |
A list of character strings obtained so far to build the complete characters string at the end.
Definition at line 311 of file GenericSAXHandler.h.
Referenced by characters(), endElement(), and startElement().
std::string GenericSAXHandler::myFileName [private] |
The name of the currently parsed file.
Definition at line 320 of file GenericSAXHandler.h.
Referenced by getFileName().
The handler to give control back to.
Definition at line 314 of file GenericSAXHandler.h.
Referenced by endElement(), and registerParent().
int GenericSAXHandler::myParentIndicator [private] |
The tag indicating that control should be given back.
Definition at line 317 of file GenericSAXHandler.h.
Referenced by endElement(), and registerParent().
AttrMap GenericSAXHandler::myPredefinedTags [private] |
Definition at line 293 of file GenericSAXHandler.h.
Referenced by GenericSAXHandler(), startElement(), and ~GenericSAXHandler().
std::map<int, std::string> GenericSAXHandler::myPredefinedTagsMML [private] |
the map from ids to their string representation
Definition at line 296 of file GenericSAXHandler.h.
Referenced by GenericSAXHandler(), and startElement().
TagMap GenericSAXHandler::myTagMap [private] |
Definition at line 307 of file GenericSAXHandler.h.
Referenced by GenericSAXHandler().