PVData C++
8.0.2
misc
pv
status.h
1
/* status.h */
2
/*
3
* Copyright information and license terms for this software can be
4
* found in the file LICENSE that is included with the distribution
5
*/
6
/**
7
* @author mse
8
*/
9
#
ifndef
STATUS_H
10
#
define
STATUS_H
11
12
#
include
<
ostream
>
13
14
#
include
<
pv
/
serialize
.
h
>
15
#
include
<
pv
/
byteBuffer
.
h
>
16
#
include
<
pv
/
sharedPtr
.
h
>
17
18
#
include
<
shareLib
.
h
>
19
20
namespace
epics {
namespace
pvData
{
21
22
/**
23
* @brief Status.
24
*
25
* This is a class for returning status to clients.
26
* @author mse
27
*/
28
class
epicsShareClass
Status
:
public
epics
::
pvData
::
Serializable
{
29
public
:
30
POINTER_DEFINITIONS
(
Status
);
31
/**
32
* Status type enum.
33
*/
34
enum
StatusType
{
35
/** Operation completed successfully. */
36
STATUSTYPE_OK
,
37
/** Operation completed successfully, but there is a warning message. */
38
STATUSTYPE_WARNING
,
39
/** Operation failed due to an error. */
40
STATUSTYPE_ERROR
,
41
/** Operation failed due to an unexpected error. */
42
STATUSTYPE_FATAL
43
};
44
45
static
const
char
*
StatusTypeName
[];
46
47
static
Status
Ok
;
48
49
static
inline
Status
warn
(
const
std
::
string
&
m
) {
return
Status
(
STATUSTYPE_WARNING
,
m
); }
50
static
inline
Status
error
(
const
std
::
string
&
m
) {
return
Status
(
STATUSTYPE_ERROR
,
m
); }
51
static
inline
Status
fatal
(
const
std
::
string
&
m
) {
return
Status
(
STATUSTYPE_FATAL
,
m
); }
52
53
/**
54
* Creates OK status; STATUSTYPE_OK, empty message and stackDump.
55
*/
56
Status
() :
m_statusType
(
STATUSTYPE_OK
) {}
57
58
/**
59
* Create non-OK status.
60
*/
61
Status
(
StatusType
type
,
std
::
string
const
&
message
);
62
63
/**
64
* Create non-OK status.
65
*/
66
Status
(
StatusType
type
,
std
::
string
const
&
message
,
std
::
string
const
&
stackDump
);
67
68
virtual
~
Status
() {}
69
70
/**
71
* Get status type.
72
* @return status type, non-<code>null</code>.
73
*/
74
inline
StatusType
getType
()
const
{
return
m_statusType
; }
75
76
/**
77
* Get error message describing an error. Required if error status.
78
* @return error message.
79
*/
80
inline
const
std
::
string
&
getMessage
()
const
{
return
m_message
; }
81
82
/**
83
* Get stack dump where error (exception) happened. Optional.
84
* @return stack dump.
85
*/
86
inline
const
std
::
string
&
getStackDump
()
const
{
return
m_stackDump
; }
87
88
/**
89
* Convenient OK test. Same as <code>(getType() == StatusType.OK)</code>.
90
* NOTE: this will return <code>false</code> on WARNING message although operation succeeded.
91
* To check if operation succeeded, use <code>isSuccess</code>.
92
* @return OK status.
93
* @see #isSuccess()
94
*/
95
inline
bool
isOK
()
const
{
96
return
(
m_statusType
==
STATUSTYPE_OK
);
97
}
98
99
/**
100
* Check if operation succeeded (OK or WARNING).
101
* @return operation success status.
102
*/
103
inline
bool
isSuccess
()
const
{
104
return
(
m_statusType
==
STATUSTYPE_OK
||
m_statusType
==
STATUSTYPE_WARNING
);
105
}
106
107
#
if
__cplusplus
>=
201103L
108
FORCE_INLINE
explicit
operator
bool
()
const
{
109
return
isSuccess
();
110
}
111
#
else
112
private
:
113
typedef
bool
(
Status
::*
truth_type
)()
const
;
114
public
:
115
FORCE_INLINE
operator
truth_type
()
const
{
116
return
isSuccess
() ? &
Status
::
isSuccess
: 0;
117
}
118
#
endif
119
120
/** override this Status if the other has higher StatusType
121
@code
122
Status ret;
123
ret |= call1();
124
if(ret)
125
ret |= call2();
126
return ret;
127
@endcode
128
*/
129
void
maximize
(
const
Status
&
o
);
130
131
//! short hand for "this->maximize(o)"
132
FORCE_INLINE
Status
&
operator
|=(
const
Status
&
o
) {
133
maximize
(
o
);
134
return
*
this
;
135
}
136
137
void
serialize
(
ByteBuffer
*
buffer
,
SerializableControl
*
flusher
)
const
;
138
void
deserialize
(
ByteBuffer
*
buffer
,
DeserializableControl
*
flusher
);
139
140
void
dump
(
std
::
ostream
&
o
)
const
;
141
142
private
:
143
144
StatusType
m_statusType
;
145
std
::
string
m_message
;
146
std
::
string
m_stackDump
;
147
148
};
149
150
FORCE_INLINE
std::ostream& operator<<(std::ostream& o,
const
Status& status) {
151
status.dump(o);
152
return
o;
153
}
154
155
FORCE_INLINE
std::ostream& operator<<(std::ostream& o,
const
Status::StatusType& statusType) {
156
o << Status::StatusTypeName[statusType];
157
return
o;
158
}
159
160
}}
161
#
endif
/* STATUS_H */
POINTER_DEFINITIONS
#define POINTER_DEFINITIONS(clazz)
Definition:
sharedPtr.h:198
FORCE_INLINE
#define FORCE_INLINE
Definition:
templateMeta.h:20
epics::pvData::yajl_parse_helper
epicsShareFunc bool yajl_parse_helper(std::istream &src, yajl_handle handle)
epics::pvData::Status
Status.
Definition:
status.h:28
Generated on Sat Jul 11 2020 19:33:56 for PVData C++ by
1.8.13