Delete class ScopedPtrCollection. Replaced with vector of unique_ptr.
BUG=None Review-Url: https://codereview.webrtc.org/2808463002 Cr-Commit-Position: refs/heads/master@{#17605}
This commit is contained in:
parent
bd1a6814ea
commit
188596f20f
@ -508,7 +508,6 @@ rtc_static_library("rtc_base") {
|
||||
"optionsfile.cc",
|
||||
"optionsfile.h",
|
||||
"rollingaccumulator.h",
|
||||
"scopedptrcollection.h",
|
||||
"sslroots.h",
|
||||
"testbase64.h",
|
||||
"testclient.cc",
|
||||
@ -869,7 +868,6 @@ if (rtc_include_tests) {
|
||||
"rollingaccumulator_unittest.cc",
|
||||
"rtccertificate_unittest.cc",
|
||||
"rtccertificategenerator_unittest.cc",
|
||||
"scopedptrcollection_unittest.cc",
|
||||
"sha1digest_unittest.cc",
|
||||
"sharedexclusivelock_unittest.cc",
|
||||
"signalthread_unittest.cc",
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
#include "webrtc/base/event.h"
|
||||
#include "webrtc/base/gunit.h"
|
||||
#include "webrtc/base/platform_thread.h"
|
||||
#include "webrtc/base/scopedptrcollection.h"
|
||||
#include "webrtc/base/thread.h"
|
||||
|
||||
namespace rtc {
|
||||
@ -199,13 +198,13 @@ struct CompareAndSwapOp {
|
||||
static int AtomicOp(int* i) { return AtomicOps::CompareAndSwap(i, 0, 1); }
|
||||
};
|
||||
|
||||
void StartThreads(ScopedPtrCollection<Thread>* threads,
|
||||
void StartThreads(std::vector<std::unique_ptr<Thread>>* threads,
|
||||
MessageHandler* handler) {
|
||||
for (int i = 0; i < kNumThreads; ++i) {
|
||||
Thread* thread = new Thread();
|
||||
std::unique_ptr<Thread> thread(new Thread());
|
||||
thread->Start();
|
||||
thread->Post(RTC_FROM_HERE, handler);
|
||||
threads->PushBack(thread);
|
||||
threads->push_back(std::move(thread));
|
||||
}
|
||||
}
|
||||
|
||||
@ -248,7 +247,7 @@ TEST(AtomicOpsTest, SimplePtr) {
|
||||
TEST(AtomicOpsTest, Increment) {
|
||||
// Create and start lots of threads.
|
||||
AtomicOpRunner<IncrementOp, UniqueValueVerifier> runner(0);
|
||||
ScopedPtrCollection<Thread> threads;
|
||||
std::vector<std::unique_ptr<Thread>> threads;
|
||||
StartThreads(&threads, &runner);
|
||||
runner.SetExpectedThreadCount(kNumThreads);
|
||||
|
||||
@ -261,7 +260,7 @@ TEST(AtomicOpsTest, Decrement) {
|
||||
// Create and start lots of threads.
|
||||
AtomicOpRunner<DecrementOp, UniqueValueVerifier> runner(
|
||||
kOperationsToRun * kNumThreads);
|
||||
ScopedPtrCollection<Thread> threads;
|
||||
std::vector<std::unique_ptr<Thread>> threads;
|
||||
StartThreads(&threads, &runner);
|
||||
runner.SetExpectedThreadCount(kNumThreads);
|
||||
|
||||
@ -273,7 +272,7 @@ TEST(AtomicOpsTest, Decrement) {
|
||||
TEST(AtomicOpsTest, CompareAndSwap) {
|
||||
// Create and start lots of threads.
|
||||
AtomicOpRunner<CompareAndSwapOp, CompareAndSwapVerifier> runner(0);
|
||||
ScopedPtrCollection<Thread> threads;
|
||||
std::vector<std::unique_ptr<Thread>> threads;
|
||||
StartThreads(&threads, &runner);
|
||||
runner.SetExpectedThreadCount(kNumThreads);
|
||||
|
||||
@ -285,7 +284,7 @@ TEST(AtomicOpsTest, CompareAndSwap) {
|
||||
TEST(GlobalLockTest, Basic) {
|
||||
// Create and start lots of threads.
|
||||
LockRunner<GlobalLock> runner;
|
||||
ScopedPtrCollection<Thread> threads;
|
||||
std::vector<std::unique_ptr<Thread>> threads;
|
||||
StartThreads(&threads, &runner);
|
||||
runner.SetExpectedThreadCount(kNumThreads);
|
||||
|
||||
@ -297,7 +296,7 @@ TEST(GlobalLockTest, Basic) {
|
||||
TEST(CriticalSectionTest, Basic) {
|
||||
// Create and start lots of threads.
|
||||
LockRunner<CriticalSectionLock> runner;
|
||||
ScopedPtrCollection<Thread> threads;
|
||||
std::vector<std::unique_ptr<Thread>> threads;
|
||||
StartThreads(&threads, &runner);
|
||||
runner.SetExpectedThreadCount(kNumThreads);
|
||||
|
||||
|
||||
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 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.
|
||||
*/
|
||||
|
||||
// Stores a collection of pointers that are deleted when the container is
|
||||
// destructed.
|
||||
|
||||
#ifndef WEBRTC_BASE_SCOPEDPTRCOLLECTION_H_
|
||||
#define WEBRTC_BASE_SCOPEDPTRCOLLECTION_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
template<class T>
|
||||
class ScopedPtrCollection {
|
||||
public:
|
||||
typedef std::vector<T*> VectorT;
|
||||
|
||||
ScopedPtrCollection() { }
|
||||
~ScopedPtrCollection() {
|
||||
for (typename VectorT::iterator it = collection_.begin();
|
||||
it != collection_.end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
|
||||
const VectorT& collection() const { return collection_; }
|
||||
void Reserve(size_t size) {
|
||||
collection_.reserve(size);
|
||||
}
|
||||
void PushBack(T* t) {
|
||||
collection_.push_back(t);
|
||||
}
|
||||
|
||||
// Remove |t| from the collection without deleting it.
|
||||
void Remove(T* t) {
|
||||
collection_.erase(std::remove(collection_.begin(), collection_.end(), t),
|
||||
collection_.end());
|
||||
}
|
||||
|
||||
private:
|
||||
VectorT collection_;
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(ScopedPtrCollection);
|
||||
};
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // WEBRTC_BASE_SCOPEDPTRCOLLECTION_H_
|
||||
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright 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.
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
#include "webrtc/base/scopedptrcollection.h"
|
||||
#include "webrtc/base/gunit.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
namespace {
|
||||
|
||||
class InstanceCounter {
|
||||
public:
|
||||
explicit InstanceCounter(int* num_instances)
|
||||
: num_instances_(num_instances) {
|
||||
++(*num_instances_);
|
||||
}
|
||||
~InstanceCounter() {
|
||||
--(*num_instances_);
|
||||
}
|
||||
|
||||
private:
|
||||
int* num_instances_;
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(InstanceCounter);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
class ScopedPtrCollectionTest : public testing::Test {
|
||||
protected:
|
||||
ScopedPtrCollectionTest()
|
||||
: num_instances_(0),
|
||||
collection_(new ScopedPtrCollection<InstanceCounter>()) {
|
||||
}
|
||||
|
||||
int num_instances_;
|
||||
std::unique_ptr<ScopedPtrCollection<InstanceCounter> > collection_;
|
||||
};
|
||||
|
||||
TEST_F(ScopedPtrCollectionTest, PushBack) {
|
||||
EXPECT_EQ(0u, collection_->collection().size());
|
||||
EXPECT_EQ(0, num_instances_);
|
||||
const int kNum = 100;
|
||||
for (int i = 0; i < kNum; ++i) {
|
||||
collection_->PushBack(new InstanceCounter(&num_instances_));
|
||||
}
|
||||
EXPECT_EQ(static_cast<size_t>(kNum), collection_->collection().size());
|
||||
EXPECT_EQ(kNum, num_instances_);
|
||||
collection_.reset();
|
||||
EXPECT_EQ(0, num_instances_);
|
||||
}
|
||||
|
||||
TEST_F(ScopedPtrCollectionTest, Remove) {
|
||||
InstanceCounter* ic = new InstanceCounter(&num_instances_);
|
||||
collection_->PushBack(ic);
|
||||
EXPECT_EQ(1u, collection_->collection().size());
|
||||
collection_->Remove(ic);
|
||||
EXPECT_EQ(1, num_instances_);
|
||||
collection_.reset();
|
||||
EXPECT_EQ(1, num_instances_);
|
||||
delete ic;
|
||||
EXPECT_EQ(0, num_instances_);
|
||||
}
|
||||
|
||||
|
||||
} // namespace rtc
|
||||
Loading…
x
Reference in New Issue
Block a user