Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:55:05

0001 #ifndef DETECTOR_DESCRIPTION_PARSER_DDL_SAX2_HANDLER_H
0002 #define DETECTOR_DESCRIPTION_PARSER_DDL_SAX2_HANDLER_H
0003 
0004 #include <xercesc/sax2/Attributes.hpp>
0005 #include <xercesc/sax2/DefaultHandler.hpp>
0006 #include <iostream>
0007 #include <string>
0008 #include <vector>
0009 
0010 ///  DDLSAX2Handler inherits from Xerces C++ DefaultHandler.
0011 /** @class DDLSAX2Handler
0012  * @author Michael Case
0013  *
0014  *  DDLSAX2Handler.h  -  description
0015  *  -------------------
0016  *  begin: Mon Oct 22 2001
0017  *
0018  *  The DefaultHandler of Xerces C++ provides an interface to the SAX2 event
0019  *  driven processing of XML documents.  It does so by providing methods which
0020  *  are redefined by the inheriting class (DDLSAX2Handler in this case) to
0021  *  provide the desired processing for each event.
0022  *
0023  *  In this case, we accumulate some statistics.  This class does nothing with
0024  *  startElement and endElement events.
0025  *
0026  */
0027 class DDLSAX2Handler : public XERCES_CPP_NAMESPACE::DefaultHandler {
0028 public:
0029   using Attributes = XERCES_CPP_NAMESPACE::Attributes;
0030   using SAXParseException = XERCES_CPP_NAMESPACE::SAXParseException;
0031 
0032   DDLSAX2Handler();
0033   ~DDLSAX2Handler() override;
0034 
0035   /// Get the count of elements processed so far.
0036   unsigned int getElementCount() const { return elementCount_; }
0037   /// Get the count of attributes processed so far.
0038   unsigned int getAttrCount() const { return attrCount_; }
0039   /// Get the count of characters processed so far.
0040   unsigned int getCharacterCount() const { return characterCount_; }
0041   /// Did the XML parser see any errors?
0042   bool getSawErrors() const { return sawErrors_; }
0043   /// Get the count of spaces processed so far.
0044   unsigned int getSpaceCount() const { return spaceCount_; }
0045 
0046   // -----------------------------------------------------------------------
0047   //  Handlers for the SAX ContentHandler interface
0048   // -----------------------------------------------------------------------
0049 
0050   void startElement(const XMLCh* uri, const XMLCh* localname, const XMLCh* qname, const Attributes& attrs) override;
0051   void endElement(const XMLCh* uri, const XMLCh* localname, const XMLCh* qname) override;
0052   void characters(const XMLCh* chars, XMLSize_t length) override;
0053   void comment(const XMLCh* chars, XMLSize_t length) override;
0054   void ignorableWhitespace(const XMLCh* chars, XMLSize_t length) override;
0055   void resetDocument() override;
0056 
0057   // -----------------------------------------------------------------------
0058   //  Handlers for the SAX ErrorHandler interface
0059   // -----------------------------------------------------------------------
0060   void warning(const SAXParseException& exception) override;
0061   void error(const SAXParseException& exception) override;
0062   void fatalError(const SAXParseException& exception) override;
0063   virtual void dumpStats(const std::string& fname);
0064 
0065 protected:
0066   // -----------------------------------------------------------------------
0067   //  Protected data members
0068   //
0069   //  attrCount_
0070   //  characterCount_
0071   //  elementCount_
0072   //  spaceCount_
0073   //      These are just counters that are run upwards based on the input
0074   //      from the document handlers.
0075   //
0076   //  sawErrors
0077   //      This is set by the error handlers, and is queryable later to
0078   //      see if any errors occurred.
0079   // -----------------------------------------------------------------------
0080   XMLSize_t attrCount_;
0081   XMLSize_t characterCount_;
0082   XMLSize_t elementCount_;
0083   XMLSize_t spaceCount_;
0084   bool sawErrors_;
0085   bool userNS_;
0086   std::string nmspace_;
0087 
0088 public:
0089   /** This allows the DDLSAX2Handler and objects that inherit from it to set
0090    ** the userNS_ flag to indicate 
0091    **     false[default] use the filename of the file being handled as the DD namespace
0092    **     true           assume ALL the "name" attributes have DD namespace specified.
0093    **/
0094   virtual void setUserNS(bool userns);
0095   virtual void setNameSpace(const std::string& nms);
0096 };
0097 
0098 #endif