summaryrefslogtreecommitdiff
path: root/third_party/base
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2016-03-09 17:37:12 -0800
committerTom Sepez <tsepez@chromium.org>2016-03-09 17:37:12 -0800
commit99406198ac4921a53425edc73cac67e7b4760895 (patch)
treed2f2411dad87d84001202e9a04bb2ed60b725683 /third_party/base
parent520f247443253356b0ce236066fce95e7fad7680 (diff)
downloadpdfium-99406198ac4921a53425edc73cac67e7b4760895.tar.xz
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 .
Diffstat (limited to 'third_party/base')
-rw-r--r--third_party/base/stl_util.h17
1 files changed, 17 insertions, 0 deletions
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 <algorithm>
+#include <set>
#include "third_party/base/numerics/safe_conversions.h"
@@ -33,6 +34,22 @@ ResultType CollectionSize(const Collection& collection) {
return pdfium::base::checked_cast<ResultType, size_t>(collection.size());
}
+// Track the addition of an object to a set, removing it automatically when
+// the ScopedSetInsertion goes out of scope.
+template <typename T>
+class ScopedSetInsertion {
+ public:
+ ScopedSetInsertion(std::set<T>* 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<T>* const m_Set;
+ const T m_Entry;
+};
+
} // namespace pdfium
#endif // PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_