From 39472a64ebd7d73ccbbc9b084a6e7b22febe36e3 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 14 Jun 2009 11:12:20 +0000 Subject: [PATCH] 2009-06-14 Tatsuhiro Tsujikawa DownloadContext now has _fileEntries so that DownloadContext::getFileEntries() can returns its const reference. * src/DefaultBtContext.cc * src/DefaultBtContext.h * src/DownloadContext.cc * src/DownloadContext.h * src/SingleFileDownloadContext.cc * src/SingleFileDownloadContext.h --- ChangeLog | 11 +++++++++++ src/DefaultBtContext.cc | 22 +++++++++------------- src/DefaultBtContext.h | 3 --- src/DownloadContext.cc | 1 + src/DownloadContext.h | 8 ++++++-- src/SingleFileDownloadContext.cc | 26 ++++++++++---------------- src/SingleFileDownloadContext.h | 7 +++---- 7 files changed, 40 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index d3433903..205c9b04 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2009-06-14 Tatsuhiro Tsujikawa + + DownloadContext now has _fileEntries so that + DownloadContext::getFileEntries() can returns its const reference. + * src/DefaultBtContext.cc + * src/DefaultBtContext.h + * src/DownloadContext.cc + * src/DownloadContext.h + * src/SingleFileDownloadContext.cc + * src/SingleFileDownloadContext.h + 2009-06-14 Tatsuhiro Tsujikawa Moved getFirstRequestedFileEntry(), countRequestedFileEntry() and diff --git a/src/DefaultBtContext.cc b/src/DefaultBtContext.cc index 45fcf0d6..29aaea47 100644 --- a/src/DefaultBtContext.cc +++ b/src/DefaultBtContext.cc @@ -122,7 +122,7 @@ void DefaultBtContext::clear() { memset(infoHash, 0, INFO_HASH_LENGTH); infoHashString = A2STR::NIL; pieceHashes.clear(); - fileEntries.clear(); + _fileEntries.clear(); totalLength = 0; pieceLength = 0; fileMode = BtContext::SINGLE; @@ -211,7 +211,7 @@ void DefaultBtContext::extractFileEntries(const BDE& infoDict, FileEntryHandle fileEntry(new FileEntry(strconcat(_dir, "/", path), fileLengthData.i(), offset, uris)); - fileEntries.push_back(fileEntry); + _fileEntries.push_back(fileEntry); offset += fileEntry->getLength(); } totalLength = length; @@ -245,7 +245,7 @@ void DefaultBtContext::extractFileEntries(const BDE& infoDict, Util::joinPath(pathelems.begin(), pathelems.end())), totalLength, 0, uris)); - fileEntries.push_back(fileEntry); + _fileEntries.push_back(fileEntry); } } @@ -435,10 +435,6 @@ BtContext::FILE_MODE DefaultBtContext::getFileMode() const { return fileMode; } -FileEntries DefaultBtContext::getFileEntries() const { - return fileEntries; -} - const std::string& DefaultBtContext::getPieceHashAlgo() const { return MessageDigestContext::SHA1; @@ -464,8 +460,8 @@ size_t DefaultBtContext::getNumPieces() const { std::string DefaultBtContext::getActualBasePath() const { - if(fileEntries.size() == 1) { - return fileEntries.front()->getPath(); + if(_fileEntries.size() == 1) { + return _fileEntries.front()->getPath(); } else { return strconcat(_dir, "/", name); } @@ -552,8 +548,8 @@ void DefaultBtContext::setInfoHash(const unsigned char* infoHash) void DefaultBtContext::setFilePathWithIndex (size_t index, const std::string& path) { - if(0 < index && index <= fileEntries.size()) { - fileEntries[index-1]->setPath(path); + if(0 < index && index <= _fileEntries.size()) { + _fileEntries[index-1]->setPath(path); } else { throw DL_ABORT_EX(StringFormat("No such file with index=%u", static_cast(index)).str()); @@ -567,11 +563,11 @@ void DefaultBtContext::setFileFilter(IntSequence seq) fileIndexes.erase(std::unique(fileIndexes.begin(), fileIndexes.end()), fileIndexes.end()); - bool selectAll = fileIndexes.empty() || fileEntries.size() == 1; + bool selectAll = fileIndexes.empty() || _fileEntries.size() == 1; int32_t index = 1; for(std::deque >::const_iterator i = - fileEntries.begin(); i != fileEntries.end(); ++i, ++index) { + _fileEntries.begin(); i != _fileEntries.end(); ++i, ++index) { (*i)->setRequested (selectAll || std::binary_search(fileIndexes.begin(), fileIndexes.end(), index)); diff --git a/src/DefaultBtContext.h b/src/DefaultBtContext.h index 7a7c6d82..a238c7a8 100644 --- a/src/DefaultBtContext.h +++ b/src/DefaultBtContext.h @@ -55,7 +55,6 @@ private: unsigned char infoHash[INFO_HASH_LENGTH]; std::string infoHashString; std::deque pieceHashes; - std::deque > fileEntries; FILE_MODE fileMode; uint64_t totalLength; size_t pieceLength; @@ -143,8 +142,6 @@ private: virtual FILE_MODE getFileMode() const; - virtual std::deque > getFileEntries() const; - virtual const std::string& getPieceHashAlgo() const; virtual const std::deque >& diff --git a/src/DownloadContext.cc b/src/DownloadContext.cc index 98811952..2d3b888a 100644 --- a/src/DownloadContext.cc +++ b/src/DownloadContext.cc @@ -33,6 +33,7 @@ */ /* copyright --> */ #include "DownloadContext.h" +#include "FileEntry.h" namespace aria2 { diff --git a/src/DownloadContext.h b/src/DownloadContext.h index a73aa236..e40c9a18 100644 --- a/src/DownloadContext.h +++ b/src/DownloadContext.h @@ -51,8 +51,9 @@ class FileEntry; class DownloadContext { protected: - std::string _dir; + std::deque > _fileEntries; + std::string _dir; private: Time _downloadStartTime; @@ -79,7 +80,10 @@ public: virtual FILE_MODE getFileMode() const = 0; - virtual std::deque > getFileEntries() const = 0; + const std::deque >& getFileEntries() const + { + return _fileEntries; + } virtual size_t getPieceLength() const = 0; diff --git a/src/SingleFileDownloadContext.cc b/src/SingleFileDownloadContext.cc index 3e2c2f35..92332f85 100644 --- a/src/SingleFileDownloadContext.cc +++ b/src/SingleFileDownloadContext.cc @@ -44,22 +44,24 @@ SingleFileDownloadContext::SingleFileDownloadContext(size_t pieceLength, const std::string& filename, const std::string& ufilename): _pieceLength(pieceLength), - _fileEntry(new FileEntry(filename, totalLength, 0)), _filename(filename), _ufilename(ufilename), _knowsTotalLength(true) { + _fileEntries.push_back + (SharedHandle(new FileEntry(filename, totalLength, 0))); updateFileEntry(); } void SingleFileDownloadContext::updateFileEntry() { + const SharedHandle& fileEntry = _fileEntries.front(); if(!_ufilename.empty()) { - _fileEntry->setPath(_ufilename); + fileEntry->setPath(_ufilename); } else if(!_filename.empty()) { - _fileEntry->setPath(_filename); + fileEntry->setPath(_filename); } else { - _fileEntry->setPath(""); + fileEntry->setPath(""); } } @@ -71,7 +73,7 @@ SingleFileDownloadContext::getPieceHashes() const uint64_t SingleFileDownloadContext::getTotalLength() const { - return _fileEntry->getLength(); + return _fileEntries.front()->getLength(); } bool SingleFileDownloadContext::knowsTotalLength() const @@ -79,27 +81,19 @@ bool SingleFileDownloadContext::knowsTotalLength() const return _knowsTotalLength; } -FileEntries -SingleFileDownloadContext::getFileEntries() const -{ - FileEntries fs; - fs.push_back(_fileEntry); - return fs; -} - size_t SingleFileDownloadContext::getNumPieces() const { - return (_fileEntry->getLength()+_pieceLength-1)/_pieceLength; + return (_fileEntries.front()->getLength()+_pieceLength-1)/_pieceLength; } std::string SingleFileDownloadContext::getActualBasePath() const { - return _fileEntry->getPath(); + return _fileEntries.front()->getPath(); } void SingleFileDownloadContext::setTotalLength(uint64_t totalLength) { - _fileEntry->setLength(totalLength); + _fileEntries.front()->setLength(totalLength); } void SingleFileDownloadContext::markTotalLengthIsUnknown() diff --git a/src/SingleFileDownloadContext.h b/src/SingleFileDownloadContext.h index 6a254c88..1375ba5c 100644 --- a/src/SingleFileDownloadContext.h +++ b/src/SingleFileDownloadContext.h @@ -36,17 +36,18 @@ #define _D_SINGLE_FILE_DOWNLOAD_CONTEXT_H_ #include "DownloadContext.h" -#include "A2STR.h" + #include #include +#include "A2STR.h" + namespace aria2 { class SingleFileDownloadContext:public DownloadContext { private: size_t _pieceLength; - SharedHandle _fileEntry; /** * _filename and _ufilename may contains directory path name. So * /usr/local/aria2c is acceptable here. These should be complete @@ -95,8 +96,6 @@ public: return SINGLE; } - virtual std::deque > getFileEntries() const; - virtual size_t getPieceLength() const { return _pieceLength;