|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A handler which converts occuring elements and attributes into enums 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 #ifndef GenericSAXHandler_h 00020 #define GenericSAXHandler_h 00021 00022 00023 // =========================================================================== 00024 // included modules 00025 // =========================================================================== 00026 #ifdef _MSC_VER 00027 #include <windows_config.h> 00028 #else 00029 #include <config.h> 00030 #endif 00031 00032 #include <string> 00033 #include <map> 00034 #include <stack> 00035 #include <sstream> 00036 #include <vector> 00037 #include <xercesc/sax2/Attributes.hpp> 00038 #include <xercesc/sax2/DefaultHandler.hpp> 00039 #include <utils/common/UtilExceptions.h> 00040 #include <utils/common/StringBijection.h> 00041 #include "SUMOSAXAttributes.h" 00042 00043 00044 // =========================================================================== 00045 // xerces 2.2 compatibility 00046 // =========================================================================== 00047 #if defined(XERCES_HAS_CPP_NAMESPACE) 00048 using namespace XERCES_CPP_NAMESPACE; 00049 #endif 00050 00051 00052 // =========================================================================== 00053 // class definitions 00054 // =========================================================================== 00080 class GenericSAXHandler : public DefaultHandler { 00081 00082 public: 00101 GenericSAXHandler( 00102 StringBijection<int>::Entry* tags, int terminatorTag, 00103 StringBijection<int>::Entry* attrs, int terminatorAttr, 00104 const std::string& file); 00105 00106 00108 virtual ~GenericSAXHandler(); 00109 00110 00123 void startElement(const XMLCh* const uri, const XMLCh* const localname, 00124 const XMLCh* const qname, const Attributes& attrs); 00125 00126 00136 void characters(const XMLCh* const chars, const XERCES3_SIZE_t length); 00137 00138 00151 void endElement(const XMLCh* const uri, const XMLCh* const localname, 00152 const XMLCh* const qname); 00153 00154 00158 void registerParent(const int tag, GenericSAXHandler* handler); 00159 00160 00168 void setFileName(const std::string& name) throw(); 00169 00170 00176 const std::string& getFileName() const throw(); 00177 00178 00180 00181 00190 void warning(const SAXParseException& exception) throw(); 00191 00192 00201 void error(const SAXParseException& exception) throw(ProcessError); 00202 00203 00212 void fatalError(const SAXParseException& exception) throw(ProcessError); 00214 00215 00216 00217 protected: 00227 std::string buildErrorMessage(const SAXParseException& exception) throw(); 00228 00229 00238 virtual void myStartElement(int element, 00239 const SUMOSAXAttributes& attrs); 00240 00241 00250 virtual void myCharacters(int element, 00251 const std::string& chars); 00252 00253 00260 virtual void myEndElement(int element); 00261 00262 00263 private: 00271 XMLCh* convert(const std::string& name) const throw(); 00272 00273 00282 int convertTag(const std::string& tag) const throw(); 00283 00284 00285 private: 00287 00288 00289 // the type of the map from ids to their unicode-string representation 00290 typedef std::map<int, XMLCh*> AttrMap; 00291 00292 // the map from ids to their unicode-string representation 00293 AttrMap myPredefinedTags; 00294 00296 std::map<int, std::string> myPredefinedTagsMML; 00298 00299 00301 00302 00303 // the type of the map that maps tag names to ints 00304 typedef std::map<std::string, int> TagMap; 00305 00306 // the map of tag names to their internal numerical representation 00307 TagMap myTagMap; 00309 00311 std::vector<std::string> myCharactersVector; 00312 00314 GenericSAXHandler* myParentHandler; 00315 00317 int myParentIndicator; 00318 00320 std::string myFileName; 00321 00322 }; 00323 00324 #endif 00325 00326 /****************************************************************************/ 00327