SUMO - Simulation of Urban MObility
GenericSAXHandler.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // A handler which converts occuring elements and attributes into enums
20 /****************************************************************************/
21 #ifndef GenericSAXHandler_h
22 #define GenericSAXHandler_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <map>
36 #include <stack>
37 #include <sstream>
38 #include <vector>
39 #include <xercesc/sax2/Attributes.hpp>
40 #include <xercesc/sax2/DefaultHandler.hpp>
43 #include "SUMOSAXAttributes.h"
44 
45 
46 // ===========================================================================
47 // class definitions
48 // ===========================================================================
74 class GenericSAXHandler : public XERCES_CPP_NAMESPACE::DefaultHandler {
75 
76 public:
96  StringBijection<int>::Entry* tags, int terminatorTag,
97  StringBijection<int>::Entry* attrs, int terminatorAttr,
98  const std::string& file);
99 
100 
102  virtual ~GenericSAXHandler();
103 
104 
117  void startElement(const XMLCh* const uri, const XMLCh* const localname,
118  const XMLCh* const qname, const XERCES_CPP_NAMESPACE::Attributes& attrs);
119 
120 
130  void characters(const XMLCh* const chars, const XERCES3_SIZE_t length);
131 
132 
145  void endElement(const XMLCh* const uri, const XMLCh* const localname,
146  const XMLCh* const qname);
147 
148 
152  void registerParent(const int tag, GenericSAXHandler* handler);
153 
154 
162  void setFileName(const std::string& name);
163 
164 
170  const std::string& getFileName() const;
171 
172 
174 
175 
184  void warning(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
185 
186 
195  void error(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
196 
197 
206  void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
208 
209 
210  // Reader needs access to myStartElement, myEndElement
211  friend class SUMOSAXReader;
212 
213 
214 protected:
224  std::string buildErrorMessage(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
225 
226 
235  virtual void myStartElement(int element,
236  const SUMOSAXAttributes& attrs);
237 
238 
247  virtual void myCharacters(int element,
248  const std::string& chars);
249 
250 
257  virtual void myEndElement(int element);
258 
259 
260 private:
268  XMLCh* convert(const std::string& name) const;
269 
270 
279  int convertTag(const std::string& tag) const;
280 
281 
282 private:
284 
285 
286  // the type of the map from ids to their unicode-string representation
287  typedef std::map<int, XMLCh*> AttrMap;
288 
289  // the map from ids to their unicode-string representation
291 
293  std::map<int, std::string> myPredefinedTagsMML;
295 
296 
298 
299 
300  // the type of the map that maps tag names to ints
301  typedef std::map<std::string, int> TagMap;
302 
303  // the map of tag names to their internal numerical representation
304  TagMap myTagMap;
306 
308  std::vector<std::string> myCharactersVector;
309 
312 
315 
317  std::string myFileName;
318 
319 private:
322 
325 
326 };
327 
328 #endif
329 
330 /****************************************************************************/
331 
int convertTag(const std::string &tag) const
Converts a tag from its string into its numerical representation.
GenericSAXHandler(StringBijection< int >::Entry *tags, int terminatorTag, StringBijection< int >::Entry *attrs, int terminatorAttr, const std::string &file)
Constructor.
const std::string & getFileName() const
returns the current file name
std::string myFileName
The name of the currently parsed file.
std::string buildErrorMessage(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Builds an error message.
SAX-reader encapsulation containing binary reader.
Definition: SUMOSAXReader.h:57
std::vector< std::string > myCharactersVector
A list of character strings obtained so far to build the complete characters string at the end...
void error(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Handler for XML-errors.
void characters(const XMLCh *const chars, const XERCES3_SIZE_t length)
The inherited method called when characters occured.
virtual ~GenericSAXHandler()
Destructor.
A handler which converts occuring elements and attributes into enums.
const GenericSAXHandler & operator=(const GenericSAXHandler &s)
invalidated assignment operator
void setFileName(const std::string &name)
Sets the current file name.
Encapsulated SAX-Attributes.
XMLCh * convert(const std::string &name) const
converts from c++-string into unicode
void warning(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Handler for XML-warnings.
virtual void myCharacters(int element, const std::string &chars)
Callback method for characters to implement by derived classes.
std::map< int, XMLCh * > AttrMap
GenericSAXHandler * myParentHandler
The handler to give control back to.
void registerParent(const int tag, GenericSAXHandler *handler)
Assigning a parent handler which is enabled when the specified tag is closed.
#define XERCES3_SIZE_t
Definition: config.h:216
void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Handler for XML-errors.
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Callback method for an opening tag to implement by derived classes.
std::map< std::string, int > TagMap
std::map< int, std::string > myPredefinedTagsMML
the map from ids to their string representation
int myParentIndicator
The tag indicating that control should be given back.
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.
void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
The inherited method called when a tag is being closed.
virtual void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.