BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
XmlErrorHandler.h
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/xmlBase/xmlBase/XmlErrorHandler.h,v 1.1.1.1 2005/10/17 06:10:27 maqm Exp $
2// Author: J. Bogart
3
4#ifndef xmlBase_XmlErrorHandler_h
5#define xmlBase_XmlErrorHandler_h
6
7#include <xercesc/sax/ErrorHandler.hpp>
8#include <xercesc/sax/SAXParseException.hpp>
9#include <iostream>
10#include <string>
11
12namespace xmlBase {
13 XERCES_CPP_NAMESPACE_USE
14
15 //! Exception class for XmlParser, XmlErrorHandler
16 class ParseException : std::exception {
17 public:
18 ParseException(const std::string& extraInfo = "") : std::exception(),
19 m_name("ParseException"), m_extra(extraInfo) {}
20 virtual ~ParseException() throw() {}
21 virtual std::string getMsg() {
22 std::string msg = m_name + ": " + m_extra;
23 return msg;}
24 virtual const char* what() {
25 return m_extra.c_str();
26 }
27 protected:
28 std::string m_name;
29 private:
30 std::string m_extra;
31 };
32
33
34 /// This class handles errors during parsing of an xml file.
35 /// By default output will go to cerr, but if @a throwErrors is
36 /// set to true an exception of type xml::ParseException will be
37 /// thrown instead
38 class XmlErrorHandler : public XERCES_CPP_NAMESPACE_QUALIFIER ErrorHandler {
39 public:
40 // Constructor, destructor have little to do.
41 XmlErrorHandler(bool throwErrors = false) : m_throwErrors(throwErrors)
42 {resetErrors();}
44 // The following methods all override pure virtual methods
45 // from ErrorHandler base class.
46 /// Keep count of warnings seen
47 void warning(const SAXParseException& exception);
48 /// Output row, column of parse error and increment counter
49 void error(const SAXParseException& exception);
50 /// Output row, column of fatal parse error and increment counter
51 void fatalError(const SAXParseException& exception);
52 /// Clear counters
53 void resetErrors();
54
55 // "get" methods
56 int getWarningCount() const {return m_nWarning;}
57 int getErrorCount() const {return m_nError;}
58 int getFatalCount() const {return m_nFatal;}
59
60 private:
61 int m_nWarning;
62 int m_nError;
63 int m_nFatal;
64 bool m_throwErrors;
65 }; // end class definition
66} // end namespace xml
67
68#endif
Exception class for XmlParser, XmlErrorHandler.
ParseException(const std::string &extraInfo="")
virtual const char * what()
virtual std::string getMsg()
void warning(const SAXParseException &exception)
Keep count of warnings seen.
void resetErrors()
Clear counters.
XmlErrorHandler(bool throwErrors=false)
void fatalError(const SAXParseException &exception)
Output row, column of fatal parse error and increment counter.
void error(const SAXParseException &exception)
Output row, column of parse error and increment counter.