SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GenericSAXHandler.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // A handler which converts occuring elements and attributes into enums
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef GenericSAXHandler_h
23 #define GenericSAXHandler_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <string>
36 #include <map>
37 #include <stack>
38 #include <sstream>
39 #include <vector>
40 #include <xercesc/sax2/Attributes.hpp>
41 #include <xercesc/sax2/DefaultHandler.hpp>
44 #include "SUMOSAXAttributes.h"
45 
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
75 class GenericSAXHandler : public XERCES_CPP_NAMESPACE::DefaultHandler {
76 
77 public:
97  StringBijection<int>::Entry* tags, int terminatorTag,
98  StringBijection<int>::Entry* attrs, int terminatorAttr,
99  const std::string& file);
100 
101 
103  virtual ~GenericSAXHandler();
104 
105 
118  void startElement(const XMLCh* const uri, const XMLCh* const localname,
119  const XMLCh* const qname, const XERCES_CPP_NAMESPACE::Attributes& attrs);
120 
121 
131  void characters(const XMLCh* const chars, const XERCES3_SIZE_t length);
132 
133 
146  void endElement(const XMLCh* const uri, const XMLCh* const localname,
147  const XMLCh* const qname);
148 
149 
153  void registerParent(const int tag, GenericSAXHandler* handler);
154 
155 
163  void setFileName(const std::string& name);
164 
165 
171  const std::string& getFileName() const;
172 
173 
175 
176 
185  void warning(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
186 
187 
196  void error(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
197 
198 
207  void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
209 
210 
211  // Reader needs access to myStartElement, myEndElement
212  friend class SUMOSAXReader;
213 
214 
215 protected:
225  std::string buildErrorMessage(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
226 
227 
236  virtual void myStartElement(int element,
237  const SUMOSAXAttributes& attrs);
238 
239 
248  virtual void myCharacters(int element,
249  const std::string& chars);
250 
251 
258  virtual void myEndElement(int element);
259 
260 
261 private:
269  XMLCh* convert(const std::string& name) const;
270 
271 
280  int convertTag(const std::string& tag) const;
281 
282 
283 private:
285 
286 
287  // the type of the map from ids to their unicode-string representation
288  typedef std::map<int, XMLCh*> AttrMap;
289 
290  // the map from ids to their unicode-string representation
292 
294  std::map<int, std::string> myPredefinedTagsMML;
296 
297 
299 
300 
301  // the type of the map that maps tag names to ints
302  typedef std::map<std::string, int> TagMap;
303 
304  // the map of tag names to their internal numerical representation
307 
309  std::vector<std::string> myCharactersVector;
310 
313 
316 
318  std::string myFileName;
319 
320 private:
323 
326 
327 };
328 
329 #endif
330 
331 /****************************************************************************/
332 
GenericSAXHandler(StringBijection< int >::Entry *tags, int terminatorTag, StringBijection< int >::Entry *attrs, int terminatorAttr, const std::string &file)
Constructor.
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:54
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.
XMLCh * convert(const std::string &name) const
converts from c++-string into unicode
int convertTag(const std::string &tag) const
Converts a tag from its string into its numerical representation.
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
const std::string & getFileName() const
returns the current file name
void setFileName(const std::string &name)
Sets the current file name.
Encapsulated SAX-Attributes.
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:239
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.