OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... | |
24 template <typename Container> | 24 template <typename Container> |
25 bool MultimapAssociationExists(const Container& multimap, | 25 bool MultimapAssociationExists(const Container& multimap, |
26 const typename Container::key_type& key, | 26 const typename Container::key_type& key, |
27 const typename Container::mapped_type& val) { | 27 const typename Container::mapped_type& val) { |
28 auto it_range = multimap.equal_range(key); | 28 auto it_range = multimap.equal_range(key); |
29 using Reference = typename Container::const_reference; | 29 using Reference = typename Container::const_reference; |
30 return std::any_of(it_range.first, it_range.second, | 30 return std::any_of(it_range.first, it_range.second, |
31 [val](Reference elem) { return elem.second == val; }); | 31 [val](Reference elem) { return elem.second == val; }); |
32 } | 32 } |
33 | 33 |
34 // TODO(eladalon): Remove this in the next CL. | |
34 template <typename Container, typename Value> | 35 template <typename Container, typename Value> |
35 size_t RemoveFromMultimapByValue(Container* multimap, const Value& value) { | 36 size_t RemoveFromMultimapByValue(Container* multimap, const Value& value) { |
36 size_t count = 0; | 37 size_t count = 0; |
37 for (auto it = multimap->begin(); it != multimap->end();) { | 38 for (auto it = multimap->begin(); it != multimap->end();) { |
38 if (it->second == value) { | 39 if (it->second == value) { |
39 it = multimap->erase(it); | 40 it = multimap->erase(it); |
40 ++count; | 41 ++count; |
41 } else { | 42 } else { |
42 ++it; | 43 ++it; |
43 } | 44 } |
44 } | 45 } |
45 return count; | 46 return count; |
46 } | 47 } |
47 | 48 |
49 template <typename Map, typename Value> | |
50 size_t RemoveFromMapByValue(Map* map, const Value& value) { | |
51 size_t count = 0; | |
52 for (auto it = map->begin(); it != map->end();) { | |
53 if (it->second == value) { | |
54 it = map->erase(it); | |
55 ++count; | |
56 } else { | |
57 ++it; | |
58 } | |
59 } | |
60 return count; | |
61 } | |
62 | |
48 template <typename Container, typename Key> | 63 template <typename Container, typename Key> |
49 bool ContainerHasKey(const Container& c, const Key& k) { | 64 bool ContainerHasKey(const Container& c, const Key& k) { |
50 return std::find(c.cbegin(), c.cend(), k) != c.cend(); | 65 return std::find(c.cbegin(), c.cend(), k) != c.cend(); |
51 } | 66 } |
52 | 67 |
68 // TODO(eladalon): Remove this in the next CL. | |
danilchap
2017/06/30 16:45:31
Why next CL? do you mean 'Remove when unused'?
or
eladalon
2017/07/03 08:23:35
The next CL will do something similar for RtcpDemu
danilchap
2017/07/26 11:25:46
Acknowledged.
| |
53 template <typename Container> | 69 template <typename Container> |
54 bool MultimapHasValue(const Container& c, | 70 bool MultimapHasValue(const Container& c, |
55 const typename Container::mapped_type& v) { | 71 const typename Container::mapped_type& v) { |
56 auto predicate = [v](const typename Container::value_type& it) { | 72 auto predicate = [v](const typename Container::value_type& it) { |
57 return it.second == v; | 73 return it.second == v; |
58 }; | 74 }; |
59 return std::any_of(c.cbegin(), c.cend(), predicate); | 75 return std::any_of(c.cbegin(), c.cend(), predicate); |
60 } | 76 } |
61 | 77 |
78 template <typename Map> | |
79 bool MapHasValue(const Map& map, const typename Map::mapped_type& value) { | |
80 auto predicate = [value](const typename Map::value_type& it) { | |
81 return it.second == value; | |
82 }; | |
83 return std::any_of(map.cbegin(), map.cend(), predicate); | |
84 } | |
85 | |
62 rtc::Optional<uint32_t> ParseRtcpPacketSenderSsrc( | 86 rtc::Optional<uint32_t> ParseRtcpPacketSenderSsrc( |
63 rtc::ArrayView<const uint8_t> packet); | 87 rtc::ArrayView<const uint8_t> packet); |
64 | 88 |
65 } // namespace webrtc | 89 } // namespace webrtc |
66 | 90 |
67 #endif // WEBRTC_CALL_RTP_RTCP_DEMUXER_HELPER_H_ | 91 #endif // WEBRTC_CALL_RTP_RTCP_DEMUXER_HELPER_H_ |
OLD | NEW |