Export media_cas_proxy_sdk
This commit is contained in:
58
util/gtl/map_util.h
Normal file
58
util/gtl/map_util.h
Normal file
@@ -0,0 +1,58 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 <class Collection>
|
||||
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 <class Collection>
|
||||
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 <class Collection>
|
||||
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 <class C, class K>
|
||||
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_
|
||||
Reference in New Issue
Block a user