1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*++
Copyright (c) 2011 Microsoft Corporation
Module Name:
ref_util.h
Abstract:
Some goodies for managing reference counters.
Author:
Leonardo (leonardo) 2011-06-07
Notes:
--*/
#pragma once
/**
\brief Decrement the reference counter of the keys and values stored in the map,
then reset the map.
*/
template<typename Mng1, typename Mng2, typename Map>
void dec_ref_map_key_values(Mng1 & m1, Mng2 & m2, Map & map) {
typename Map::iterator it = map.begin();
typename Map::iterator end = map.end();
for (; it != end; ++it) {
m1.dec_ref(it->m_key);
m2.dec_ref(it->m_value);
}
map.reset();
}
/**
\brief Decrement the reference counter of the keys and values stored in the map,
then reset the map.
*/
template<typename Mng, typename Map>
void dec_ref_map_key_values(Mng & m, Map & map) {
dec_ref_map_key_values(m, m, map);
}
/**
\brief Decrement the reference counter of the keys stored in the map,
then reset the map.
*/
template<typename Mng, typename Map>
void dec_ref_map_keys(Mng & m, Map & map) {
typename Map::iterator it = map.begin();
typename Map::iterator end = map.end();
for (; it != end; ++it) {
m.dec_ref(it->m_key);
}
map.reset();
}
/**
\brief Decrement the reference counter of the values stored in the map,
then reset the map.
*/
template<typename Mng, typename Map>
void dec_ref_map_values(Mng & m, Map & map) {
typename Map::iterator it = map.begin();
typename Map::iterator end = map.end();
for (; it != end; ++it) {
m.dec_ref(it->m_value);
}
map.reset();
}
/**
\brief Decrement the reference counter of the values stored in the map,
then reset the map.
*/
template<typename Mng, typename C>
void dec_ref_collection_values(Mng & m, C & c) {
typename C::iterator it = c.begin();
typename C::iterator end = c.end();
for (; it != end; ++it) {
m.dec_ref(*it);
}
c.reset();
}