GenericSAXHandler.h
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GenericSAXHandler_h
00020 #define GenericSAXHandler_h
00021
00022
00023
00024
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 "SUMOXMLDefinitions.h"
00041 #include "SUMOSAXAttributes.h"
00042
00043
00044
00045
00046
00047 #if defined(XERCES_HAS_CPP_NAMESPACE)
00048 using namespace XERCES_CPP_NAMESPACE;
00049 #endif
00050
00051
00052
00053
00054
00080 class GenericSAXHandler : public DefaultHandler {
00081 public:
00086 struct Attr {
00088 const char *name;
00090 SumoXMLAttr key;
00091 };
00092
00097 struct Tag {
00099 const char *name;
00101 SumoXMLTag key;
00102 };
00103
00104
00105 public:
00123 GenericSAXHandler(Tag *tags, Attr *attrs, const std::string &file) throw();
00124
00125
00127 virtual ~GenericSAXHandler() throw();
00128
00129
00142 void startElement(const XMLCh* const uri, const XMLCh* const localname,
00143 const XMLCh* const qname, const Attributes& attrs);
00144
00145
00155 void characters(const XMLCh* const chars, const XERCES3_SIZE_t length);
00156
00157
00170 void endElement(const XMLCh* const uri, const XMLCh* const localname,
00171 const XMLCh* const qname);
00172
00173
00177 void registerParent(const SumoXMLTag tag, GenericSAXHandler* handler);
00178
00179
00187 void setFileName(const std::string &name) throw();
00188
00189
00195 const std::string &getFileName() const throw();
00196
00197
00198 protected:
00207 virtual void myStartElement(SumoXMLTag element,
00208 const SUMOSAXAttributes &attrs) throw(ProcessError);
00209
00210
00219 virtual void myCharacters(SumoXMLTag element,
00220 const std::string &chars) throw(ProcessError);
00221
00222
00229 virtual void myEndElement(SumoXMLTag element) throw(ProcessError);
00230
00231
00232 private:
00240 XMLCh *convert(const std::string &name) const throw();
00241
00242
00251 SumoXMLTag convertTag(const std::string &tag) const throw();
00252
00253
00254 private:
00256
00257
00258
00259 typedef std::map<SumoXMLAttr, XMLCh*> AttrMap;
00260
00261
00262 AttrMap myPredefinedTags;
00263
00265 std::map<SumoXMLAttr, std::string> myPredefinedTagsMML;
00267
00268
00270
00271
00272
00273 typedef std::map<std::string, SumoXMLTag> TagMap;
00274
00275
00276 TagMap myTagMap;
00278
00280 std::vector<std::string> myCharactersVector;
00281
00283 std::string myFileName;
00284
00285 GenericSAXHandler* myParentHandler;
00286 SumoXMLTag myParentIndicator;
00287
00288
00289 };
00290
00291
00292
00293
00294
00295
00297 extern GenericSAXHandler::Tag sumotags[];
00298
00300 extern GenericSAXHandler::Attr sumoattrs[];
00301
00302
00303 #endif
00304
00305
00306