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