| 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> |
| 9 |
| 8 #include "third_party/base/numerics/safe_conversions.h" | 10 #include "third_party/base/numerics/safe_conversions.h" |
| 9 | 11 |
| 10 namespace pdfium { | 12 namespace pdfium { |
| 11 | 13 |
| 12 // Test to see if a set, map, hash_set or hash_map contains a particular key. | 14 // Test to see if a set, map, hash_set or hash_map contains a particular key. |
| 13 // Returns true if the key is in the collection. | 15 // Returns true if the key is in the collection. |
| 14 template <typename Collection, typename Key> | 16 template <typename Collection, typename Key> |
| 15 bool ContainsKey(const Collection& collection, const Key& key) { | 17 bool ContainsKey(const Collection& collection, const Key& key) { |
| 16 return collection.find(key) != collection.end(); | 18 return collection.find(key) != collection.end(); |
| 17 } | 19 } |
| 18 | 20 |
| 19 // Test to see if a collection like a vector contains a particular value. | 21 // Test to see if a collection like a vector contains a particular value. |
| 20 // Returns true if the value is in the collection. | 22 // Returns true if the value is in the collection. |
| 21 template <typename Collection, typename Value> | 23 template <typename Collection, typename Value> |
| 22 bool ContainsValue(const Collection& collection, const Value& value) { | 24 bool ContainsValue(const Collection& collection, const Value& value) { |
| 23 return std::find(collection.begin(), collection.end(), value) != | 25 return std::find(collection.begin(), collection.end(), value) != |
| 24 collection.end(); | 26 collection.end(); |
| 25 } | 27 } |
| 26 | 28 |
| 27 // Convenience routine for "int-fected" code, so that the stl collection | 29 // Convenience routine for "int-fected" code, so that the stl collection |
| 28 // size_t size() method return values will be checked. | 30 // size_t size() method return values will be checked. |
| 29 template <typename ResultType, typename Collection> | 31 template <typename ResultType, typename Collection> |
| 30 ResultType CollectionSize(const Collection& collection) { | 32 ResultType CollectionSize(const Collection& collection) { |
| 31 return pdfium::base::checked_cast<ResultType, size_t>(collection.size()); | 33 return pdfium::base::checked_cast<ResultType, size_t>(collection.size()); |
| 32 } | 34 } |
| 33 | 35 |
| 34 } // namespace pdfium | 36 } // namespace pdfium |
| 35 | 37 |
| 36 #endif // PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ | 38 #endif // PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ |
| OLD | NEW |