diff --git a/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc index 69c1c00807..254a7d0ae6 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc @@ -26,7 +26,6 @@ #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" #include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h" #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" -#include "webrtc/system_wrappers/include/stl_util.h" #include "webrtc/test/field_trial.h" #include "webrtc/test/gmock.h" #include "webrtc/test/gtest.h" diff --git a/webrtc/system_wrappers/BUILD.gn b/webrtc/system_wrappers/BUILD.gn index 37366bf494..7f56fd8dcb 100644 --- a/webrtc/system_wrappers/BUILD.gn +++ b/webrtc/system_wrappers/BUILD.gn @@ -32,7 +32,6 @@ rtc_static_library("system_wrappers") { "include/rw_lock_wrapper.h", "include/sleep.h", "include/static_instance.h", - "include/stl_util.h", "include/stringize_macros.h", "include/timestamp_extrapolator.h", "include/trace.h", @@ -181,7 +180,6 @@ if (rtc_include_tests) { "source/metrics_unittest.cc", "source/ntp_time_unittest.cc", "source/rtp_to_ntp_unittest.cc", - "source/stl_util_unittest.cc", "source/stringize_macros_unittest.cc", ] configs += [ "//build/config/compiler:no_size_t_to_int_warning" ] diff --git a/webrtc/system_wrappers/include/stl_util.h b/webrtc/system_wrappers/include/stl_util.h deleted file mode 100644 index b7a702113f..0000000000 --- a/webrtc/system_wrappers/include/stl_util.h +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -// Borrowed from Chromium's src/base/stl_util.h. - -#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_STL_UTIL_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_STL_UTIL_H_ - -#include -#include -#include -#include -#include -#include - -namespace webrtc { - -// Clears internal memory of an STL object. -// STL clear()/reserve(0) does not always free internal memory allocated -// This function uses swap/destructor to ensure the internal memory is freed. -template -void STLClearObject(T* obj) { - T tmp; - tmp.swap(*obj); - // Sometimes "T tmp" allocates objects with memory (arena implementation?). - // Hence using additional reserve(0) even if it doesn't always work. - obj->reserve(0); -} - -// For a range within a container of pointers, calls delete (non-array version) -// on these pointers. -// NOTE: for these three functions, we could just implement a DeleteObject -// functor and then call for_each() on the range and functor, but this -// requires us to pull in all of algorithm.h, which seems expensive. -// For hash_[multi]set, it is important that this deletes behind the iterator -// because the hash_set may call the hash function on the iterator when it is -// advanced, which could result in the hash function trying to deference a -// stale pointer. -template -void STLDeleteContainerPointers(ForwardIterator begin, ForwardIterator end) { - while (begin != end) { - ForwardIterator temp = begin; - ++begin; - delete *temp; - } -} - -// For a range within a container of pairs, calls delete (non-array version) on -// BOTH items in the pairs. -// NOTE: Like STLDeleteContainerPointers, it is important that this deletes -// behind the iterator because if both the key and value are deleted, the -// container may call the hash function on the iterator when it is advanced, -// which could result in the hash function trying to dereference a stale -// pointer. -template -void STLDeleteContainerPairPointers(ForwardIterator begin, - ForwardIterator end) { - while (begin != end) { - ForwardIterator temp = begin; - ++begin; - delete temp->first; - delete temp->second; - } -} - -// For a range within a container of pairs, calls delete (non-array version) on -// the FIRST item in the pairs. -// NOTE: Like STLDeleteContainerPointers, deleting behind the iterator. -template -void STLDeleteContainerPairFirstPointers(ForwardIterator begin, - ForwardIterator end) { - while (begin != end) { - ForwardIterator temp = begin; - ++begin; - delete temp->first; - } -} - -// For a range within a container of pairs, calls delete. -// NOTE: Like STLDeleteContainerPointers, deleting behind the iterator. -// Deleting the value does not always invalidate the iterator, but it may -// do so if the key is a pointer into the value object. -template -void STLDeleteContainerPairSecondPointers(ForwardIterator begin, - ForwardIterator end) { - while (begin != end) { - ForwardIterator temp = begin; - ++begin; - delete temp->second; - } -} - -// To treat a possibly-empty vector as an array, use these functions. -// If you know the array will never be empty, you can use &*v.begin() -// directly, but that is undefined behaviour if |v| is empty. -template -inline T* vector_as_array(std::vector* v) { - return v->empty() ? NULL : &*v->begin(); -} - -template -inline const T* vector_as_array(const std::vector* v) { - return v->empty() ? NULL : &*v->begin(); -} - -// Return a mutable char* pointing to a string's internal buffer, -// which may not be null-terminated. Writing through this pointer will -// modify the string. -// -// string_as_array(&str)[i] is valid for 0 <= i < str.size() until the -// next call to a string method that invalidates iterators. -// -// As of 2006-04, there is no standard-blessed way of getting a -// mutable reference to a string's internal buffer. However, issue 530 -// (http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-active.html#530) -// proposes this as the method. According to Matt Austern, this should -// already work on all current implementations. -inline char* string_as_array(std::string* str) { - // DO NOT USE const_cast(str->data()) - return str->empty() ? NULL : &*str->begin(); -} - -// The following functions are useful for cleaning up STL containers whose -// elements point to allocated memory. - -// STLDeleteElements() deletes all the elements in an STL container and clears -// the container. This function is suitable for use with a vector, set, -// hash_set, or any other STL container which defines sensible begin(), end(), -// and clear() methods. -// -// If container is NULL, this function is a no-op. -// -// As an alternative to calling STLDeleteElements() directly, consider -// STLElementDeleter (defined below), which ensures that your container's -// elements are deleted when the STLElementDeleter goes out of scope. -template -void STLDeleteElements(T* container) { - if (!container) - return; - STLDeleteContainerPointers(container->begin(), container->end()); - container->clear(); -} - -// Given an STL container consisting of (key, value) pairs, STLDeleteValues -// deletes all the "value" components and clears the container. Does nothing -// in the case it's given a NULL pointer. -template -void STLDeleteValues(T* container) { - if (!container) - return; - for (typename T::iterator i(container->begin()); i != container->end(); ++i) - delete i->second; - container->clear(); -} - - -// The following classes provide a convenient way to delete all elements or -// values from STL containers when they goes out of scope. This greatly -// simplifies code that creates temporary objects and has multiple return -// statements. Example: -// -// vector tmp_proto; -// STLElementDeleter > d(&tmp_proto); -// if (...) return false; -// ... -// return success; - -// Given a pointer to an STL container this class will delete all the element -// pointers when it goes out of scope. -template -class STLElementDeleter { - public: - STLElementDeleter(T* container) : container_(container) {} - ~STLElementDeleter() { STLDeleteElements(container_); } - - private: - T* container_; -}; - -// Given a pointer to an STL container this class will delete all the value -// pointers when it goes out of scope. -template -class STLValueDeleter { - public: - STLValueDeleter(T* container) : container_(container) {} - ~STLValueDeleter() { STLDeleteValues(container_); } - - private: - T* container_; -}; - -// Test to see if a set, map, hash_set or hash_map contains a particular key. -// Returns true if the key is in the collection. -template -bool ContainsKey(const Collection& collection, const Key& key) { - return collection.find(key) != collection.end(); -} - -// Returns true if the container is sorted. -template -bool STLIsSorted(const Container& cont) { - // Note: Use reverse iterator on container to ensure we only require - // value_type to implement operator<. - return std::adjacent_find(cont.rbegin(), cont.rend(), - std::less()) - == cont.rend(); -} - -// Returns a new ResultType containing the difference of two sorted containers. -template -ResultType STLSetDifference(const Arg1& a1, const Arg2& a2) { - assert(STLIsSorted(a1)); - assert(STLIsSorted(a2)); - ResultType difference; - std::set_difference(a1.begin(), a1.end(), - a2.begin(), a2.end(), - std::inserter(difference, difference.end())); - return difference; -} - -// Returns a new ResultType containing the union of two sorted containers. -template -ResultType STLSetUnion(const Arg1& a1, const Arg2& a2) { - assert(STLIsSorted(a1)); - assert(STLIsSorted(a2)); - ResultType result; - std::set_union(a1.begin(), a1.end(), - a2.begin(), a2.end(), - std::inserter(result, result.end())); - return result; -} - -// Returns a new ResultType containing the intersection of two sorted -// containers. -template -ResultType STLSetIntersection(const Arg1& a1, const Arg2& a2) { - assert(STLIsSorted(a1)); - assert(STLIsSorted(a2)); - ResultType result; - std::set_intersection(a1.begin(), a1.end(), - a2.begin(), a2.end(), - std::inserter(result, result.end())); - return result; -} - -// Returns true if the sorted container |a1| contains all elements of the sorted -// container |a2|. -template -bool STLIncludes(const Arg1& a1, const Arg2& a2) { - assert(STLIsSorted(a1)); - assert(STLIsSorted(a2)); - return std::includes(a1.begin(), a1.end(), - a2.begin(), a2.end()); -} - -} // namespace webrtc - -#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_STL_UTIL_H_ diff --git a/webrtc/system_wrappers/source/stl_util_unittest.cc b/webrtc/system_wrappers/source/stl_util_unittest.cc deleted file mode 100644 index d75e44a052..0000000000 --- a/webrtc/system_wrappers/source/stl_util_unittest.cc +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -// Borrowed from Chromium's src/base/stl_util_unittest.cc -#include "webrtc/system_wrappers/include/stl_util.h" - -#include - -#include "webrtc/test/gtest.h" - -namespace { - -// Used as test case to ensure the various base::STLXxx functions don't require -// more than operators "<" and "==" on values stored in containers. -class ComparableValue { - public: - explicit ComparableValue(int value) : value_(value) {} - - bool operator==(const ComparableValue& rhs) const { - return value_ == rhs.value_; - } - - bool operator<(const ComparableValue& rhs) const { - return value_ < rhs.value_; - } - - private: - int value_; -}; - -} // namespace - -namespace webrtc { -namespace { - -TEST(STLUtilTest, STLIsSorted) { - { - std::set set; - set.insert(24); - set.insert(1); - set.insert(12); - EXPECT_TRUE(STLIsSorted(set)); - } - - { - std::set set; - set.insert(ComparableValue(24)); - set.insert(ComparableValue(1)); - set.insert(ComparableValue(12)); - EXPECT_TRUE(STLIsSorted(set)); - } - - { - std::vector vector; - vector.push_back(1); - vector.push_back(1); - vector.push_back(4); - vector.push_back(64); - vector.push_back(12432); - EXPECT_TRUE(STLIsSorted(vector)); - vector.back() = 1; - EXPECT_FALSE(STLIsSorted(vector)); - } -} - -TEST(STLUtilTest, STLSetDifference) { - std::set a1; - a1.insert(1); - a1.insert(2); - a1.insert(3); - a1.insert(4); - - std::set a2; - a2.insert(3); - a2.insert(4); - a2.insert(5); - a2.insert(6); - a2.insert(7); - - { - std::set difference; - difference.insert(1); - difference.insert(2); - EXPECT_EQ(difference, STLSetDifference >(a1, a2)); - } - - { - std::set difference; - difference.insert(5); - difference.insert(6); - difference.insert(7); - EXPECT_EQ(difference, STLSetDifference >(a2, a1)); - } - - { - std::vector difference; - difference.push_back(1); - difference.push_back(2); - EXPECT_EQ(difference, STLSetDifference >(a1, a2)); - } - - { - std::vector difference; - difference.push_back(5); - difference.push_back(6); - difference.push_back(7); - EXPECT_EQ(difference, STLSetDifference >(a2, a1)); - } -} - -TEST(STLUtilTest, STLSetUnion) { - std::set a1; - a1.insert(1); - a1.insert(2); - a1.insert(3); - a1.insert(4); - - std::set a2; - a2.insert(3); - a2.insert(4); - a2.insert(5); - a2.insert(6); - a2.insert(7); - - { - std::set result; - result.insert(1); - result.insert(2); - result.insert(3); - result.insert(4); - result.insert(5); - result.insert(6); - result.insert(7); - EXPECT_EQ(result, STLSetUnion >(a1, a2)); - } - - { - std::set result; - result.insert(1); - result.insert(2); - result.insert(3); - result.insert(4); - result.insert(5); - result.insert(6); - result.insert(7); - EXPECT_EQ(result, STLSetUnion >(a2, a1)); - } - - { - std::vector result; - result.push_back(1); - result.push_back(2); - result.push_back(3); - result.push_back(4); - result.push_back(5); - result.push_back(6); - result.push_back(7); - EXPECT_EQ(result, STLSetUnion >(a1, a2)); - } - - { - std::vector result; - result.push_back(1); - result.push_back(2); - result.push_back(3); - result.push_back(4); - result.push_back(5); - result.push_back(6); - result.push_back(7); - EXPECT_EQ(result, STLSetUnion >(a2, a1)); - } -} - -TEST(STLUtilTest, STLSetIntersection) { - std::set a1; - a1.insert(1); - a1.insert(2); - a1.insert(3); - a1.insert(4); - - std::set a2; - a2.insert(3); - a2.insert(4); - a2.insert(5); - a2.insert(6); - a2.insert(7); - - { - std::set result; - result.insert(3); - result.insert(4); - EXPECT_EQ(result, STLSetIntersection >(a1, a2)); - } - - { - std::set result; - result.insert(3); - result.insert(4); - EXPECT_EQ(result, STLSetIntersection >(a2, a1)); - } - - { - std::vector result; - result.push_back(3); - result.push_back(4); - EXPECT_EQ(result, STLSetIntersection >(a1, a2)); - } - - { - std::vector result; - result.push_back(3); - result.push_back(4); - EXPECT_EQ(result, STLSetIntersection >(a2, a1)); - } -} - -TEST(STLUtilTest, STLIncludes) { - std::set a1; - a1.insert(1); - a1.insert(2); - a1.insert(3); - a1.insert(4); - - std::set a2; - a2.insert(3); - a2.insert(4); - - std::set a3; - a3.insert(3); - a3.insert(4); - a3.insert(5); - - EXPECT_TRUE(STLIncludes >(a1, a2)); - EXPECT_FALSE(STLIncludes >(a1, a3)); - EXPECT_FALSE(STLIncludes >(a2, a1)); - EXPECT_FALSE(STLIncludes >(a2, a3)); - EXPECT_FALSE(STLIncludes >(a3, a1)); - EXPECT_TRUE(STLIncludes >(a3, a2)); -} - -} // namespace -} // namespace webrtc -