1 | #ifndef FACT_MessageImp
|
---|
2 | #define FACT_MessageImp
|
---|
3 |
|
---|
4 | #include <string>
|
---|
5 | #include <sstream>
|
---|
6 | #include <iostream>
|
---|
7 |
|
---|
8 | class Time;
|
---|
9 |
|
---|
10 | class MessageImp
|
---|
11 | {
|
---|
12 | public:
|
---|
13 | /// Severity of a message
|
---|
14 | enum Severity
|
---|
15 | {
|
---|
16 | kMessage = 10, ///< Just a message, usually obsolete
|
---|
17 | kInfo = 20, ///< An info telling something which can be interesting to know
|
---|
18 | kWarn = 30, ///< A warning, things that somehow might result in unexpected or unwanted bahaviour
|
---|
19 | kError = 40, ///< Error, something unexpected happened, but can still be handled by the program
|
---|
20 | kFatal = 50, ///< An error which cannot be handled at all happend, the only solution is program termination
|
---|
21 | kDebug = 99, ///< A message used for debugging only
|
---|
22 | };
|
---|
23 |
|
---|
24 | private:
|
---|
25 | std::ostream &fOut; /// The ostream to which by default Write redirects its output
|
---|
26 |
|
---|
27 | public:
|
---|
28 | MessageImp(std::ostream &out=std::cout);
|
---|
29 |
|
---|
30 | virtual int Write(const Time &time, const char *txt, int qos=kInfo);
|
---|
31 |
|
---|
32 | int Update(const char *txt, int qos=kInfo);
|
---|
33 | int Update(const std::string &str, int qos=kInfo) { return Update(str.c_str(), qos); }
|
---|
34 | int Update(const std::stringstream &str, int qos=kInfo) { return Update(str.str(), qos); }
|
---|
35 | int Update(int qos, const char *fmt, ...);
|
---|
36 |
|
---|
37 | int Debug(const char *txt) { return Update(txt, kDebug); }
|
---|
38 | int Message(const char *txt) { return Update(txt, kMessage); }
|
---|
39 | int Info(const char *txt) { return Update(txt, kInfo); }
|
---|
40 | int Warn(const char *txt) { return Update(txt, kWarn); }
|
---|
41 | int Error(const char *txt) { return Update(txt, kError); }
|
---|
42 | int Fatal(const char *txt) { return Update(txt, kFatal); }
|
---|
43 |
|
---|
44 | int Debug(const std::string &str) { return Debug(str.c_str()); }
|
---|
45 | int Message(const std::string &str) { return Message(str.c_str()); }
|
---|
46 | int Info(const std::string &str) { return Info(str.c_str()); }
|
---|
47 | int Warn(const std::string &str) { return Warn(str.c_str()); }
|
---|
48 | int Error(const std::string &str) { return Error(str.c_str()); }
|
---|
49 | int Fatal(const std::string &str) { return Fatal(str.c_str()); }
|
---|
50 |
|
---|
51 | int Debug(const std::stringstream &str) { return Debug(str.str()); }
|
---|
52 | int Message(const std::stringstream &str) { return Message(str.str()); }
|
---|
53 | int Info(const std::stringstream &str) { return Info(str.str()); }
|
---|
54 | int Warn(const std::stringstream &str) { return Warn(str.str()); }
|
---|
55 | int Error(const std::stringstream &str) { return Error(str.str()); }
|
---|
56 | int Fatal(const std::stringstream &str) { return Fatal(str.str()); }
|
---|
57 |
|
---|
58 | std::ostream &operator()() const { return fOut; }
|
---|
59 | std::ostream &Out() const { return fOut; }
|
---|
60 | };
|
---|
61 |
|
---|
62 | #endif
|
---|