Warning.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 2006 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9// psrchive/Util/genutil/Warning.h
10
11#ifndef __Warning_h
12#define __Warning_h
13
14#include "ThreadContext.h"
15
16#include <map>
17#include <string>
18#include <sstream>
19#include <iostream>
20
21typedef std::ostream& (*manipulator) ( std::ostream& os );
22
24
34class Warning {
35
36 public:
37
39 static bool verbose;
40
42 Warning (std::ostream& output = std::cerr);
43
45 virtual ~Warning ();
46
48 std::string prefix;
49
51 bool first;
52
54 bool all;
55
57 bool summary;
58
60 template<class T>
61 friend Warning& operator<< (Warning& warning, const T& t)
62 {
64
65 if (verbose)
66 std::cerr << "Warning::operator<<(T) t=" << t << std::endl;
67
68 warning.buffer << t;
69 warning.message += "*";
70 return warning;
71 }
72
74 friend Warning& operator<< (Warning& warning, const char* t);
75
77 friend Warning& operator<< (Warning& warning, manipulator m);
78
79protected:
80
82 std::map<std::string, unsigned> messages;
83
85 std::ostream& output;
86
88 std::ostringstream buffer;
89
91 std::string message;
92
94 void insertion (manipulator m);
95
98
99};
100
101
102#endif
Locks the mutex on construction and unlocks on deletion.
Definition ThreadContext.h:56
ThreadContext class.
Definition ThreadContext.h:15
Handles warning messages in a standardized fashion.
Definition Warning.h:34
void insertion(manipulator m)
Does the work for the insertion operator.
Definition Warning.C:59
std::string message
The text of the message, without variables.
Definition Warning.h:91
bool summary
Print a summary of the number of times a message was repeated.
Definition Warning.h:57
std::ostream & output
The output stream to which messages are sent.
Definition Warning.h:85
bool all
Print every message.
Definition Warning.h:54
std::map< std::string, unsigned > messages
Warning messages printed so far.
Definition Warning.h:82
Warning(std::ostream &output=std::cerr)
Construct with a specified output stream.
Definition Warning.C:14
std::ostringstream buffer
The buffer used to store the message until a manipulator is inserted.
Definition Warning.h:88
ThreadContext * context
Multi-thread safe.
Definition Warning.h:97
std::string prefix
The prefix printed before each warning message.
Definition Warning.h:48
static bool verbose
Print debugging messages.
Definition Warning.h:39
bool first
Print first message.
Definition Warning.h:51
friend Warning & operator<<(Warning &warning, const T &t)
Print a variable to the output stream.
Definition Warning.h:61
virtual ~Warning()
Destructor prints summary, if requested.
Definition Warning.C:22

Generated using doxygen 1.14.0