]> matita.cs.unibo.it Git - helm.git/blob - helm/papers/use_case/stats/parse/DOMCount/DOMCount.hpp
ocaml 3.09 transition
[helm.git] / helm / papers / use_case / stats / parse / DOMCount / DOMCount.hpp
1 /*
2  * Copyright 1999-2000,2004 The Apache Software Foundation.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /*
18  * $Log$
19  * Revision 1.1  2004/11/23 13:38:52  lpadovan
20  * * basic infrastructure for collecting statistics
21  *
22  * Revision 1.11  2004/09/08 13:55:31  peiyongz
23  * Apache License Version 2.0
24  *
25  * Revision 1.10  2003/05/30 09:36:35  gareth
26  * Use new macros for iostream.h and std:: issues.
27  *
28  * Revision 1.9  2003/02/05 18:53:22  tng
29  * [Bug 11915] Utility for freeing memory.
30  *
31  * Revision 1.8  2002/11/05 21:46:19  tng
32  * Explicit code using namespace in application.
33  *
34  * Revision 1.7  2002/06/18 16:19:40  knoaman
35  * Replace XercesDOMParser with DOMBuilder for parsing XML documents.
36  *
37  * Revision 1.6  2002/02/01 22:35:01  peiyongz
38  * sane_include
39  *
40  * Revision 1.5  2000/10/20 22:00:35  andyh
41  * DOMCount sample Minor cleanup - rename error handler class to say that it is an error handler.
42  *
43  * Revision 1.4  2000/03/02 19:53:39  roddey
44  * This checkin includes many changes done while waiting for the
45  * 1.1.0 code to be finished. I can't list them all here, but a list is
46  * available elsewhere.
47  *
48  * Revision 1.3  2000/02/11 02:43:55  abagchi
49  * Removed StrX::transcode
50  *
51  * Revision 1.2  2000/02/06 07:47:17  rahulj
52  * Year 2K copyright swat.
53  *
54  * Revision 1.1.1.1  1999/11/09 01:09:52  twl
55  * Initial checkin
56  *
57  * Revision 1.5  1999/11/08 20:43:35  rahul
58  * Swat for adding in Product name and CVS comment log variable.
59  *
60  */
61
62 // ---------------------------------------------------------------------------
63 //  Includes
64 // ---------------------------------------------------------------------------
65 #include <xercesc/dom/DOMErrorHandler.hpp>
66 #include <xercesc/util/XMLString.hpp>
67 #if defined(XERCES_NEW_IOSTREAMS)
68 #include <iostream>
69 #else
70 #include <iostream.h>
71 #endif
72
73 XERCES_CPP_NAMESPACE_USE
74
75 // ---------------------------------------------------------------------------
76 //  Simple error handler deriviative to install on parser
77 // ---------------------------------------------------------------------------
78 class DOMCountErrorHandler : public DOMErrorHandler
79 {
80 public:
81     // -----------------------------------------------------------------------
82     //  Constructors and Destructor
83     // -----------------------------------------------------------------------
84     DOMCountErrorHandler();
85     ~DOMCountErrorHandler();
86
87
88     // -----------------------------------------------------------------------
89     //  Getter methods
90     // -----------------------------------------------------------------------
91     bool getSawErrors() const;
92
93
94     // -----------------------------------------------------------------------
95     //  Implementation of the DOM ErrorHandler interface
96     // -----------------------------------------------------------------------
97     bool handleError(const DOMError& domError);
98     void resetErrors();
99
100
101 private :
102     // -----------------------------------------------------------------------
103     //  Unimplemented constructors and operators
104     // -----------------------------------------------------------------------
105     DOMCountErrorHandler(const DOMCountErrorHandler&);
106     void operator=(const DOMCountErrorHandler&);
107
108
109     // -----------------------------------------------------------------------
110     //  Private data members
111     //
112     //  fSawErrors
113     //      This is set if we get any errors, and is queryable via a getter
114     //      method. Its used by the main code to suppress output if there are
115     //      errors.
116     // -----------------------------------------------------------------------
117     bool    fSawErrors;
118 };
119
120
121 // ---------------------------------------------------------------------------
122 //  This is a simple class that lets us do easy (though not terribly efficient)
123 //  trancoding of XMLCh data to local code page for display.
124 // ---------------------------------------------------------------------------
125 class StrX
126 {
127 public :
128     // -----------------------------------------------------------------------
129     //  Constructors and Destructor
130     // -----------------------------------------------------------------------
131     StrX(const XMLCh* const toTranscode)
132     {
133         // Call the private transcoding method
134         fLocalForm = XMLString::transcode(toTranscode);
135     }
136
137     ~StrX()
138     {
139         XMLString::release(&fLocalForm);
140     }
141
142
143     // -----------------------------------------------------------------------
144     //  Getter methods
145     // -----------------------------------------------------------------------
146     const char* localForm() const
147     {
148         return fLocalForm;
149     }
150
151 private :
152     // -----------------------------------------------------------------------
153     //  Private data members
154     //
155     //  fLocalForm
156     //      This is the local code page form of the string.
157     // -----------------------------------------------------------------------
158     char*   fLocalForm;
159 };
160
161 inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
162 {
163     target << toDump.localForm();
164     return target;
165 }
166
167 inline bool DOMCountErrorHandler::getSawErrors() const
168 {
169     return fSawErrors;
170 }