From 99406198ac4921a53425edc73cac67e7b4760895 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 9 Mar 2016 17:37:12 -0800 Subject: Move ScopedSetInsertion to third_party/base/stl_util.h Also move ScopedFileStream, since it isn't specific to the parser, and belongs with the fxcrt object it manipulates. R=ochang@chromium.org Review URL: https://codereview.chromium.org/1780063003 . --- third_party/base/stl_util.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'third_party/base') diff --git a/third_party/base/stl_util.h b/third_party/base/stl_util.h index 353d3a68c3..2d1846724c 100644 --- a/third_party/base/stl_util.h +++ b/third_party/base/stl_util.h @@ -6,6 +6,7 @@ #define PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ #include +#include #include "third_party/base/numerics/safe_conversions.h" @@ -33,6 +34,22 @@ ResultType CollectionSize(const Collection& collection) { return pdfium::base::checked_cast(collection.size()); } +// Track the addition of an object to a set, removing it automatically when +// the ScopedSetInsertion goes out of scope. +template +class ScopedSetInsertion { + public: + ScopedSetInsertion(std::set* org_set, T elem) + : m_Set(org_set), m_Entry(elem) { + m_Set->insert(m_Entry); + } + ~ScopedSetInsertion() { m_Set->erase(m_Entry); } + + private: + std::set* const m_Set; + const T m_Entry; +}; + } // namespace pdfium #endif // PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ -- cgit v1.2.3