//////////////////////////////////////////////////////////////////////////////// // Copyright 2017 Google LLC. // // This software is licensed under the terms defined in the Widevine Master // License Agreement. For a copy of this agreement, please contact // widevine-licensing@google.com. //////////////////////////////////////////////////////////////////////////////// #ifndef UTIL_GTL_MAP_UTIL_H_ #define UTIL_GTL_MAP_UTIL_H_ namespace widevine { namespace gtl { template const typename Collection::value_type::second_type& FindWithDefault( const Collection& collection, const typename Collection::value_type::first_type& key, const typename Collection::value_type::second_type& value) { typename Collection::const_iterator it = collection.find(key); if (it == collection.end()) { return value; } return it->second; } template typename Collection::value_type::second_type* FindOrNull( const Collection& collection, const typename Collection::value_type::first_type& key) { typename Collection::iterator it = collection.find(key); if (it == collection.end()) { return nullptr; } return &it->second; } template typename Collection::value_type::second_type* FindOrNull( Collection& collection, // NOLINT const typename Collection::value_type::first_type& key) { typename Collection::iterator it = collection.find(key); if (it == collection.end()) { return nullptr; } return &it->second; } template bool ContainsKey(const C& collection, const K& key) { typename C::const_iterator it = collection.find(key); return it != collection.end(); } } // namespace gtl } // namespace widevine #endif // UTIL_GTL_MAP_UTIL_H_