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

Last change on this file since 10936 was 10780, checked in by tbretz, 14 years ago
Replaced stringstream in log-stream by ostringstream.
File size: 3.3 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 kDebug = 99, ///< A message used for debugging only
22 };
23
24private:
25 std::ostream &fOut; /// The ostream to which by default Write redirects its output
26
27public:
28 MessageImp(std::ostream &out=std::cout);
29
30 virtual void IndicateStateChange(const Time &, const std::string &) { }
31 void StateChanged(const Time &time, const std::string &server, const std::string &msg, int state);
32 virtual int Write(const Time &time, const std::string &txt, int qos=kInfo);
33
34 int Update(const std::string &txt, int severity=kInfo);
35 int Update(const char *txt, int severity=kInfo) { return Update(std::string(txt), severity); }
36 int Update(const std::ostringstream &str, int severity=kInfo) { return Update(str.str(), severity); }
37// int Update(int qos, const char *fmt, ...);
38
39 int Debug(const std::string &str) { return Update(str, kDebug); }
40 int Message(const std::string &str) { return Update(str, kMessage); }
41 int Info(const std::string &str) { return Update(str, kInfo); }
42 int Warn(const std::string &str) { return Update(str, kWarn); }
43 int Error(const std::string &str) { return Update(str, kError); }
44 int Fatal(const std::string &str) { return Update(str, kFatal); }
45
46 int Debug(const char *txt) { return Debug(std::string(txt)); }
47 int Message(const char *txt) { return Message(std::string(txt)); }
48 int Info(const char *txt) { return Info(std::string(txt)); }
49 int Warn(const char *txt) { return Warn(std::string(txt)); }
50 int Error(const char *txt) { return Error(std::string(txt)); }
51 int Fatal(const char *txt) { return Fatal(std::string(txt)); }
52
53 int Debug(const std::ostringstream &str) { return Debug(str.str()); }
54 int Message(const std::ostringstream &str) { return Message(str.str()); }
55 int Info(const std::ostringstream &str) { return Info(str.str()); }
56 int Warn(const std::ostringstream &str) { return Warn(str.str()); }
57 int Error(const std::ostringstream &str) { return Error(str.str()); }
58 int Fatal(const std::ostringstream &str) { return Fatal(str.str()); }
59
60 std::ostream &operator()() const { return fOut; }
61 std::ostream &Out() const { return fOut; }
62};
63
64#endif
65
66// ***************************************************************************
67/** @fn MessageImp::IndicateStateChange(const Time &time, const std::string &server)
68
69This function is called to indicate a state change by StateChanged() to
70derived classes.
71
72@param time
73 Time at which the state change happened
74
75@param server
76 Server which emitted the state change
77
78**/
79// ***************************************************************************
Note: See TracBrowser for help on using the repository browser.