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 {
29  public:
30  using Attributes = XERCES_CPP_NAMESPACE::Attributes;
31  using SAXParseException = XERCES_CPP_NAMESPACE::SAXParseException;
32 
34  ~DDLSAX2Handler() override;
35 
37  unsigned int getElementCount() const
38  {
39  return elementCount_;
40  }
42  unsigned int getAttrCount() const
43  {
44  return attrCount_;
45  }
47  unsigned int getCharacterCount() const
48  {
49  return characterCount_;
50  }
52  bool getSawErrors() const
53  {
54  return sawErrors_;
55  }
57  unsigned int getSpaceCount() const
58  {
59  return spaceCount_;
60  }
61 
62  // -----------------------------------------------------------------------
63  // Handlers for the SAX ContentHandler interface
64  // -----------------------------------------------------------------------
65 
66  void startElement( const XMLCh* uri, const XMLCh* localname,
67  const XMLCh* qname, const Attributes& attrs ) override;
68  void endElement( const XMLCh* uri, const XMLCh* localname,
69  const XMLCh* qname ) override;
70  void characters( const XMLCh* chars, XMLSize_t length ) override;
71  void comment( const XMLCh* chars, XMLSize_t length ) override;
72  void ignorableWhitespace( const XMLCh* chars, XMLSize_t length ) override;
73  void resetDocument() override;
74 
75  // -----------------------------------------------------------------------
76  // Handlers for the SAX ErrorHandler interface
77  // -----------------------------------------------------------------------
78  void warning(const SAXParseException& exception) override;
79  void error(const SAXParseException& exception) override;
80  void fatalError(const SAXParseException& exception) override;
81  virtual void dumpStats(const std::string& fname);
82 
83  protected:
84 
85  // -----------------------------------------------------------------------
86  // Protected data members
87  //
88  // attrCount_
89  // characterCount_
90  // elementCount_
91  // spaceCount_
92  // These are just counters that are run upwards based on the input
93  // from the document handlers.
94  //
95  // sawErrors
96  // This is set by the error handlers, and is queryable later to
97  // see if any errors occurred.
98  // -----------------------------------------------------------------------
99  XMLSize_t attrCount_;
100  XMLSize_t characterCount_;
101  XMLSize_t elementCount_;
102  XMLSize_t spaceCount_;
104  bool userNS_;
106 
107  public:
113  virtual void setUserNS(bool userns);
114  virtual void setNameSpace(const std::string& nms);
115 };
116 
117 #endif
~DDLSAX2Handler() override
void error(const SAXParseException &exception) override
unsigned int getAttrCount() const
Get the count of attributes processed so far.
XMLSize_t spaceCount_
XMLSize_t characterCount_
XMLSize_t attrCount_
XMLSize_t elementCount_
void fatalError(const SAXParseException &exception) override
void characters(const XMLCh *chars, XMLSize_t length) override
bool getSawErrors() const
Did the XML parser see any errors?
virtual void setUserNS(bool userns)
std::string nmspace_
unsigned int getElementCount() const
Get the count of elements processed so far.
unsigned int getCharacterCount() const
Get the count of characters processed so far.
void comment(const XMLCh *chars, XMLSize_t length) override
unsigned int getSpaceCount() const
Get the count of spaces processed so far.
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.
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