SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // A handler which converts occuring elements and attributes into enums 00010 /****************************************************************************/ 00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00013 /****************************************************************************/ 00014 // 00015 // This file is part of SUMO. 00016 // SUMO is free software: you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation, either version 3 of the License, or 00019 // (at your option) any later version. 00020 // 00021 /****************************************************************************/ 00022 #ifndef GenericSAXHandler_h 00023 #define GenericSAXHandler_h 00024 00025 00026 // =========================================================================== 00027 // included modules 00028 // =========================================================================== 00029 #ifdef _MSC_VER 00030 #include <windows_config.h> 00031 #else 00032 #include <config.h> 00033 #endif 00034 00035 #include <string> 00036 #include <map> 00037 #include <stack> 00038 #include <sstream> 00039 #include <vector> 00040 #include <xercesc/sax2/Attributes.hpp> 00041 #include <xercesc/sax2/DefaultHandler.hpp> 00042 #include <utils/common/UtilExceptions.h> 00043 #include <utils/common/StringBijection.h> 00044 #include "SUMOSAXAttributes.h" 00045 00046 00047 // =========================================================================== 00048 // xerces 2.2 compatibility 00049 // =========================================================================== 00050 #if defined(XERCES_HAS_CPP_NAMESPACE) 00051 using namespace XERCES_CPP_NAMESPACE; 00052 #endif 00053 00054 00055 // =========================================================================== 00056 // class definitions 00057 // =========================================================================== 00083 class GenericSAXHandler : public DefaultHandler { 00084 00085 public: 00104 GenericSAXHandler( 00105 StringBijection<int>::Entry* tags, int terminatorTag, 00106 StringBijection<int>::Entry* attrs, int terminatorAttr, 00107 const std::string& file); 00108 00109 00111 virtual ~GenericSAXHandler(); 00112 00113 00126 void startElement(const XMLCh* const uri, const XMLCh* const localname, 00127 const XMLCh* const qname, const Attributes& attrs); 00128 00129 00139 void characters(const XMLCh* const chars, const XERCES3_SIZE_t length); 00140 00141 00154 void endElement(const XMLCh* const uri, const XMLCh* const localname, 00155 const XMLCh* const qname); 00156 00157 00161 void registerParent(const int tag, GenericSAXHandler* handler); 00162 00163 00171 void setFileName(const std::string& name) ; 00172 00173 00179 const std::string& getFileName() const ; 00180 00181 00183 00184 00193 void warning(const SAXParseException& exception) ; 00194 00195 00204 void error(const SAXParseException& exception) ; 00205 00206 00215 void fatalError(const SAXParseException& exception) ; 00217 00218 00219 00220 protected: 00230 std::string buildErrorMessage(const SAXParseException& exception) ; 00231 00232 00241 virtual void myStartElement(int element, 00242 const SUMOSAXAttributes& attrs); 00243 00244 00253 virtual void myCharacters(int element, 00254 const std::string& chars); 00255 00256 00263 virtual void myEndElement(int element); 00264 00265 00266 private: 00274 XMLCh* convert(const std::string& name) const ; 00275 00276 00285 int convertTag(const std::string& tag) const ; 00286 00287 00288 private: 00290 00291 00292 // the type of the map from ids to their unicode-string representation 00293 typedef std::map<int, XMLCh*> AttrMap; 00294 00295 // the map from ids to their unicode-string representation 00296 AttrMap myPredefinedTags; 00297 00299 std::map<int, std::string> myPredefinedTagsMML; 00301 00302 00304 00305 00306 // the type of the map that maps tag names to ints 00307 typedef std::map<std::string, int> TagMap; 00308 00309 // the map of tag names to their internal numerical representation 00310 TagMap myTagMap; 00312 00314 std::vector<std::string> myCharactersVector; 00315 00317 GenericSAXHandler* myParentHandler; 00318 00320 int myParentIndicator; 00321 00323 std::string myFileName; 00324 00325 }; 00326 00327 #endif 00328 00329 /****************************************************************************/ 00330