From 0c6fe2c1c627f4f43c82bf1a3d5654ae38f6d290 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Sun, 8 Apr 2018 16:04:36 -0700 Subject: [PATCH] client.h: add validity test for all handles --- src/client/pva/client.h | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/client/pva/client.h b/src/client/pva/client.h index 21f6b3a..e594ad3 100644 --- a/src/client/pva/client.h +++ b/src/client/pva/client.h @@ -64,6 +64,17 @@ struct epicsShareClass Operation //! Does not wait for remote confirmation. void cancel(); + bool valid() const { return !!impl; } + +#if __cplusplus>=201103L + explicit operator bool() const { return valid(); } +#else +private: + typedef bool (Operation::*bool_type)() const; +public: + operator bool_type() const { return valid() ? &Operation::valid : 0; } +#endif + protected: std::tr1::shared_ptr impl; }; @@ -133,6 +144,17 @@ struct epicsShareClass Monitor epics::pvData::BitSet changed, overrun; + bool valid() const { return !!impl; } + +#if __cplusplus>=201103L + explicit operator bool() const { return valid(); } +#else +private: + typedef bool (Monitor::*bool_type)() const; +public: + operator bool_type() const { return valid() ? &Monitor::valid : 0; } +#endif + private: std::tr1::shared_ptr impl; friend struct MonitorSync; @@ -247,6 +269,17 @@ public: //! Channel name or an empty string std::string name() const; + bool valid() const { return !!impl; } + +#if __cplusplus>=201103L + explicit operator bool() const { return valid(); } +#else +private: + typedef bool (ClientChannel::*bool_type)() const; +public: + operator bool_type() const { return valid() ? &ClientChannel::valid : 0; } +#endif + //! callback for get() and rpc() struct GetCallback { virtual ~GetCallback() {} @@ -450,6 +483,17 @@ public: //! Clear channel cache void disconnect(); + + bool valid() const { return !!impl; } + +#if __cplusplus>=201103L + explicit operator bool() const { return valid(); } +#else +private: + typedef bool (ClientProvider::*bool_type)() const; +public: + operator bool_type() const { return valid() ? &ClientProvider::valid : 0; } +#endif };