Minor Python style clean-up
[chromium-blink-merge.git] / tools / android / forwarder2 / util.h
blob9947628ca77696fad18b36a446f2deda6a2d6a6e
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef TOOLS_ANDROID_FORWARDER2_UTIL_H_
6 #define TOOLS_ANDROID_FORWARDER2_UTIL_H_
8 #include "base/logging.h"
10 namespace forwarder2 {
12 // Safely deletes a ref-counted value in a provided map by unlinking the object
13 // from the map before deleting it in case its destructor would access the map.
14 // Deletion will only happen by definition if the object's refcount is set to 1
15 // before this function gets called. Returns whether the element could be found
16 // in the map.
17 template <typename Map, typename K>
18 bool DeleteRefCountedValueInMap(const K& key, Map* map) {
19 const typename Map::iterator it = map->find(key);
20 if (it == map->end())
21 return false;
22 DeleteRefCountedValueInMapFromIterator(it, map);
23 return true;
26 // See DeleteRefCountedValuetInMap() above.
27 template <typename Map, typename Iterator>
28 void DeleteRefCountedValueInMapFromIterator(Iterator it, Map* map) {
29 DCHECK(it != map->end());
30 const typename Map::value_type::second_type shared_ptr_copy = it->second;
31 map->erase(it);
34 } // namespace forwarder2
36 #endif // TOOLS_ANDROID_FORWARDER2_UTIL_H_