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