From f0b7d5960d6c0bab6c4d8126be296b39f21c3134 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 10 Oct 2018 18:54:24 +0000 Subject: Add Observable::ObservedPtr::HasObservable(). if (pObserved->HasObservable()) is more readable than if (*pObserved). Change-Id: I61ad3deb8e9f30cdc120a05555c2558f34489681 Reviewed-on: https://pdfium-review.googlesource.com/c/43811 Commit-Queue: Lei Zhang Reviewed-by: Tom Sepez --- core/fxcrt/observable.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/fxcrt/observable.h b/core/fxcrt/observable.h index e118dc898b..3205bc09df 100644 --- a/core/fxcrt/observable.h +++ b/core/fxcrt/observable.h @@ -46,6 +46,7 @@ class Observable { ASSERT(m_pObservable); m_pObservable = nullptr; } + bool HasObservable() const { return !!m_pObservable; } ObservedPtr& operator=(const ObservedPtr& that) { Reset(that.Get()); return *this; @@ -54,7 +55,7 @@ class Observable { return m_pObservable == that.m_pObservable; } bool operator!=(const ObservedPtr& that) const { return !(*this == that); } - explicit operator bool() const { return !!m_pObservable; } + explicit operator bool() const { return HasObservable(); } T* Get() const { return m_pObservable; } T& operator*() const { return *m_pObservable; } T* operator->() const { return m_pObservable; } -- cgit v1.2.3