summaryrefslogtreecommitdiff
path: root/core/fxcrt/cfx_observable.h
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-09-21 15:25:32 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-09-21 19:41:49 +0000
commit65ecca4bc9c8e043b355c459486870ac1518095d (patch)
tree2cca0a32a7873f2743e9d927010533019e4c85b9 /core/fxcrt/cfx_observable.h
parent3418f710f923785a0fd05f7c556d09bc9a8d3447 (diff)
downloadpdfium-65ecca4bc9c8e043b355c459486870ac1518095d.tar.xz
Move CFX_Observable to Observable
This CL renames CFX_Observable to Observable and moves into the fxcrt namespace. The test suite names were updated to ObservedPtr from fxcrt. Bug: pdfium:898 Change-Id: Ia507482bc0a1d6d8bbf12c0c55c4a88f6c8910e2 Reviewed-on: https://pdfium-review.googlesource.com/14615 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcrt/cfx_observable.h')
-rw-r--r--core/fxcrt/cfx_observable.h81
1 files changed, 0 insertions, 81 deletions
diff --git a/core/fxcrt/cfx_observable.h b/core/fxcrt/cfx_observable.h
deleted file mode 100644
index 8dc0907cae..0000000000
--- a/core/fxcrt/cfx_observable.h
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CORE_FXCRT_CFX_OBSERVABLE_H_
-#define CORE_FXCRT_CFX_OBSERVABLE_H_
-
-#include <set>
-
-#include "core/fxcrt/fx_system.h"
-#include "third_party/base/stl_util.h"
-
-template <class T>
-class CFX_Observable {
- public:
- class ObservedPtr {
- public:
- ObservedPtr() : m_pObservable(nullptr) {}
- explicit ObservedPtr(T* pObservable) : m_pObservable(pObservable) {
- if (m_pObservable)
- m_pObservable->AddObservedPtr(this);
- }
- ObservedPtr(const ObservedPtr& that) : ObservedPtr(that.Get()) {}
- ~ObservedPtr() {
- if (m_pObservable)
- m_pObservable->RemoveObservedPtr(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_pObservable);
- m_pObservable = nullptr;
- }
- ObservedPtr& operator=(const ObservedPtr& that) {
- Reset(that.Get());
- return *this;
- }
- bool operator==(const ObservedPtr& that) const {
- return m_pObservable == that.m_pObservable;
- }
- bool operator!=(const ObservedPtr& that) const { return !(*this == that); }
- 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_pObservable;
- };
-
- CFX_Observable() {}
- CFX_Observable(const CFX_Observable& that) = delete;
- ~CFX_Observable() { NotifyObservedPtrs(); }
- void AddObservedPtr(ObservedPtr* pObservedPtr) {
- ASSERT(!pdfium::ContainsKey(m_ObservedPtrs, pObservedPtr));
- m_ObservedPtrs.insert(pObservedPtr);
- }
- void RemoveObservedPtr(ObservedPtr* pObservedPtr) {
- ASSERT(pdfium::ContainsKey(m_ObservedPtrs, pObservedPtr));
- m_ObservedPtrs.erase(pObservedPtr);
- }
- void NotifyObservedPtrs() {
- for (auto* pObservedPtr : m_ObservedPtrs)
- pObservedPtr->OnDestroy();
- m_ObservedPtrs.clear();
- }
- CFX_Observable& operator=(const CFX_Observable& that) = delete;
-
- protected:
- size_t ActiveObservedPtrsForTesting() const { return m_ObservedPtrs.size(); }
-
- private:
- std::set<ObservedPtr*> m_ObservedPtrs;
-};
-
-#endif // CORE_FXCRT_CFX_OBSERVABLE_H_