/DetectorDescription/Parser/interface/DDLSAX2Handler.h

https://github.com/aivanov-cern/cmssw · C Header · 136 lines · 60 code · 16 blank · 60 comment · 0 complexity · 6f986ec16399994dba7861ef6b37bae1 MD5 · raw file

  1. #ifndef DDLSAX2HANDLER_H
  2. #define DDLSAX2HANDLER_H
  3. // ---------------------------------------------------------------------------
  4. // Includes
  5. // ---------------------------------------------------------------------------
  6. // Xerces C++ Dependencies
  7. #include <xercesc/util/XercesDefs.hpp>
  8. #include <xercesc/sax2/Attributes.hpp>
  9. #include <xercesc/sax2/DefaultHandler.hpp>
  10. #include <string>
  11. #include <vector>
  12. #include <iostream>
  13. /// DDLSAX2Handler inherits from Xerces C++ DefaultHandler.
  14. /** @class DDLSAX2Handler
  15. * @author Michael Case
  16. *
  17. * DDLSAX2Handler.h - description
  18. * -------------------
  19. * begin: Mon Oct 22 2001
  20. * email: case@ucdhep.ucdavis.edu
  21. *
  22. * The DefaultHandler of Xerces C++ provides an interface to the SAX2 event
  23. * driven processing of XML documents. It does so by providing methods which
  24. * are redefined by the inheriting class (DDLSAX2Handler in this case) to
  25. * provide the desired processing for each event.
  26. *
  27. * In this case, we accumulate some statistics. This class does nothing with
  28. * startElement and endElement events.
  29. *
  30. */
  31. class DDLSAX2Handler : public XERCES_CPP_NAMESPACE::DefaultHandler
  32. {
  33. public:
  34. typedef XERCES_CPP_NAMESPACE::Attributes Attributes;
  35. typedef XERCES_CPP_NAMESPACE::SAXParseException SAXParseException;
  36. // -----------------------------------------------------------------------
  37. // Constructor and Destructor
  38. // -----------------------------------------------------------------------
  39. // DDLSAX2Handler();
  40. DDLSAX2Handler();
  41. ~DDLSAX2Handler();
  42. // -----------------------------------------------------------------------
  43. // Getter methods
  44. // -----------------------------------------------------------------------
  45. /// Get the count of elements processed so far.
  46. unsigned int getElementCount() const
  47. {
  48. return elementCount_;
  49. }
  50. /// Get the count of attributes processed so far.
  51. unsigned int getAttrCount() const
  52. {
  53. return attrCount_;
  54. }
  55. /// Get the count of characters processed so far.
  56. unsigned int getCharacterCount() const
  57. {
  58. return characterCount_;
  59. }
  60. /// Did the XML parser see any errors?
  61. bool getSawErrors() const
  62. {
  63. return sawErrors_;
  64. }
  65. /// Get the count of spaces processed so far.
  66. unsigned int getSpaceCount() const
  67. {
  68. return spaceCount_;
  69. }
  70. // -----------------------------------------------------------------------
  71. // Handlers for the SAX ContentHandler interface
  72. // -----------------------------------------------------------------------
  73. virtual void startElement(const XMLCh* const uri, const XMLCh* const localname
  74. , const XMLCh* const qname, const Attributes& attrs);
  75. virtual void endElement(const XMLCh* const uri, const XMLCh* const localname
  76. , const XMLCh* const qname);
  77. virtual void characters(const XMLCh* const chars, const unsigned int length);
  78. virtual void comment (const XMLCh *const chars, const unsigned int length );
  79. virtual void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
  80. virtual void resetDocument();
  81. // -----------------------------------------------------------------------
  82. // Handlers for the SAX ErrorHandler interface
  83. // -----------------------------------------------------------------------
  84. virtual void warning(const SAXParseException& exception);
  85. virtual void error(const SAXParseException& exception);
  86. virtual void fatalError(const SAXParseException& exception);
  87. virtual void dumpStats(const std::string& fname);
  88. protected:
  89. // -----------------------------------------------------------------------
  90. // Protected data members
  91. //
  92. // attrCount_
  93. // characterCount_
  94. // elementCount_
  95. // spaceCount_
  96. // These are just counters that are run upwards based on the input
  97. // from the document handlers.
  98. //
  99. // sawErrors
  100. // This is set by the error handlers, and is queryable later to
  101. // see if any errors occurred.
  102. // -----------------------------------------------------------------------
  103. unsigned int attrCount_;
  104. unsigned int characterCount_;
  105. unsigned int elementCount_;
  106. unsigned int spaceCount_;
  107. bool sawErrors_;
  108. bool userNS_;
  109. std::string nmspace_;
  110. /* std::string getnmspace(const std::string& fname); */
  111. public:
  112. /** This allows the DDLSAX2Handler and objects that inherit from it to set
  113. ** the userNS_ flag to indicate
  114. ** false[default] use the filename of the file being handled as the DD namespace
  115. ** true assume ALL the "name" attributes have DD namespace specified.
  116. **/
  117. virtual void setUserNS(bool userns);
  118. virtual void setNameSpace(const std::string& nms);
  119. };
  120. #endif