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 
21 typedef std::ostream& (*manipulator) ( std::ostream& os );
22 
24 
34 class 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  {
63  ThreadContext::Lock (warning.context);
64 
65  warning.buffer << t;
66  warning.message += "*";
67  return warning;
68  }
69 
71  friend Warning& operator<< (Warning& warning, const char* t);
72 
74  friend Warning& operator<< (Warning& warning, manipulator m);
75 
76 protected:
77 
79  std::map<std::string, unsigned> messages;
80 
82  std::ostream& output;
83 
85  std::ostringstream buffer;
86 
88  std::string message;
89 
91  void insertion (manipulator m);
92 
95 
96 };
97 
98 
99 #endif
Locks the mutex on construction and unlocks on deletion.
Definition: ThreadContext.h:56
std::string message
The text of the message, without variables.
Definition: Warning.h:88
static bool verbose
Print debugging messages.
Definition: Warning.h:39
std::ostringstream buffer
The buffer used to store the message until a manipulator is inserted.
Definition: Warning.h:85
std::map< std::string, unsigned > messages
Warning messages printed so far.
Definition: Warning.h:79
std::ostream & output
The output stream to which messages are sent.
Definition: Warning.h:82
void insertion(manipulator m)
Does the work for the insertion operator.
Definition: Warning.C:59
friend Warning & operator<<(Warning &warning, const T &t)
Print a variable to the output stream.
Definition: Warning.h:61
bool summary
Print a summary of the number of times a message was repeated.
Definition: Warning.h:57
Handles warning messages in a standardized fashion.
Definition: Warning.h:34
Warning(std::ostream &output=std::cerr)
Construct with a specified output stream.
Definition: Warning.C:14
ThreadContext class.
Definition: ThreadContext.h:15
ThreadContext * context
Multi-thread safe.
Definition: Warning.h:94
bool first
Print first message.
Definition: Warning.h:51
virtual ~Warning()
Destructor prints summary, if requested.
Definition: Warning.C:22
std::string prefix
The prefix printed before each warning message.
Definition: Warning.h:48
bool all
Print every message.
Definition: Warning.h:54

Generated using doxygen 1.8.17