-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathError.cpp
136 lines (119 loc) · 3.48 KB
/
Error.cpp
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* \file Error.cc
* \brief
*/
#include "Error.h"
//--------------------------------------------------------------------------------------------------
Error::Error()
{
}
//--------------------------------------------------------------------------------------------------
Error::Error(
const Level a_level,
const int a_code,
const std::string &a_msg,
const bool a_expr
) :
_level{a_level},
_code {a_code},
_msg {a_msg},
_expr {a_expr}
{
}
//--------------------------------------------------------------------------------------------------
Error::~Error()
{
}
//--------------------------------------------------------------------------------------------------
bool
Error::isOk() const
{
if (_level == Level::Ok &&
_code == 0 &&
_msg.empty() &&
_expr)
{
return true;
}
return false;
}
//-------------------------------------------------------------------------------------------------
/**************************************************************************************************
* static
*
**************************************************************************************************/
//--------------------------------------------------------------------------------------------------
/* static */
Error
Error::ok()
{
return Error();
}
//--------------------------------------------------------------------------------------------------
/* static */
Error
Error::error(
const Level a_level,
const int a_code,
const std::string &a_msg,
const bool a_expr
)
{
return {a_level, a_code, a_msg, a_expr};
}
//--------------------------------------------------------------------------------------------------
/* static */
Error
Error::test(
const bool a_expr
)
{
return {Level::Error, 10, "Test fail", a_expr};
}
//-------------------------------------------------------------------------------------------------
/**************************************************************************************************
* friend
*
**************************************************************************************************/
//--------------------------------------------------------------------------------------------------
/* friend */
std::ostream &
operator << (
std::ostream &a_stream,
const Error &a_error
)
{
a_stream
<< "{"
<< a_error.isOk() << ", "
<< (int)a_error._level << ", "
<< a_error._code << ", "
<< a_error._msg << ", "
<< a_error._expr
<< "}"
;
return a_stream;
}
//--------------------------------------------------------------------------------------------------
int main(int, char **)
{
std::cout << "ok: " << Error::ok() << std::endl;
std::cout << "error: " << Error::error(Error::Level::Warning, 202, "Warning fail", false) << std::endl;
std::cout << "test: " << Error::test(true) << std::endl;
std::cout << "test: " << Error::test(false) << std::endl;
std::cout << std::endl;
std::cout << "ok: " << Error() << std::endl;
std::cout << "error: " << Error(Error::Level::Warning, 202, "Warning fail", false) << std::endl;
// std::cout << "xxx: " << Error(true) << std::endl;
// std::cout << "xxx: " << Error(false) << std::endl;
return EXIT_SUCCESS;
}
//--------------------------------------------------------------------------------------------------
#if OUTPUT
ok: {1, 0, 0, , 1}
error: {0, 4, 202, Warning fail, 0}
test: {0, 5, 10, Test fail, 1}
test: {0, 5, 10, Test fail, 0}
ok: {1, 0, 0, , 1}
error: {0, 4, 202, Warning fail, 0}
#endif