PageRenderTime 22ms CodeModel.GetById 15ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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