OSDN Git Service

fix ticket #18663
[yamy/yamy.git] / errormessage.h
1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
2 // errormessage.h\r
3 \r
4 \r
5 #ifndef _ERRORMESSAGE_H\r
6 #  define _ERRORMESSAGE_H\r
7 \r
8 #  include "stringtool.h"\r
9 #  include <sstream>\r
10 \r
11 \r
12 ///\r
13 class ErrorMessage\r
14 {\r
15         tstringstream m_ost;                            ///\r
16 \r
17 public:\r
18         ///\r
19         ErrorMessage() { }\r
20         ///\r
21         ErrorMessage(const ErrorMessage &i_em) {\r
22                 m_ost << i_em.getMessage();\r
23         }\r
24 \r
25         /// get error message\r
26         tstring getMessage() const {\r
27                 return m_ost.str();\r
28         }\r
29 \r
30         /// add message\r
31         template<class T> ErrorMessage &operator<<(const T &i_value) {\r
32                 m_ost << i_value;\r
33                 return *this;\r
34         }\r
35 \r
36         /// ios manipulator\r
37         ErrorMessage &operator<<(\r
38                 std::ios_base &(*i_manip)(std::ios_base&)) {\r
39                 m_ost << i_manip;\r
40                 return *this;\r
41         }\r
42 \r
43 #ifdef UNICODE\r
44         /// add message\r
45         template<> ErrorMessage &operator<<(const std::string &i_value) {\r
46                 m_ost << to_wstring(i_value);\r
47                 return *this;\r
48         }\r
49 \r
50         /// add message\r
51         typedef const char *const_char_ptr;\r
52         template<> ErrorMessage &operator<<(const const_char_ptr &i_value) {\r
53                 m_ost << to_wstring(i_value);\r
54                 return *this;\r
55         }\r
56 #endif\r
57 \r
58         /// stream output\r
59         friend tostream &operator<<(tostream &i_ost, const ErrorMessage &i_em);\r
60 };\r
61 \r
62 \r
63 /// stream output\r
64 inline tostream &operator<<(tostream &i_ost, const ErrorMessage &i_em)\r
65 {\r
66         return i_ost << i_em.getMessage();\r
67 }\r
68 \r
69 \r
70 ///\r
71 class WarningMessage : public ErrorMessage\r
72 {\r
73 public:\r
74         /// add message\r
75         template<class T> WarningMessage &operator<<(const T &i_value) {\r
76                 ErrorMessage::operator<<(i_value);\r
77                 return *this;\r
78         }\r
79 };\r
80 \r
81 \r
82 #endif // !_ERRORMESSAGE_H\r