1 |
chuckv |
1490 |
#include <protomol/base/Report.h> |
2 |
|
|
|
3 |
|
|
#include <iomanip> |
4 |
|
|
|
5 |
|
|
#include <protomol/base/SystemUtilities.h> |
6 |
|
|
|
7 |
|
|
using namespace std; |
8 |
|
|
|
9 |
|
|
namespace ProtoMol { |
10 |
|
|
//____ Report |
11 |
|
|
namespace Report { |
12 |
|
|
MyStreamer &debug::operator()(MyStreamer &stream) const { |
13 |
|
|
stream.setLevel(myLevel); |
14 |
|
|
stream << "DEBUG: "; |
15 |
|
|
return stream; |
16 |
|
|
} |
17 |
|
|
|
18 |
|
|
MyStreamer &reportlevel::operator()(MyStreamer &stream) const { |
19 |
|
|
stream.setReportLevel(myReportlevel); |
20 |
|
|
return stream; |
21 |
|
|
} |
22 |
|
|
//___________________________________________________________ |
23 |
|
|
// Currently defaulting to std::cerr |
24 |
|
|
MyStreamer report(&(std::cerr)); |
25 |
|
|
|
26 |
|
|
// MyStreamer |
27 |
|
|
MyStreamer::MyStreamer(ostream *a) { |
28 |
|
|
setStream(a); |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
// Allows the changing of the stream |
32 |
|
|
ostream *MyStreamer::setStream(ostream *a) { |
33 |
|
|
ostream *tmp = myStream; |
34 |
|
|
myStream = (a != NULL) ? a : &(cerr); |
35 |
|
|
myResetFlags = myStream->flags(); |
36 |
|
|
myAbort = false; |
37 |
|
|
myQuit = false; |
38 |
|
|
myAllNodes = false; |
39 |
|
|
myAllNodesSerial = false; |
40 |
|
|
myAllSlavesSerial = false; |
41 |
|
|
myIAmMaster = true; |
42 |
|
|
myDoHint = true; |
43 |
|
|
mySilentHint = 0; |
44 |
|
|
myReportLevel = 0; |
45 |
|
|
myLevel = 0; |
46 |
|
|
return tmp; |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
void MyStreamer::setAbort(bool flag) { |
50 |
|
|
myAbort = flag; |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
void MyStreamer::setQuit(bool flag) { |
54 |
|
|
myQuit = flag; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
void MyStreamer::setAllNodes(bool flag) { |
58 |
|
|
myAllNodes = flag; |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
void MyStreamer::setf(ios::fmtflags flag) { |
62 |
|
|
myStream->setf(flag); |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
void MyStreamer::setf(ios::fmtflags flag, ios::fmtflags mask) { |
66 |
|
|
myStream->setf(flag, mask); |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
void MyStreamer::precision(int prec) { |
70 |
|
|
myStream->precision(prec); |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
void MyStreamer::width(int wide) { |
74 |
|
|
myStream->width(wide); |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
void MyStreamer::reset() { |
78 |
|
|
myStream->flags(myResetFlags); |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
// MyStreamer |
82 |
|
|
// Standard Overloads |
83 |
|
|
|
84 |
|
|
MyStreamer &MyStreamer::operator<<(bool a) { |
85 |
|
|
if (print()){ |
86 |
|
|
if (a) { |
87 |
|
|
*myStream << "true"; |
88 |
|
|
}else{ |
89 |
|
|
*myStream << "false"; |
90 |
|
|
} |
91 |
|
|
} |
92 |
|
|
return *this; |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
MyStreamer &MyStreamer::operator<<(char a) { |
96 |
|
|
if (print()) |
97 |
|
|
*myStream << a; |
98 |
|
|
return *this; |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
MyStreamer &MyStreamer::operator<<(unsigned char a) { |
102 |
|
|
if (print()) |
103 |
|
|
*myStream << a; |
104 |
|
|
return *this; |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
MyStreamer &MyStreamer::operator<<(signed char a) { |
108 |
|
|
if (print()) |
109 |
|
|
*myStream << a; |
110 |
|
|
return *this; |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
MyStreamer &MyStreamer::operator<<(char *a) { |
114 |
|
|
if (print()) |
115 |
|
|
*myStream << a; |
116 |
|
|
return *this; |
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
MyStreamer &MyStreamer::operator<<(const char *a) { |
120 |
|
|
if (print()) |
121 |
|
|
*myStream << a; |
122 |
|
|
return *this; |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
MyStreamer &MyStreamer::operator<<(unsigned char *a) { |
126 |
|
|
if (print()) |
127 |
|
|
*myStream << a; |
128 |
|
|
return *this; |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
MyStreamer &MyStreamer::operator<<(signed char *a) { |
132 |
|
|
if (print()) |
133 |
|
|
*myStream << a; |
134 |
|
|
return *this; |
135 |
|
|
} |
136 |
|
|
|
137 |
|
|
MyStreamer &MyStreamer::operator<<(short a) { |
138 |
|
|
if (print()) |
139 |
|
|
*myStream << a; |
140 |
|
|
return *this; |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
MyStreamer &MyStreamer::operator<<(unsigned short a) { |
144 |
|
|
if (print()) |
145 |
|
|
*myStream << a; |
146 |
|
|
return *this; |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
MyStreamer &MyStreamer::operator<<(int a) { |
150 |
|
|
if (print()) |
151 |
|
|
*myStream << a; |
152 |
|
|
return *this; |
153 |
|
|
} |
154 |
|
|
|
155 |
|
|
MyStreamer &MyStreamer::operator<<(unsigned int a) { |
156 |
|
|
if (print()) |
157 |
|
|
*myStream << a; |
158 |
|
|
return *this; |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
MyStreamer &MyStreamer::operator<<(long a) { |
162 |
|
|
if (print()) |
163 |
|
|
*myStream << a; |
164 |
|
|
return *this; |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
MyStreamer &MyStreamer::operator<<(unsigned long a) { |
168 |
|
|
if (print()) |
169 |
|
|
*myStream << a; |
170 |
|
|
return *this; |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
MyStreamer &MyStreamer::operator<<(long long a) { |
174 |
|
|
if (print()) |
175 |
|
|
#if (defined (_GLIBCPP_USE_LONG_LONG) || !defined (__GNUC__)) |
176 |
|
|
*myStream << a; |
177 |
|
|
#else |
178 |
|
|
*myStream << (long)a; |
179 |
|
|
#endif |
180 |
|
|
return *this; |
181 |
|
|
} |
182 |
|
|
|
183 |
|
|
MyStreamer &MyStreamer::operator<<(unsigned long long a) { |
184 |
|
|
if (print()) |
185 |
|
|
#if (defined (_GLIBCPP_USE_LONG_LONG) || !defined (__GNUC__)) |
186 |
|
|
*myStream << a; |
187 |
|
|
#else |
188 |
|
|
*myStream << (unsigned long)a; |
189 |
|
|
#endif |
190 |
|
|
return *this; |
191 |
|
|
} |
192 |
|
|
|
193 |
|
|
MyStreamer &MyStreamer::operator<<(float a) { |
194 |
|
|
if (print()) |
195 |
|
|
*myStream << a; |
196 |
|
|
return *this; |
197 |
|
|
} |
198 |
|
|
|
199 |
|
|
MyStreamer &MyStreamer::operator<<(double a) { |
200 |
|
|
if (print()) |
201 |
|
|
*myStream << a; |
202 |
|
|
return *this; |
203 |
|
|
} |
204 |
|
|
|
205 |
|
|
MyStreamer &MyStreamer::operator<<(const ostream &a) { |
206 |
|
|
if (print()) |
207 |
|
|
*myStream << a; |
208 |
|
|
return *this; |
209 |
|
|
} |
210 |
|
|
|
211 |
|
|
MyStreamer &MyStreamer::operator<<(ostream *a) { |
212 |
|
|
if (print()) |
213 |
|
|
*myStream << a; |
214 |
|
|
return *this; |
215 |
|
|
} |
216 |
|
|
|
217 |
|
|
MyStreamer &MyStreamer::operator<<(ios & (*f)(ios &)) { |
218 |
|
|
if (print()) |
219 |
|
|
(*f)(*myStream); |
220 |
|
|
return *this; |
221 |
|
|
} |
222 |
|
|
|
223 |
|
|
MyStreamer &MyStreamer::operator<<(ostream & (*f)(ostream &)) { |
224 |
|
|
if (print()) |
225 |
|
|
(*f)(*myStream); |
226 |
|
|
return *this; |
227 |
|
|
} |
228 |
|
|
|
229 |
|
|
MyStreamer &MyStreamer::operator<<(const string &a) { |
230 |
|
|
if (print()) |
231 |
|
|
*myStream << a; |
232 |
|
|
return *this; |
233 |
|
|
} |
234 |
|
|
|
235 |
|
|
MyStreamer &MyStreamer::operator<<(MyStreamer & (*f)(MyStreamer &)) { |
236 |
|
|
(*f)(*this); |
237 |
|
|
return *this; |
238 |
|
|
} |
239 |
|
|
|
240 |
|
|
// Our Output Levels |
241 |
|
|
|
242 |
|
|
MyStreamer &plain(MyStreamer &stream) { |
243 |
|
|
stream.myLevel = -4; |
244 |
|
|
return stream; |
245 |
|
|
} |
246 |
|
|
|
247 |
|
|
MyStreamer &error(MyStreamer &stream) { |
248 |
|
|
stream.myAbort = true; |
249 |
|
|
stream.myLevel = -3; |
250 |
|
|
if (stream.print()) |
251 |
|
|
stream << "Fatal Error: "; |
252 |
|
|
return stream; |
253 |
|
|
} |
254 |
|
|
|
255 |
|
|
MyStreamer &recoverable(MyStreamer &stream) { |
256 |
|
|
stream.myLevel = -2; |
257 |
|
|
if (stream.print()) |
258 |
|
|
stream << "Recoverable Error: "; |
259 |
|
|
return stream; |
260 |
|
|
} |
261 |
|
|
|
262 |
|
|
MyStreamer &warning(MyStreamer &stream) { |
263 |
|
|
stream.myLevel = -1; |
264 |
|
|
if (stream.print()) |
265 |
|
|
stream << "Warning: "; |
266 |
|
|
return stream; |
267 |
|
|
} |
268 |
|
|
|
269 |
|
|
MyStreamer &hint(MyStreamer &stream) { |
270 |
|
|
stream.myLevel = 0; |
271 |
|
|
if (!stream.myDoHint) |
272 |
|
|
stream.mySilentHint++; |
273 |
|
|
if (stream.print()) |
274 |
|
|
stream << "Hint: "; |
275 |
|
|
return stream; |
276 |
|
|
} |
277 |
|
|
|
278 |
|
|
MyStreamer &operator<<(MyStreamer &stream, const reportlevel &rl) { |
279 |
|
|
return rl(stream); |
280 |
|
|
} |
281 |
|
|
|
282 |
|
|
MyStreamer &operator<<(MyStreamer &stream, const debug &d) { |
283 |
|
|
return d(stream); |
284 |
|
|
} |
285 |
|
|
|
286 |
|
|
MyStreamer &allnodes(MyStreamer &stream) { |
287 |
|
|
stream.myAllNodes = true; |
288 |
|
|
return stream; |
289 |
|
|
} |
290 |
|
|
|
291 |
|
|
MyStreamer &quit(MyStreamer &stream) { |
292 |
|
|
stream.myQuit = true; |
293 |
|
|
return stream; |
294 |
|
|
} |
295 |
|
|
|
296 |
|
|
MyStreamer &aborting(MyStreamer &stream) { |
297 |
|
|
stream.myAbort = true; |
298 |
|
|
return stream; |
299 |
|
|
} |
300 |
|
|
|
301 |
|
|
MyStreamer &dohint(MyStreamer &stream) { |
302 |
|
|
stream.myDoHint = true; |
303 |
|
|
return stream; |
304 |
|
|
} |
305 |
|
|
|
306 |
|
|
MyStreamer &donthint(MyStreamer &stream) { |
307 |
|
|
stream.myDoHint = false; |
308 |
|
|
return stream; |
309 |
|
|
} |
310 |
|
|
|
311 |
|
|
// Our Output Controll |
312 |
|
|
MyStreamer &allnodesserial(MyStreamer &stream) { |
313 |
|
|
stream.myAllNodes = true; |
314 |
|
|
stream.myAllNodesSerial = true; |
315 |
|
|
stream << flush; |
316 |
|
|
protomolStartSerial(false); |
317 |
|
|
return stream; |
318 |
|
|
} |
319 |
|
|
|
320 |
|
|
MyStreamer &allslavesserial(MyStreamer &stream) { |
321 |
|
|
stream.myAllNodes = true; |
322 |
|
|
stream.myAllSlavesSerial = true; |
323 |
|
|
stream << flush; |
324 |
|
|
protomolStartSerial(true); |
325 |
|
|
return stream; |
326 |
|
|
} |
327 |
|
|
|
328 |
|
|
MyStreamer &endr(MyStreamer &stream) { |
329 |
|
|
stream << endl; |
330 |
|
|
if (!stream.myDoHint) |
331 |
|
|
stream.mySilentHint = max(stream.mySilentHint - 1, 0); |
332 |
|
|
if (stream.myQuit) |
333 |
|
|
if (!stream.myAllNodesSerial || !stream.myAllSlavesSerial) |
334 |
|
|
protomolExit(); |
335 |
|
|
else |
336 |
|
|
protomolAbort(); |
337 |
|
|
else if (stream.myAbort) |
338 |
|
|
protomolAbort(); |
339 |
|
|
else if (stream.myAllNodesSerial) |
340 |
|
|
protomolEndSerial(false); |
341 |
|
|
else if (stream.myAllSlavesSerial) |
342 |
|
|
protomolEndSerial(true); |
343 |
|
|
stream.myAllSlavesSerial = false; |
344 |
|
|
stream.myAllNodesSerial = false; |
345 |
|
|
stream.myAllNodes = false; |
346 |
|
|
return stream; |
347 |
|
|
} |
348 |
|
|
} |
349 |
|
|
} |