Use std::unique_ptr for IteratableValidator

pull/106/head
Tatsuhiro Tsujikawa 2013-07-05 22:48:34 +09:00
parent d3a04d10a7
commit c9e58779e1
4 changed files with 22 additions and 20 deletions

View File

@ -45,8 +45,8 @@
namespace aria2 { namespace aria2 {
CheckIntegrityEntry::CheckIntegrityEntry(RequestGroup* requestGroup, CheckIntegrityEntry::CheckIntegrityEntry(RequestGroup* requestGroup,
std::unique_ptr<Command> nextCommand): std::unique_ptr<Command> nextCommand)
RequestGroupEntry(requestGroup, std::move(nextCommand)) : RequestGroupEntry{requestGroup, std::move(nextCommand)}
{} {}
CheckIntegrityEntry::~CheckIntegrityEntry() {} CheckIntegrityEntry::~CheckIntegrityEntry() {}
@ -97,9 +97,9 @@ void CheckIntegrityEntry::proceedFileAllocation
} }
void CheckIntegrityEntry::setValidator void CheckIntegrityEntry::setValidator
(const std::shared_ptr<IteratableValidator>& validator) (std::unique_ptr<IteratableValidator> validator)
{ {
validator_ = validator; validator_ = std::move(validator);
} }
} // namespace aria2 } // namespace aria2

View File

@ -51,9 +51,9 @@ class FileAllocationEntry;
class CheckIntegrityEntry : public RequestGroupEntry, class CheckIntegrityEntry : public RequestGroupEntry,
public ProgressAwareEntry { public ProgressAwareEntry {
private: private:
std::shared_ptr<IteratableValidator> validator_; std::unique_ptr<IteratableValidator> validator_;
protected: protected:
void setValidator(const std::shared_ptr<IteratableValidator>& validator); void setValidator(std::unique_ptr<IteratableValidator> validator);
void proceedFileAllocation(std::vector<std::unique_ptr<Command>>& commands, void proceedFileAllocation(std::vector<std::unique_ptr<Command>>& commands,
const std::shared_ptr<FileAllocationEntry>& entry, const std::shared_ptr<FileAllocationEntry>& entry,

View File

@ -45,9 +45,10 @@
namespace aria2 { namespace aria2 {
ChecksumCheckIntegrityEntry::ChecksumCheckIntegrityEntry ChecksumCheckIntegrityEntry::ChecksumCheckIntegrityEntry
(RequestGroup* requestGroup, std::unique_ptr<Command> nextCommand): (RequestGroup* requestGroup, std::unique_ptr<Command> nextCommand)
CheckIntegrityEntry(requestGroup, std::move(nextCommand)), : CheckIntegrityEntry{requestGroup, std::move(nextCommand)},
redownload_(false) {} redownload_{false}
{}
ChecksumCheckIntegrityEntry::~ChecksumCheckIntegrityEntry() {} ChecksumCheckIntegrityEntry::~ChecksumCheckIntegrityEntry() {}
@ -60,11 +61,11 @@ bool ChecksumCheckIntegrityEntry::isValidationReady()
void ChecksumCheckIntegrityEntry::initValidator() void ChecksumCheckIntegrityEntry::initValidator()
{ {
std::shared_ptr<IteratableChecksumValidator> validator auto validator = make_unique<IteratableChecksumValidator>
(new IteratableChecksumValidator(getRequestGroup()->getDownloadContext(), (getRequestGroup()->getDownloadContext(),
getRequestGroup()->getPieceStorage())); getRequestGroup()->getPieceStorage());
validator->init(); validator->init();
setValidator(validator); setValidator(std::move(validator));
} }
void void

View File

@ -37,13 +37,15 @@
#include "IteratableChunkChecksumValidator.h" #include "IteratableChunkChecksumValidator.h"
#include "DownloadContext.h" #include "DownloadContext.h"
#include "PieceStorage.h" #include "PieceStorage.h"
#include "a2functional.h"
namespace aria2 { namespace aria2 {
PieceHashCheckIntegrityEntry::PieceHashCheckIntegrityEntry PieceHashCheckIntegrityEntry::PieceHashCheckIntegrityEntry
(RequestGroup* requestGroup, (RequestGroup* requestGroup,
std::unique_ptr<Command> nextCommand): std::unique_ptr<Command> nextCommand)
CheckIntegrityEntry(requestGroup, std::move(nextCommand)) {} : CheckIntegrityEntry{requestGroup, std::move(nextCommand)}
{}
PieceHashCheckIntegrityEntry::~PieceHashCheckIntegrityEntry() {} PieceHashCheckIntegrityEntry::~PieceHashCheckIntegrityEntry() {}
@ -57,12 +59,11 @@ bool PieceHashCheckIntegrityEntry::isValidationReady()
void PieceHashCheckIntegrityEntry::initValidator() void PieceHashCheckIntegrityEntry::initValidator()
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
std::shared_ptr<IteratableChunkChecksumValidator> validator auto validator = make_unique<IteratableChunkChecksumValidator>
(new IteratableChunkChecksumValidator (getRequestGroup()->getDownloadContext(),
(getRequestGroup()->getDownloadContext(), getRequestGroup()->getPieceStorage());
getRequestGroup()->getPieceStorage()));
validator->init(); validator->init();
setValidator(validator); setValidator(std::move(validator));
#endif // ENABLE_MESSAGE_DIGEST #endif // ENABLE_MESSAGE_DIGEST
} }