CMS 3D CMS Logo

DDLSAX2Handler.h
Go to the documentation of this file.
1 #ifndef DETECTOR_DESCRIPTION_PARSER_DDL_SAX2_HANDLER_H
2 #define DETECTOR_DESCRIPTION_PARSER_DDL_SAX2_HANDLER_H
3 
4 #include <xercesc/sax2/Attributes.hpp>
5 #include <xercesc/sax2/DefaultHandler.hpp>
6 #include <iostream>
7 #include <string>
8 #include <vector>
9 
11 
27 class DDLSAX2Handler : public XERCES_CPP_NAMESPACE::DefaultHandler {
28 public:
29  using Attributes = XERCES_CPP_NAMESPACE::Attributes;
30  using SAXParseException = XERCES_CPP_NAMESPACE::SAXParseException;
31 
33  ~DDLSAX2Handler() override;
34 
36  unsigned int getElementCount() const { return elementCount_; }
38  unsigned int getAttrCount() const { return attrCount_; }
40  unsigned int getCharacterCount() const { return characterCount_; }
42  bool getSawErrors() const { return sawErrors_; }
44  unsigned int getSpaceCount() const { return spaceCount_; }
45 
46  // -----------------------------------------------------------------------
47  // Handlers for the SAX ContentHandler interface
48  // -----------------------------------------------------------------------
49 
50  void startElement(const XMLCh* uri, const XMLCh* localname, const XMLCh* qname, const Attributes& attrs) override;
51  void endElement(const XMLCh* uri, const XMLCh* localname, const XMLCh* qname) override;
52  void characters(const XMLCh* chars, XMLSize_t length) override;
53  void comment(const XMLCh* chars, XMLSize_t length) override;
54  void ignorableWhitespace(const XMLCh* chars, XMLSize_t length) override;
55  void resetDocument() override;
56 
57  // -----------------------------------------------------------------------
58  // Handlers for the SAX ErrorHandler interface
59  // -----------------------------------------------------------------------
60  void warning(const SAXParseException& exception) override;
61  void error(const SAXParseException& exception) override;
62  void fatalError(const SAXParseException& exception) override;
63  virtual void dumpStats(const std::string& fname);
64 
65 protected:
66  // -----------------------------------------------------------------------
67  // Protected data members
68  //
69  // attrCount_
70  // characterCount_
71  // elementCount_
72  // spaceCount_
73  // These are just counters that are run upwards based on the input
74  // from the document handlers.
75  //
76  // sawErrors
77  // This is set by the error handlers, and is queryable later to
78  // see if any errors occurred.
79  // -----------------------------------------------------------------------
80  XMLSize_t attrCount_;
81  XMLSize_t characterCount_;
82  XMLSize_t elementCount_;
83  XMLSize_t spaceCount_;
84  bool sawErrors_;
85  bool userNS_;
87 
88 public:
94  virtual void setUserNS(bool userns);
95  virtual void setNameSpace(const std::string& nms);
96 };
97 
98 #endif
~DDLSAX2Handler() override
void error(const SAXParseException &exception) override
unsigned int getSpaceCount() const
Get the count of spaces processed so far.
XMLSize_t spaceCount_
XMLSize_t characterCount_
XMLSize_t attrCount_
XMLSize_t elementCount_
unsigned int getElementCount() const
Get the count of elements processed so far.
void fatalError(const SAXParseException &exception) override
unsigned int getCharacterCount() const
Get the count of characters processed so far.
void characters(const XMLCh *chars, XMLSize_t length) override
virtual void setUserNS(bool userns)
std::string nmspace_
void comment(const XMLCh *chars, XMLSize_t length) override
void endElement(const XMLCh *uri, const XMLCh *localname, const XMLCh *qname) override
void warning(const SAXParseException &exception) override
void resetDocument() override
string fname
main script
virtual void setNameSpace(const std::string &nms)
void ignorableWhitespace(const XMLCh *chars, XMLSize_t length) override
XERCES_CPP_NAMESPACE::Attributes Attributes
DDLSAX2Handler inherits from Xerces C++ DefaultHandler.
unsigned int getAttrCount() const
Get the count of attributes processed so far.
bool getSawErrors() const
Did the XML parser see any errors?
virtual void dumpStats(const std::string &fname)
XERCES_CPP_NAMESPACE::SAXParseException SAXParseException
void startElement(const XMLCh *uri, const XMLCh *localname, const XMLCh *qname, const Attributes &attrs) override