mirror of https://github.com/aria2/aria2
2009-06-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Moved getFirstRequestedFileEntry(), countRequestedFileEntry() and writeFilePath() function template from RequestGroupMan.cc to FileEntry.h * src/FileEntry.h * src/RequestGroupMan.ccpull/1/head
parent
1c070ed66e
commit
9120e79ff1
|
@ -1,3 +1,11 @@
|
||||||
|
2009-06-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Moved getFirstRequestedFileEntry(), countRequestedFileEntry() and
|
||||||
|
writeFilePath() function template from RequestGroupMan.cc to
|
||||||
|
FileEntry.h
|
||||||
|
* src/FileEntry.h
|
||||||
|
* src/RequestGroupMan.cc
|
||||||
|
|
||||||
2009-06-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-06-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Documented 'position' parameter is starting from 0 in man page.
|
Documented 'position' parameter is starting from 0 in man page.
|
||||||
|
|
|
@ -36,10 +36,13 @@
|
||||||
#define _D_FILE_ENTRY_H_
|
#define _D_FILE_ENTRY_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "SharedHandle.h"
|
|
||||||
#include "File.h"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
#include "SharedHandle.h"
|
||||||
|
#include "File.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -106,6 +109,64 @@ public:
|
||||||
typedef SharedHandle<FileEntry> FileEntryHandle;
|
typedef SharedHandle<FileEntry> FileEntryHandle;
|
||||||
typedef std::deque<FileEntryHandle> FileEntries;
|
typedef std::deque<FileEntryHandle> FileEntries;
|
||||||
|
|
||||||
|
// Returns the first FileEntry which isRequested() method returns
|
||||||
|
// true. If no such FileEntry exists, then returns
|
||||||
|
// SharedHandle<FileEntry>().
|
||||||
|
template<typename InputIterator>
|
||||||
|
SharedHandle<FileEntry> getFirstRequestedFileEntry
|
||||||
|
(InputIterator first, InputIterator last)
|
||||||
|
{
|
||||||
|
for(; first != last; ++first) {
|
||||||
|
if((*first)->isRequested()) {
|
||||||
|
return *first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return SharedHandle<FileEntry>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Counts the number of files selected in the given iterator range
|
||||||
|
// [first, last).
|
||||||
|
template<typename InputIterator>
|
||||||
|
size_t countRequestedFileEntry(InputIterator first, InputIterator last)
|
||||||
|
{
|
||||||
|
size_t count = 0;
|
||||||
|
for(; first != last; ++first) {
|
||||||
|
if((*first)->isRequested()) {
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Writes first filename to given o. If memory is true, the output is
|
||||||
|
// "[MEMORY]" plus the basename of the first filename. If there is no
|
||||||
|
// FileEntry, writes "n/a" to o. If more than 1 FileEntry are in the
|
||||||
|
// iterator range [first, last), "(Nmore)" is written at the end where
|
||||||
|
// N is the number of files in iterator range [first, last) minus 1.
|
||||||
|
template<typename InputIterator>
|
||||||
|
void writeFilePath
|
||||||
|
(InputIterator first, InputIterator last, std::ostream& o, bool memory)
|
||||||
|
{
|
||||||
|
SharedHandle<FileEntry> e = getFirstRequestedFileEntry(first, last);
|
||||||
|
if(e.isNull()) {
|
||||||
|
o << "n/a";
|
||||||
|
} else {
|
||||||
|
if(e->getPath().empty()) {
|
||||||
|
o << "n/a";
|
||||||
|
} else {
|
||||||
|
if(memory) {
|
||||||
|
o << "[MEMORY]" << File(e->getPath()).getBasename();
|
||||||
|
} else {
|
||||||
|
o << e->getPath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
size_t count = countRequestedFileEntry(first, last);
|
||||||
|
if(count > 1) {
|
||||||
|
o << " (" << count-1 << "more)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // _D_FILE_ENTRY_H_
|
#endif // _D_FILE_ENTRY_H_
|
||||||
|
|
|
@ -616,54 +616,6 @@ void RequestGroupMan::showDownloadResults(std::ostream& o) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename InputIterator>
|
|
||||||
static SharedHandle<FileEntry> getFirstRequestedFileEntry
|
|
||||||
(InputIterator first, InputIterator last)
|
|
||||||
{
|
|
||||||
for(; first != last; ++first) {
|
|
||||||
if((*first)->isRequested()) {
|
|
||||||
return *first;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return SharedHandle<FileEntry>();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename InputIterator>
|
|
||||||
static size_t countRequestedFileEntry(InputIterator first, InputIterator last)
|
|
||||||
{
|
|
||||||
size_t count = 0;
|
|
||||||
for(; first != last; ++first) {
|
|
||||||
if((*first)->isRequested()) {
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename InputIterator>
|
|
||||||
static void writeFilePath
|
|
||||||
(InputIterator first, InputIterator last, std::ostream& o, bool memory)
|
|
||||||
{
|
|
||||||
SharedHandle<FileEntry> e = getFirstRequestedFileEntry(first, last);
|
|
||||||
if(e.isNull()) {
|
|
||||||
o << "n/a";
|
|
||||||
} else {
|
|
||||||
if(e->getPath().empty()) {
|
|
||||||
o << "n/a";
|
|
||||||
} else {
|
|
||||||
if(memory) {
|
|
||||||
o << "[MEMORY]" << File(e->getPath()).getBasename();
|
|
||||||
} else {
|
|
||||||
o << e->getPath();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
size_t count = countRequestedFileEntry(first, last);
|
|
||||||
if(count > 1) {
|
|
||||||
o << " (" << count-1 << "more)";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string RequestGroupMan::formatDownloadResult(const std::string& status, const DownloadResultHandle& downloadResult) const
|
std::string RequestGroupMan::formatDownloadResult(const std::string& status, const DownloadResultHandle& downloadResult) const
|
||||||
{
|
{
|
||||||
std::stringstream o;
|
std::stringstream o;
|
||||||
|
|
Loading…
Reference in New Issue