summaryrefslogtreecommitdiff
path: root/core/fxcrt/cfx_observable.h
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-12-28 11:16:15 -0800
committerCommit bot <commit-bot@chromium.org>2016-12-28 11:16:15 -0800
commitd0bbccdd32113baf95ae16565c0314166d989638 (patch)
tree08d7c16a7a29919efc8b6c91fbde3baef835e533 /core/fxcrt/cfx_observable.h
parent04a407093c135cdf08644a03c210ae2182869254 (diff)
downloadpdfium-d0bbccdd32113baf95ae16565c0314166d989638.tar.xz
Make CFX_Observable copy constructable.chromium/2969chromium/2968chromium/2967chromium/2966
Fix some naming to make things clearer. Review-Url: https://codereview.chromium.org/2587233002
Diffstat (limited to 'core/fxcrt/cfx_observable.h')
-rw-r--r--core/fxcrt/cfx_observable.h47
1 files changed, 25 insertions, 22 deletions
diff --git a/core/fxcrt/cfx_observable.h b/core/fxcrt/cfx_observable.h
index dc869b1766..8dc0907cae 100644
--- a/core/fxcrt/cfx_observable.h
+++ b/core/fxcrt/cfx_observable.h
@@ -15,39 +15,42 @@ class CFX_Observable {
public:
class ObservedPtr {
public:
- ObservedPtr() : m_pObservedPtr(nullptr) {}
- explicit ObservedPtr(T* pObservedPtr) : m_pObservedPtr(pObservedPtr) {
- if (m_pObservedPtr)
- m_pObservedPtr->AddObservedPtr(this);
+ ObservedPtr() : m_pObservable(nullptr) {}
+ explicit ObservedPtr(T* pObservable) : m_pObservable(pObservable) {
+ if (m_pObservable)
+ m_pObservable->AddObservedPtr(this);
}
- ObservedPtr(const ObservedPtr& that) = delete;
+ ObservedPtr(const ObservedPtr& that) : ObservedPtr(that.Get()) {}
~ObservedPtr() {
- if (m_pObservedPtr)
- m_pObservedPtr->RemoveObservedPtr(this);
+ if (m_pObservable)
+ m_pObservable->RemoveObservedPtr(this);
}
- void Reset(T* pObservedPtr = nullptr) {
- if (m_pObservedPtr)
- m_pObservedPtr->RemoveObservedPtr(this);
- m_pObservedPtr = pObservedPtr;
- if (m_pObservedPtr)
- m_pObservedPtr->AddObservedPtr(this);
+ void Reset(T* pObservable = nullptr) {
+ if (m_pObservable)
+ m_pObservable->RemoveObservedPtr(this);
+ m_pObservable = pObservable;
+ if (m_pObservable)
+ m_pObservable->AddObservedPtr(this);
}
void OnDestroy() {
- ASSERT(m_pObservedPtr);
- m_pObservedPtr = nullptr;
+ ASSERT(m_pObservable);
+ m_pObservable = nullptr;
+ }
+ ObservedPtr& operator=(const ObservedPtr& that) {
+ Reset(that.Get());
+ return *this;
}
- ObservedPtr& operator=(const ObservedPtr& that) = delete;
bool operator==(const ObservedPtr& that) const {
- return m_pObservedPtr == that.m_pObservedPtr;
+ return m_pObservable == that.m_pObservable;
}
bool operator!=(const ObservedPtr& that) const { return !(*this == that); }
- explicit operator bool() const { return !!m_pObservedPtr; }
- T* Get() const { return m_pObservedPtr; }
- T& operator*() const { return *m_pObservedPtr; }
- T* operator->() const { return m_pObservedPtr; }
+ explicit operator bool() const { return !!m_pObservable; }
+ T* Get() const { return m_pObservable; }
+ T& operator*() const { return *m_pObservable; }
+ T* operator->() const { return m_pObservable; }
private:
- T* m_pObservedPtr;
+ T* m_pObservable;
};
CFX_Observable() {}