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. More... | |
void | endElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname) |
The inherited method called when a tag is being closed. More... | |
GenericSAXHandler (StringBijection< int >::Entry *tags, int terminatorTag, StringBijection< int >::Entry *attrs, int terminatorAttr, const std::string &file) | |
Constructor. More... | |
const std::string & | getFileName () const |
returns the current file name More... | |
void | registerParent (const int tag, GenericSAXHandler *handler) |
Assigning a parent handler which is enabled when the specified tag is closed. More... | |
void | setFileName (const std::string &name) |
Sets the current file name. More... | |
void | startElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const XERCES_CPP_NAMESPACE::Attributes &attrs) |
The inherited method called when a new tag opens. More... | |
virtual | ~GenericSAXHandler () |
Destructor. More... | |
SAX ErrorHandler callbacks | |
void | warning (const XERCES_CPP_NAMESPACE::SAXParseException &exception) |
Handler for XML-warnings. More... | |
void | error (const XERCES_CPP_NAMESPACE::SAXParseException &exception) |
Handler for XML-errors. More... | |
void | fatalError (const XERCES_CPP_NAMESPACE::SAXParseException &exception) |
Handler for XML-errors. More... | |
Protected Member Functions | |
std::string | buildErrorMessage (const XERCES_CPP_NAMESPACE::SAXParseException &exception) |
Builds an error message. More... | |
virtual void | myCharacters (int element, const std::string &chars) |
Callback method for characters to implement by derived classes. More... | |
virtual void | myEndElement (int element) |
Callback method for a closing tag to implement by derived classes. More... | |
virtual void | myStartElement (int element, const SUMOSAXAttributes &attrs) |
Callback method for an opening tag to implement by derived classes. More... | |
Private Member Functions | |
XMLCh * | convert (const std::string &name) const |
converts from c++-string into unicode More... | |
int | convertTag (const std::string &tag) const |
Converts a tag from its string into its numerical representation. More... | |
GenericSAXHandler (const GenericSAXHandler &s) | |
invalidated copy constructor More... | |
const GenericSAXHandler & | operator= (const GenericSAXHandler &s) |
invalidated assignment operator More... | |
Private Attributes | |
std::vector< std::string > | myCharactersVector |
A list of character strings obtained so far to build the complete characters string at the end. More... | |
std::string | myFileName |
The name of the currently parsed file. More... | |
GenericSAXHandler * | myParentHandler |
The handler to give control back to. More... | |
int | myParentIndicator |
The tag indicating that control should be given back. More... | |
Friends | |
class | SUMOSAXReader |
attributes parsing | |
typedef std::map< int, XMLCh * > | AttrMap |
AttrMap | myPredefinedTags |
std::map< int, std::string > | myPredefinedTagsMML |
the map from ids to their string representation More... | |
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 75 of file GenericSAXHandler.h.
|
private |
Definition at line 288 of file GenericSAXHandler.h.
|
private |
Definition at line 302 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 52 of file GenericSAXHandler.cpp.
References convert(), myPredefinedTags, myPredefinedTagsMML, and myTagMap.
|
virtual |
|
private |
invalidated copy constructor
|
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 193 of file GenericSAXHandler.cpp.
References getFileName().
Referenced by error(), fatalError(), and warning().
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 176 of file GenericSAXHandler.cpp.
References TplConvert::_2str(), and myCharactersVector.
|
private |
converts from c++-string into unicode
[in] | name | The string to convert |
Definition at line 92 of file GenericSAXHandler.cpp.
Referenced by GenericSAXHandler().
|
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 183 of file GenericSAXHandler.cpp.
References myTagMap, and 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 126 of file GenericSAXHandler.cpp.
References TplConvert::_2str(), convertTag(), myCharacters(), myCharactersVector, myEndElement(), myParentHandler, myParentIndicator, XMLSubSys::setHandler(), SUMO_TAG_INCLUDE, and SUMO_TAG_NOTHING.
void GenericSAXHandler::error | ( | const XERCES_CPP_NAMESPACE::SAXParseException & | exception | ) |
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 212 of file GenericSAXHandler.cpp.
References buildErrorMessage().
void GenericSAXHandler::fatalError | ( | const XERCES_CPP_NAMESPACE::SAXParseException & | exception | ) |
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 218 of file GenericSAXHandler.cpp.
References buildErrorMessage().
const std::string & GenericSAXHandler::getFileName | ( | ) | const |
returns the current file name
Definition at line 86 of file GenericSAXHandler.cpp.
References myFileName.
Referenced by NLHandler::addE1Detector(), NLHandler::addE2Detector(), NLHandler::addEdgeLaneMeanData(), NLHandler::addInstantE1Detector(), NLHandler::addPOI(), NLHandler::addPoly(), NLHandler::addRouteProbeDetector(), NLHandler::addVTypeProbeDetector(), NLHandler::beginE3Detector(), buildErrorMessage(), PCNetProjectionLoader::load(), NILoader::loadXMLType(), RODFDetectorHandler::myStartElement(), GUISettingsHandler::myStartElement(), MSStateHandler::myStartElement(), SUMORouteHandler::myStartElement(), PCLoaderXML::myStartElement(), NLHandler::myStartElement(), NIImporter_OpenDrive::myStartElement(), XMLSubSys::runParser(), startElement(), and SUMORouteLoader::SUMORouteLoader().
|
protectedvirtual |
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 NIImporter_ITSUMO::Handler.
Definition at line 228 of file GenericSAXHandler.cpp.
Referenced by endElement().
|
protectedvirtual |
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 NIImporter_OpenDrive, NIImporter_OpenStreetMap::RelationHandler, NIImporter_OpenStreetMap::EdgesHandler, NIImporter_OpenStreetMap::NodesHandler, PCLoaderOSM::EdgesHandler, SAXWeightsHandler, MSTriggeredRerouter, PCLoaderOSM::NodesHandler, NIImporter_ITSUMO::Handler, NLHandler, MSLaneSpeedTrigger, NIImporter_SUMO, NIXMLEdgesHandler, MSCalibrator, ODDistrictHandler, RORouteHandler, SUMORouteHandler, MSStateHandler, MSRouteHandler, and NIXMLTrafficLightsHandler.
Definition at line 232 of file GenericSAXHandler.cpp.
Referenced by endElement(), and SUMOSAXReader::parseNext().
|
protectedvirtual |
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 NIImporter_OpenDrive, NIImporter_OpenStreetMap::RelationHandler, NIImporter_OpenStreetMap::EdgesHandler, NIImporter_OpenStreetMap::NodesHandler, PCLoaderOSM::EdgesHandler, SAXWeightsHandler, NIImporter_MATSim::EdgesHandler, MSTriggeredRerouter, PCLoaderOSM::NodesHandler, MSLaneSpeedTrigger, NLHandler, NIImporter_SUMO, NIImporter_MATSim::NodesHandler, NIImporter_ITSUMO::Handler, NIXMLEdgesHandler, PCLoaderXML, NIXMLNodesHandler, PCNetProjectionLoader, MSCalibrator, ROJTRTurnDefLoader, ODDistrictHandler, RONetHandler, RORouteHandler, SUMORouteHandler, MSStateHandler, NIXMLTypesHandler, NIXMLConnectionsHandler, MSRouteHandler, NIXMLTrafficLightsHandler, PCTypeDefHandler, AGActivityGenHandler, GUISettingsHandler, and RODFDetectorHandler.
Definition at line 224 of file GenericSAXHandler.cpp.
Referenced by SUMOSAXReader::parseNext(), and startElement().
|
private |
invalidated assignment operator
void GenericSAXHandler::registerParent | ( | const int | tag, |
GenericSAXHandler * | handler | ||
) |
Assigning a parent handler which is enabled when the specified tag is closed.
Definition at line 168 of file GenericSAXHandler.cpp.
References myParentHandler, myParentIndicator, and XMLSubSys::setHandler().
Referenced by NLTriggerBuilder::parseAndBuildCalibrator(), NLTriggerBuilder::parseAndBuildLaneSpeedTrigger(), and NLTriggerBuilder::parseAndBuildRerouter().
void GenericSAXHandler::setFileName | ( | const std::string & | name | ) |
Sets the current file name.
[in] | name | The name of the currently processed file |
Definition at line 80 of file GenericSAXHandler.cpp.
References myFileName.
Referenced by NIImporter_SUMO::_loadNetwork(), GUISettingsHandler::GUISettingsHandler(), PCNetProjectionLoader::load(), NIImporter_OpenStreetMap::load(), loadNet(), ROLoader::loadNet(), NIImporter_ITSUMO::loadNetwork(), NIImporter_MATSim::loadNetwork(), NIImporter_OpenDrive::loadNetwork(), and XMLSubSys::runParser().
void GenericSAXHandler::startElement | ( | const XMLCh *const | uri, |
const XMLCh *const | localname, | ||
const XMLCh *const | qname, | ||
const XERCES_CPP_NAMESPACE::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 105 of file GenericSAXHandler.cpp.
References TplConvert::_2str(), 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 XERCES_CPP_NAMESPACE::SAXParseException & | exception | ) |
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 206 of file GenericSAXHandler.cpp.
References buildErrorMessage(), and WRITE_WARNING.
|
friend |
Definition at line 212 of file GenericSAXHandler.h.
|
private |
A list of character strings obtained so far to build the complete characters string at the end.
Definition at line 309 of file GenericSAXHandler.h.
Referenced by characters(), endElement(), and startElement().
|
private |
The name of the currently parsed file.
Definition at line 318 of file GenericSAXHandler.h.
Referenced by getFileName(), and setFileName().
|
private |
The handler to give control back to.
Definition at line 312 of file GenericSAXHandler.h.
Referenced by endElement(), and registerParent().
|
private |
The tag indicating that control should be given back.
Definition at line 315 of file GenericSAXHandler.h.
Referenced by endElement(), and registerParent().
|
private |
Definition at line 291 of file GenericSAXHandler.h.
Referenced by GenericSAXHandler(), startElement(), and ~GenericSAXHandler().
|
private |
the map from ids to their string representation
Definition at line 294 of file GenericSAXHandler.h.
Referenced by GenericSAXHandler(), SUMOSAXReader::parseNext(), and startElement().
|
private |
Definition at line 305 of file GenericSAXHandler.h.
Referenced by convertTag(), and GenericSAXHandler().