source: trunk/FACT++/src/MessageImp.h@ 13643

Last change on this file since 13643 was 13207, checked in by tbretz, 13 years ago
Addeda new log-class: comments
File size: 3.6 KB
Line 
1#ifndef FACT_MessageImp
2#define FACT_MessageImp
3
4#include <string>
5#include <sstream>
6#include <iostream>
7
8class Time;
9
10class MessageImp
11{
12public:
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 kComment = 90, ///< A comment which is always printed
22 kDebug = 99, ///< A message used for debugging only
23 };
24
25private:
26 std::ostream &fOut; /// The ostream to which by default Write redirects its output
27
28public:
29 MessageImp(std::ostream &out=std::cout);
30 virtual ~MessageImp() { }
31
32 virtual void IndicateStateChange(const Time &, const std::string &) { }
33 void StateChanged(const Time &time, const std::string &server, const std::string &msg, int state);
34 virtual int Write(const Time &time, const std::string &txt, int qos=kMessage);
35
36 int Update(const std::string &txt, int severity=kMessage);
37 int Update(const char *txt, int severity=kMessage) { return Update(std::string(txt), severity); }
38 int Update(const std::ostringstream &str, int severity=kMessage) { return Update(str.str(), severity); }
39// int Update(int qos, const char *fmt, ...);
40
41 int Debug(const std::string &str) { return Update(str, kDebug); }
42 int Message(const std::string &str) { return Update(str, kMessage); }
43 int Info(const std::string &str) { return Update(str, kInfo); }
44 int Warn(const std::string &str) { return Update(str, kWarn); }
45 int Error(const std::string &str) { return Update(str, kError); }
46 int Fatal(const std::string &str) { return Update(str, kFatal); }
47 int Comment(const std::string &str) { return Update(str, kComment); }
48
49 int Debug(const char *txt) { return Debug(std::string(txt)); }
50 int Message(const char *txt) { return Message(std::string(txt)); }
51 int Info(const char *txt) { return Info(std::string(txt)); }
52 int Warn(const char *txt) { return Warn(std::string(txt)); }
53 int Error(const char *txt) { return Error(std::string(txt)); }
54 int Fatal(const char *txt) { return Fatal(std::string(txt)); }
55 int Comment(const char *txt) { return Comment(std::string(txt)); }
56
57 int Debug(const std::ostringstream &str) { return Debug(str.str()); }
58 int Message(const std::ostringstream &str) { return Message(str.str()); }
59 int Info(const std::ostringstream &str) { return Info(str.str()); }
60 int Warn(const std::ostringstream &str) { return Warn(str.str()); }
61 int Error(const std::ostringstream &str) { return Error(str.str()); }
62 int Fatal(const std::ostringstream &str) { return Fatal(str.str()); }
63 int Comment(const std::ostringstream &str) { return Comment(str.str()); }
64
65 std::ostream &operator()() const { return fOut; }
66 std::ostream &Out() const { return fOut; }
67};
68
69#endif
70
71// ***************************************************************************
72/** @fn MessageImp::IndicateStateChange(const Time &time, const std::string &server)
73
74This function is called to indicate a state change by StateChanged() to
75derived classes.
76
77@param time
78 Time at which the state change happened
79
80@param server
81 Server which emitted the state change
82
83**/
84// ***************************************************************************
Note: See TracBrowser for help on using the repository browser.