diff --git a/src/misc/pv/status.h b/src/misc/pv/status.h index 1bd9c3f..9093daa 100644 --- a/src/misc/pv/status.h +++ b/src/misc/pv/status.h @@ -53,7 +53,7 @@ namespace epics { namespace pvData { /** * Creates OK status; STATUSTYPE_OK, empty message and stackDump. */ - Status(); + Status() :m_statusType(STATUSTYPE_OK) {} /** * Create non-OK status. @@ -65,25 +65,25 @@ namespace epics { namespace pvData { */ Status(StatusType type, std::string const & message, std::string const & stackDump); - ~Status(); + virtual ~Status() {} /** * Get status type. * @return status type, non-null. */ - StatusType getType() const; + inline StatusType getType() const { return m_statusType; } /** * Get error message describing an error. Required if error status. * @return error message. */ - std::string getMessage() const; + inline std::string getMessage() const { return m_message; } /** * Get stack dump where error (exception) happened. Optional. * @return stack dump. */ - std::string getStackDump() const; + inline std::string getStackDump() const { return m_stackDump; } /** * Convenient OK test. Same as (getType() == StatusType.OK). @@ -92,13 +92,47 @@ namespace epics { namespace pvData { * @return OK status. * @see #isSuccess() */ - bool isOK() const; + inline bool isOK() const { + return (m_statusType == STATUSTYPE_OK); + } /** - * Check if operation succeeded. + * Check if operation succeeded (OK or WARNING). * @return operation success status. */ - bool isSuccess() const; + inline bool isSuccess() const { + return (m_statusType == STATUSTYPE_OK || m_statusType == STATUSTYPE_WARNING); + } + +#if __cplusplus>=201103L + FORCE_INLINE explicit operator bool() const { + return isSuccess(); + } +#else + private: + typedef bool (Status::*truth_type)() const; + public: + FORCE_INLINE operator truth_type() const { + return isSuccess() ? &Status::isSuccess : 0; + } +#endif + + /** override this Status if the other has higher StatusType + @code + Status ret; + ret |= call1(); + if(ret) + ret |= call2(); + return ret; + @endcode + */ + void maximize(const Status& o); + + //! short hand for "this->maximize(o)" + FORCE_INLINE Status& operator|=(const Status& o) { + maximize(o); + return *this; + } void serialize(ByteBuffer *buffer, SerializableControl *flusher) const; void deserialize(ByteBuffer *buffer, DeserializableControl *flusher); @@ -113,8 +147,15 @@ namespace epics { namespace pvData { }; - epicsShareExtern std::ostream& operator<<(std::ostream& o, const Status& status); - epicsShareExtern std::ostream& operator<<(std::ostream& o, const Status::StatusType& statusType); + FORCE_INLINE std::ostream& operator<<(std::ostream& o, const Status& status) { + status.dump(o); + return o; + } + + FORCE_INLINE std::ostream& operator<<(std::ostream& o, const Status::StatusType& statusType) { + o << Status::StatusTypeName[statusType]; + return o; + } }} #endif /* STATUS_H */ diff --git a/src/misc/status.cpp b/src/misc/status.cpp index a2c465f..3097d0c 100644 --- a/src/misc/status.cpp +++ b/src/misc/status.cpp @@ -19,20 +19,11 @@ const char* Status::StatusTypeName[] = { "OK", "WARNING", "ERROR", "FATAL" }; Status Status::Ok; -//PVDATA_REFCOUNT_MONITOR_DEFINE(status); - -Status::Status() : - m_statusType(STATUSTYPE_OK) -{ -} - Status::Status(StatusType type, string const & message) : m_statusType(type), m_message(message) { if (type == STATUSTYPE_OK) throw std::invalid_argument("type == STATUSTYPE_OK"); - - //PVDATA_REFCOUNT_MONITOR_CONSTRUCT(status); } Status::Status(StatusType type, string const & message, string const & stackDump) : @@ -40,38 +31,15 @@ Status::Status(StatusType type, string const & message, string const & stackDump { if (type == STATUSTYPE_OK) throw std::invalid_argument("type == STATUSTYPE_OK"); - - //PVDATA_REFCOUNT_MONITOR_CONSTRUCT(status); } -Status::~Status() { - //PVDATA_REFCOUNT_MONITOR_DESTRUCT(status); -} - -Status::StatusType Status::getType() const +void Status::maximize(const Status& o) { - return m_statusType; -} - - -string Status::getMessage() const -{ - return m_message; -} - -string Status::getStackDump() const -{ - return m_stackDump; -} - -bool Status::isOK() const -{ - return (m_statusType == STATUSTYPE_OK); -} - -bool Status::isSuccess() const -{ - return (m_statusType == STATUSTYPE_OK || m_statusType == STATUSTYPE_WARNING); + if(m_statusType < o.m_statusType) { + m_statusType = o.m_statusType; + m_message = o.m_message; + m_stackDump = o.m_stackDump; + } } void Status::serialize(ByteBuffer *buffer, SerializableControl *flusher) const @@ -120,18 +88,6 @@ void Status::dump(std::ostream& o) const if (!m_stackDump.empty()) o << ", stackDump=" << std::endl << m_stackDump; o << ']'; -} - -std::ostream& operator<<(std::ostream& o, const Status& status) -{ - status.dump(o); - return o; -} - -std::ostream& operator<<(std::ostream& o, const Status::StatusType& statusType) -{ - o << Status::StatusTypeName[statusType]; - return o; } }}