| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ | 5 #ifndef PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ |
| 6 #define PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ | 6 #define PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 class FakeUniquePtr : public std::unique_ptr<T> { | 34 class FakeUniquePtr : public std::unique_ptr<T> { |
| 35 public: | 35 public: |
| 36 using std::unique_ptr<T>::unique_ptr; | 36 using std::unique_ptr<T>::unique_ptr; |
| 37 ~FakeUniquePtr() { std::unique_ptr<T>::release(); } | 37 ~FakeUniquePtr() { std::unique_ptr<T>::release(); } |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 // Convenience routine for "int-fected" code, so that the stl collection | 40 // Convenience routine for "int-fected" code, so that the stl collection |
| 41 // size_t size() method return values will be checked. | 41 // size_t size() method return values will be checked. |
| 42 template <typename ResultType, typename Collection> | 42 template <typename ResultType, typename Collection> |
| 43 ResultType CollectionSize(const Collection& collection) { | 43 ResultType CollectionSize(const Collection& collection) { |
| 44 return pdfium::base::checked_cast<ResultType, size_t>(collection.size()); | 44 return pdfium::base::checked_cast<ResultType>(collection.size()); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Track the addition of an object to a set, removing it automatically when | 47 // Track the addition of an object to a set, removing it automatically when |
| 48 // the ScopedSetInsertion goes out of scope. | 48 // the ScopedSetInsertion goes out of scope. |
| 49 template <typename T> | 49 template <typename T> |
| 50 class ScopedSetInsertion { | 50 class ScopedSetInsertion { |
| 51 public: | 51 public: |
| 52 ScopedSetInsertion(std::set<T>* org_set, T elem) | 52 ScopedSetInsertion(std::set<T>* org_set, T elem) |
| 53 : m_Set(org_set), m_Entry(elem) { | 53 : m_Set(org_set), m_Entry(elem) { |
| 54 m_Set->insert(m_Entry); | 54 m_Set->insert(m_Entry); |
| 55 } | 55 } |
| 56 ~ScopedSetInsertion() { m_Set->erase(m_Entry); } | 56 ~ScopedSetInsertion() { m_Set->erase(m_Entry); } |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 std::set<T>* const m_Set; | 59 std::set<T>* const m_Set; |
| 60 const T m_Entry; | 60 const T m_Entry; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 } // namespace pdfium | 63 } // namespace pdfium |
| 64 | 64 |
| 65 #endif // PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ | 65 #endif // PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ |
| OLD | NEW |