From c9e58779e1a30b32ea2f86e686211d901aca19f0 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 5 Jul 2013 22:48:34 +0900 Subject: [PATCH] Use std::unique_ptr for IteratableValidator --- src/CheckIntegrityEntry.cc | 8 ++++---- src/CheckIntegrityEntry.h | 4 ++-- src/ChecksumCheckIntegrityEntry.cc | 15 ++++++++------- src/PieceHashCheckIntegrityEntry.cc | 15 ++++++++------- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/CheckIntegrityEntry.cc b/src/CheckIntegrityEntry.cc index 93a3fc20..a06b468e 100644 --- a/src/CheckIntegrityEntry.cc +++ b/src/CheckIntegrityEntry.cc @@ -45,8 +45,8 @@ namespace aria2 { CheckIntegrityEntry::CheckIntegrityEntry(RequestGroup* requestGroup, - std::unique_ptr nextCommand): - RequestGroupEntry(requestGroup, std::move(nextCommand)) + std::unique_ptr nextCommand) + : RequestGroupEntry{requestGroup, std::move(nextCommand)} {} CheckIntegrityEntry::~CheckIntegrityEntry() {} @@ -97,9 +97,9 @@ void CheckIntegrityEntry::proceedFileAllocation } void CheckIntegrityEntry::setValidator -(const std::shared_ptr& validator) +(std::unique_ptr validator) { - validator_ = validator; + validator_ = std::move(validator); } } // namespace aria2 diff --git a/src/CheckIntegrityEntry.h b/src/CheckIntegrityEntry.h index 5d6b2419..cb2576c0 100644 --- a/src/CheckIntegrityEntry.h +++ b/src/CheckIntegrityEntry.h @@ -51,9 +51,9 @@ class FileAllocationEntry; class CheckIntegrityEntry : public RequestGroupEntry, public ProgressAwareEntry { private: - std::shared_ptr validator_; + std::unique_ptr validator_; protected: - void setValidator(const std::shared_ptr& validator); + void setValidator(std::unique_ptr validator); void proceedFileAllocation(std::vector>& commands, const std::shared_ptr& entry, diff --git a/src/ChecksumCheckIntegrityEntry.cc b/src/ChecksumCheckIntegrityEntry.cc index cb6b33fb..89ee08fd 100644 --- a/src/ChecksumCheckIntegrityEntry.cc +++ b/src/ChecksumCheckIntegrityEntry.cc @@ -45,9 +45,10 @@ namespace aria2 { ChecksumCheckIntegrityEntry::ChecksumCheckIntegrityEntry -(RequestGroup* requestGroup, std::unique_ptr nextCommand): - CheckIntegrityEntry(requestGroup, std::move(nextCommand)), - redownload_(false) {} +(RequestGroup* requestGroup, std::unique_ptr nextCommand) + : CheckIntegrityEntry{requestGroup, std::move(nextCommand)}, + redownload_{false} +{} ChecksumCheckIntegrityEntry::~ChecksumCheckIntegrityEntry() {} @@ -60,11 +61,11 @@ bool ChecksumCheckIntegrityEntry::isValidationReady() void ChecksumCheckIntegrityEntry::initValidator() { - std::shared_ptr validator - (new IteratableChecksumValidator(getRequestGroup()->getDownloadContext(), - getRequestGroup()->getPieceStorage())); + auto validator = make_unique + (getRequestGroup()->getDownloadContext(), + getRequestGroup()->getPieceStorage()); validator->init(); - setValidator(validator); + setValidator(std::move(validator)); } void diff --git a/src/PieceHashCheckIntegrityEntry.cc b/src/PieceHashCheckIntegrityEntry.cc index 41d2eec2..1356fc11 100644 --- a/src/PieceHashCheckIntegrityEntry.cc +++ b/src/PieceHashCheckIntegrityEntry.cc @@ -37,13 +37,15 @@ #include "IteratableChunkChecksumValidator.h" #include "DownloadContext.h" #include "PieceStorage.h" +#include "a2functional.h" namespace aria2 { PieceHashCheckIntegrityEntry::PieceHashCheckIntegrityEntry (RequestGroup* requestGroup, - std::unique_ptr nextCommand): - CheckIntegrityEntry(requestGroup, std::move(nextCommand)) {} + std::unique_ptr nextCommand) + : CheckIntegrityEntry{requestGroup, std::move(nextCommand)} +{} PieceHashCheckIntegrityEntry::~PieceHashCheckIntegrityEntry() {} @@ -57,12 +59,11 @@ bool PieceHashCheckIntegrityEntry::isValidationReady() void PieceHashCheckIntegrityEntry::initValidator() { #ifdef ENABLE_MESSAGE_DIGEST - std::shared_ptr validator - (new IteratableChunkChecksumValidator - (getRequestGroup()->getDownloadContext(), - getRequestGroup()->getPieceStorage())); + auto validator = make_unique + (getRequestGroup()->getDownloadContext(), + getRequestGroup()->getPieceStorage()); validator->init(); - setValidator(validator); + setValidator(std::move(validator)); #endif // ENABLE_MESSAGE_DIGEST }