|
PVData C++
|
00001 /* status.h */ 00002 /* 00003 * Copyright information and license terms for this software can be 00004 * found in the file LICENSE that is included with the distribution 00005 */ 00009 #ifndef STATUS_H 00010 #define STATUS_H 00011 00012 #include <ostream> 00013 00014 #include <pv/serialize.h> 00015 #include <pv/byteBuffer.h> 00016 #include <pv/sharedPtr.h> 00017 00018 #include <shareLib.h> 00019 00020 namespace epics { namespace pvData { 00021 00028 class epicsShareClass Status : public epics::pvData::Serializable { 00029 public: 00030 POINTER_DEFINITIONS(Status); 00034 enum StatusType { 00036 STATUSTYPE_OK, 00038 STATUSTYPE_WARNING, 00040 STATUSTYPE_ERROR, 00042 STATUSTYPE_FATAL 00043 }; 00044 00045 static const char* StatusTypeName[]; 00046 00047 static Status Ok; 00048 00049 static inline Status warn(const std::string& m) { return Status(STATUSTYPE_WARNING, m); } 00050 static inline Status error(const std::string& m) { return Status(STATUSTYPE_ERROR, m); } 00051 static inline Status fatal(const std::string& m) { return Status(STATUSTYPE_FATAL, m); } 00052 00056 Status() :m_statusType(STATUSTYPE_OK) {} 00057 00061 Status(StatusType type, std::string const & message); 00062 00066 Status(StatusType type, std::string const & message, std::string const & stackDump); 00067 00068 virtual ~Status() {} 00069 00074 inline StatusType getType() const { return m_statusType; } 00075 00080 inline std::string getMessage() const { return m_message; } 00081 00086 inline std::string getStackDump() const { return m_stackDump; } 00087 00095 inline bool isOK() const { 00096 return (m_statusType == STATUSTYPE_OK); 00097 } 00098 00103 inline bool isSuccess() const { 00104 return (m_statusType == STATUSTYPE_OK || m_statusType == STATUSTYPE_WARNING); 00105 } 00106 00107 #if __cplusplus>=201103L 00108 FORCE_INLINE explicit operator bool() const { 00109 return isSuccess(); 00110 } 00111 #else 00112 private: 00113 typedef bool (Status::*truth_type)() const; 00114 public: 00115 FORCE_INLINE operator truth_type() const { 00116 return isSuccess() ? &Status::isSuccess : 0; 00117 } 00118 #endif 00119 00129 void maximize(const Status& o); 00130 00132 FORCE_INLINE Status& operator|=(const Status& o) { 00133 maximize(o); 00134 return *this; 00135 } 00136 00137 void serialize(ByteBuffer *buffer, SerializableControl *flusher) const; 00138 void deserialize(ByteBuffer *buffer, DeserializableControl *flusher); 00139 00140 void dump(std::ostream& o) const; 00141 00142 private: 00143 00144 StatusType m_statusType; 00145 std::string m_message; 00146 std::string m_stackDump; 00147 00148 }; 00149 00150 FORCE_INLINE std::ostream& operator<<(std::ostream& o, const Status& status) { 00151 status.dump(o); 00152 return o; 00153 } 00154 00155 FORCE_INLINE std::ostream& operator<<(std::ostream& o, const Status::StatusType& statusType) { 00156 o << Status::StatusTypeName[statusType]; 00157 return o; 00158 } 00159 00160 }} 00161 #endif /* STATUS_H */
1.7.4