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.sourceforge.net/
12 // Copyright (C) 2001-2012 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 // xerces 2.2 compatibility
49 // ===========================================================================
50 #if defined(XERCES_HAS_CPP_NAMESPACE)
51 using namespace XERCES_CPP_NAMESPACE;
52 #endif
53 
54 
55 // ===========================================================================
56 // class definitions
57 // ===========================================================================
84 
85 public:
105  StringBijection<int>::Entry* tags, int terminatorTag,
106  StringBijection<int>::Entry* attrs, int terminatorAttr,
107  const std::string& file);
108 
109 
111  virtual ~GenericSAXHandler();
112 
113 
126  void startElement(const XMLCh* const uri, const XMLCh* const localname,
127  const XMLCh* const qname, const Attributes& attrs);
128 
129 
139  void characters(const XMLCh* const chars, const XERCES3_SIZE_t length);
140 
141 
154  void endElement(const XMLCh* const uri, const XMLCh* const localname,
155  const XMLCh* const qname);
156 
157 
161  void registerParent(const int tag, GenericSAXHandler* handler);
162 
163 
171  void setFileName(const std::string& name) ;
172 
173 
179  const std::string& getFileName() const ;
180 
181 
183 
184 
193  void warning(const SAXParseException& exception) ;
194 
195 
204  void error(const SAXParseException& exception) ;
205 
206 
215  void fatalError(const SAXParseException& exception) ;
217 
218 
219 
220 protected:
230  std::string buildErrorMessage(const SAXParseException& exception) ;
231 
232 
241  virtual void myStartElement(int element,
242  const SUMOSAXAttributes& attrs);
243 
244 
253  virtual void myCharacters(int element,
254  const std::string& chars);
255 
256 
263  virtual void myEndElement(int element);
264 
265 
266 private:
274  XMLCh* convert(const std::string& name) const ;
275 
276 
285  int convertTag(const std::string& tag) const ;
286 
287 
288 private:
290 
291 
292  // the type of the map from ids to their unicode-string representation
293  typedef std::map<int, XMLCh*> AttrMap;
294 
295  // the map from ids to their unicode-string representation
297 
299  std::map<int, std::string> myPredefinedTagsMML;
301 
302 
304 
305 
306  // the type of the map that maps tag names to ints
307  typedef std::map<std::string, int> TagMap;
308 
309  // the map of tag names to their internal numerical representation
312 
314  std::vector<std::string> myCharactersVector;
315 
318 
321 
323  std::string myFileName;
324 
325 };
326 
327 #endif
328 
329 /****************************************************************************/
330