PVData C++ 8.0.7
Loading...
Searching...
No Matches
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 */
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
20namespace epics { namespace pvData {
21
28 class epicsShareClass Status : public epics::pvData::Serializable {
29 public:
30 POINTER_DEFINITIONS(Status);
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
56 Status() :m_statusType(STATUSTYPE_OK) {}
57
61 Status(StatusType type, std::string const & message);
62
66 Status(StatusType type, std::string const & message, std::string const & stackDump);
67
68 virtual ~Status() {}
69
74 inline StatusType getType() const { return m_statusType; }
75
80 inline const std::string& getMessage() const { return m_message; }
81
86 inline const std::string& getStackDump() const { return m_stackDump; }
87
95 inline bool isOK() const {
96 return (m_statusType == STATUSTYPE_OK);
97 }
98
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
129 void maximize(const Status& o);
130
132 FORCE_INLINE Status& operator|=(const Status& o) {
133 maximize(o);
134 return *this;
135 }
136
137 void serialize(ByteBuffer *buffer, SerializableControl *flusher) const;
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 */
basic_ostream< _CharT, _Traits > & operator<<(basic_ostream< _CharT, _Traits > &__os, const basic_string< _CharT, _Traits, _Alloc > &__str)
This class implements a Bytebuffer that is like the java.nio.ByteBuffer.
Definition byteBuffer.h:237
Callback class for deserialization.
Definition serialize.h:93
Callback class for serialization.
Definition serialize.h:42
Base class for serialization.
Definition serialize.h:138
bool isOK() const
Definition status.h:95
const std::string & getMessage() const
Definition status.h:80
Status & operator|=(const Status &o)
short hand for "this->maximize(o)"
Definition status.h:132
StatusType getType() const
Definition status.h:74
void serialize(ByteBuffer *buffer, SerializableControl *flusher) const
void deserialize(ByteBuffer *buffer, DeserializableControl *flusher)
Status(StatusType type, std::string const &message)
Status(StatusType type, std::string const &message, std::string const &stackDump)
bool isSuccess() const
Definition status.h:103
void maximize(const Status &o)
const std::string & getStackDump() const
Definition status.h:86
epics
Definition convert.h:21