PVData C++  8.0.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 
20 namespace epics { namespace pvData {
21 
28  class epicsShareClass Status : public epics::pvData::Serializable {
29  public:
30  POINTER_DEFINITIONS(Status);
34  enum StatusType {
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 
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;
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 */
basic_ostream< _CharT, _Traits > & operator<<(basic_ostream< _CharT, _Traits > &__os, const basic_string< _CharT, _Traits, _Alloc > &__str)
const std::string & getStackDump() const
Definition: status.h:86
bool isSuccess() const
Definition: status.h:103
bool isOK() const
Definition: status.h:95
const std::string & getMessage() const
Definition: status.h:80
Callback class for serialization.
Definition: serialize.h:42
StatusType getType() const
Definition: status.h:74
This class implements a Bytebuffer that is like the java.nio.ByteBuffer.
Definition: byteBuffer.h:236
Callback class for deserialization.
Definition: serialize.h:93
Status & operator|=(const Status &o)
short hand for &quot;this-&gt;maximize(o)&quot;
Definition: status.h:132
Base class for serialization.
Definition: serialize.h:138