OSDN Git Service

change EOL style to CRLF to adjust to default setting of Visual Studio
[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) { m_ost << i_em.getMessage(); }\r
22 \r
23   /// get error message\r
24   tstring getMessage() const\r
25   {\r
26     return m_ost.str();\r
27   }\r
28 \r
29   /// add message\r
30   template<class T> ErrorMessage &operator<<(const T &i_value)\r
31   {\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   {\r
40     m_ost << i_manip;\r
41     return *this;\r
42   }\r
43 \r
44 #ifdef UNICODE\r
45   /// add message\r
46   template<> ErrorMessage &operator<<(const std::string &i_value)\r
47   {\r
48     m_ost << to_wstring(i_value);\r
49     return *this;\r
50   }\r
51 \r
52   /// add message\r
53   typedef const char *const_char_ptr;\r
54   template<> ErrorMessage &operator<<(const const_char_ptr &i_value)\r
55   {\r
56     m_ost << to_wstring(i_value);\r
57     return *this;\r
58   }\r
59 #endif\r
60   \r
61   /// stream output\r
62   friend tostream &operator<<(tostream &i_ost, const ErrorMessage &i_em);\r
63 };\r
64 \r
65 \r
66 /// stream output\r
67 inline tostream &operator<<(tostream &i_ost, const ErrorMessage &i_em)\r
68 {\r
69   return i_ost << i_em.getMessage();\r
70 }\r
71 \r
72 \r
73 ///\r
74 class WarningMessage : public ErrorMessage\r
75 {\r
76 public:\r
77   /// add message\r
78   template<class T> WarningMessage &operator<<(const T &i_value)\r
79   {\r
80     ErrorMessage::operator<<(i_value);\r
81     return *this;\r
82   }\r
83 };\r
84 \r
85 \r
86 #endif // !_ERRORMESSAGE_H\r