2008-05-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Changed method sinature:
	MetalinkEntry::toFileEntry,
	MetalinkHelper::query, MetalinkHelper::parseAndQuery,
	Metalinker::queryEntry
	* src/Metalink2RequestGroup.cc
	* src/MetalinkEntry.cc
	* src/MetalinkEntry.h
	* src/MetalinkHelper.cc
	* src/MetalinkHelper.h
	* src/Metalinker.cc
	* src/Metalinker.h
	* src/main.cc
	* test/MetalinkHelperTest.cc
	* test/MetalinkerTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-05-12 11:39:34 +00:00
parent f84eac327f
commit 3da60af41e
11 changed files with 100 additions and 65 deletions

View File

@ -1,3 +1,20 @@
2008-05-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Changed method sinature:
MetalinkEntry::toFileEntry,
MetalinkHelper::query, MetalinkHelper::parseAndQuery,
Metalinker::queryEntry
* src/Metalink2RequestGroup.cc
* src/MetalinkEntry.cc
* src/MetalinkEntry.h
* src/MetalinkHelper.cc
* src/MetalinkHelper.h
* src/Metalinker.cc
* src/Metalinker.h
* src/main.cc
* test/MetalinkHelperTest.cc
* test/MetalinkerTest.cc
2008-05-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Changed method sinature:

View File

@ -102,8 +102,8 @@ void
Metalink2RequestGroup::generate(std::deque<SharedHandle<RequestGroup> >& groups,
const std::string& metalinkFile)
{
std::deque<SharedHandle<MetalinkEntry> > entries = MetalinkHelper::parseAndQuery(metalinkFile,
_option);
std::deque<SharedHandle<MetalinkEntry> > entries;
MetalinkHelper::parseAndQuery(entries, metalinkFile, _option);
createRequestGroup(groups, entries);
}
@ -111,8 +111,8 @@ void
Metalink2RequestGroup::generate(std::deque<SharedHandle<RequestGroup> >& groups,
const SharedHandle<BinaryStream>& binaryStream)
{
std::deque<SharedHandle<MetalinkEntry> > entries = MetalinkHelper::parseAndQuery(binaryStream,
_option);
std::deque<SharedHandle<MetalinkEntry> > entries;
MetalinkHelper::parseAndQuery(entries, binaryStream, _option);
createRequestGroup(groups, entries);
}

View File

@ -166,13 +166,13 @@ void MetalinkEntry::dropUnsupportedResource() {
resources.end());
}
std::deque<SharedHandle<FileEntry> >
MetalinkEntry::toFileEntry(const std::deque<SharedHandle<MetalinkEntry> >& metalinkEntries)
void MetalinkEntry::toFileEntry
(std::deque<SharedHandle<FileEntry> >& fileEntries,
const std::deque<SharedHandle<MetalinkEntry> >& metalinkEntries)
{
std::deque<SharedHandle<FileEntry> > entries;
std::transform(metalinkEntries.begin(), metalinkEntries.end(), std::back_inserter(entries),
std::transform(metalinkEntries.begin(), metalinkEntries.end(),
std::back_inserter(fileEntries),
mem_fun_sh(&MetalinkEntry::getFile));
return entries;
}
SharedHandle<FileEntry> MetalinkEntry::getFile() const

View File

@ -81,8 +81,9 @@ public:
void setLocationPreference(const std::deque<std::string>& locations, int preferenceToAdd);
void setProtocolPreference(const std::string& protocol, int preferenceToAdd);
static std::deque<SharedHandle<FileEntry> >
toFileEntry(const std::deque<SharedHandle<MetalinkEntry> >& metalinkEntries);
static void toFileEntry
(std::deque<SharedHandle<FileEntry> >& fileEntries,
const std::deque<SharedHandle<MetalinkEntry> >& metalinkEntries);
};
} // namespace aria2

View File

@ -50,35 +50,37 @@ MetalinkHelper::MetalinkHelper() {}
MetalinkHelper::~MetalinkHelper() {}
std::deque<SharedHandle<MetalinkEntry> >
MetalinkHelper::parseAndQuery(const std::string& filename, const Option* option)
void MetalinkHelper::parseAndQuery
(std::deque<SharedHandle<MetalinkEntry> >& result,
const std::string& filename, const Option* option)
{
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
SharedHandle<Metalinker> metalinker = proc->parseFile(filename);
return query(metalinker, option);
query(result, metalinker, option);
}
std::deque<SharedHandle<MetalinkEntry> >
MetalinkHelper::parseAndQuery(const SharedHandle<BinaryStream>& binaryStream, const Option* option)
void MetalinkHelper::parseAndQuery
(std::deque<SharedHandle<MetalinkEntry> >& result,
const SharedHandle<BinaryStream>& binaryStream, const Option* option)
{
SharedHandle<MetalinkProcessor> proc = MetalinkProcessorFactory::newInstance();
SharedHandle<Metalinker> metalinker = proc->parseFromBinaryStream(binaryStream);
return query(metalinker, option);
query(result, metalinker, option);
}
std::deque<SharedHandle<MetalinkEntry> >
MetalinkHelper::query(const SharedHandle<Metalinker>& metalinker, const Option* option)
void MetalinkHelper::query
(std::deque<SharedHandle<MetalinkEntry> >& result,
const SharedHandle<Metalinker>& metalinker, const Option* option)
{
if(metalinker->entries.empty()) {
throw DlAbortEx("No file entry found. Probably, the metalink file is not configured properly or broken.");
}
std::deque<SharedHandle<MetalinkEntry> > entries =
metalinker->queryEntry(option->get(PREF_METALINK_VERSION),
metalinker->queryEntry(result,
option->get(PREF_METALINK_VERSION),
option->get(PREF_METALINK_LANGUAGE),
option->get(PREF_METALINK_OS));
return entries;
}
} // namespace aria2

View File

@ -53,15 +53,18 @@ private:
~MetalinkHelper();
static std::deque<SharedHandle<MetalinkEntry> >
query(const SharedHandle<Metalinker>& metalinker, const Option* option);
static void query
(std::deque<SharedHandle<MetalinkEntry> >& result,
const SharedHandle<Metalinker>& metalinker, const Option* option);
public:
static std::deque<SharedHandle<MetalinkEntry> >
parseAndQuery(const std::string& filename, const Option* option);
static void parseAndQuery
(std::deque<SharedHandle<MetalinkEntry> >& result,
const std::string& filename, const Option* option);
static std::deque<SharedHandle<MetalinkEntry> >
parseAndQuery(const SharedHandle<BinaryStream>& binaryStream, const Option* option);
static void parseAndQuery
(std::deque<SharedHandle<MetalinkEntry> >& result,
const SharedHandle<BinaryStream>& binaryStream, const Option* option);
};
} // namespace aria2

View File

@ -75,17 +75,15 @@ public:
}
};
std::deque<SharedHandle<MetalinkEntry> >
Metalinker::queryEntry(const std::string& version,
void Metalinker::queryEntry
(std::deque<SharedHandle<MetalinkEntry> >& queryResult,
const std::string& version,
const std::string& language,
const std::string& os) const
{
std::deque<SharedHandle<MetalinkEntry> > resultEntries(entries);
resultEntries.erase(std::remove_if(resultEntries.begin(),
resultEntries.end(),
std::not1(EntryQuery(version, language, os))),
resultEntries.end());
return resultEntries;
std::remove_copy_if(entries.begin(), entries.end(),
std::back_inserter(queryResult),
std::not1(EntryQuery(version, language, os)));
}
} // namespace aria2

View File

@ -58,8 +58,10 @@ public:
return *this;
}
std::deque<SharedHandle<MetalinkEntry> >
queryEntry(const std::string& version, const std::string& language,
void queryEntry
(std::deque<SharedHandle<MetalinkEntry> >& queryResult,
const std::string& version,
const std::string& language,
const std::string& os) const;
};

View File

@ -400,7 +400,12 @@ int main(int argc, char* argv[])
#ifdef ENABLE_METALINK
if(op->defined(PREF_METALINK_FILE)) {
if(op->get(PREF_SHOW_FILES) == V_TRUE) {
Util::toStream(std::cout, MetalinkEntry::toFileEntry(MetalinkHelper::parseAndQuery(op->get(PREF_METALINK_FILE), op)));
std::deque<SharedHandle<MetalinkEntry> > metalinkEntries;
MetalinkHelper::parseAndQuery(metalinkEntries,
op->get(PREF_METALINK_FILE), op);
std::deque<SharedHandle<FileEntry> > fileEntries;
MetalinkEntry::toFileEntry(fileEntries, metalinkEntries);
Util::toStream(std::cout, fileEntries);
} else {
returnValue = downloadMetalink(op);
}

View File

@ -29,19 +29,19 @@ CPPUNIT_TEST_SUITE_REGISTRATION( MetalinkHelperTest );
void MetalinkHelperTest::testParseAndQuery()
{
Option option;
std::deque<SharedHandle<MetalinkEntry> > entries =
MetalinkHelper::parseAndQuery("test.xml", &option);
CPPUNIT_ASSERT_EQUAL((size_t)5, entries.size());
std::deque<SharedHandle<MetalinkEntry> > result;
MetalinkHelper::parseAndQuery(result, "test.xml", &option);
CPPUNIT_ASSERT_EQUAL((size_t)5, result.size());
}
void MetalinkHelperTest::testParseAndQuery_version()
{
Option option;
option.put(PREF_METALINK_VERSION, "0.5.1");
std::deque<SharedHandle<MetalinkEntry> > entries =
MetalinkHelper::parseAndQuery("test.xml", &option);
CPPUNIT_ASSERT_EQUAL((size_t)1, entries.size());
SharedHandle<MetalinkEntry> entry = entries.front();
std::deque<SharedHandle<MetalinkEntry> > result;
MetalinkHelper::parseAndQuery(result, "test.xml", &option);
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
SharedHandle<MetalinkEntry> entry = result.front();
CPPUNIT_ASSERT_EQUAL(std::string("aria2-0.5.1.tar.bz2"), entry->getPath());
}

View File

@ -43,27 +43,34 @@ void MetalinkerTest::testQueryEntry() {
version = "0.5.1";
language = "ja-JP";
os = "Linux-m68k";
std::deque<SharedHandle<MetalinkEntry> > entries =
metalinker->queryEntry(version, language, os);
CPPUNIT_ASSERT_EQUAL((size_t)1, entries.size());
CPPUNIT_ASSERT_EQUAL(std::string("0.5.1"), entries.at(0)->version);
CPPUNIT_ASSERT_EQUAL(std::string("ja-JP"), entries.at(0)->language);
CPPUNIT_ASSERT_EQUAL(std::string("Linux-m68k"), entries.at(0)->os);
{
std::deque<SharedHandle<MetalinkEntry> > result;
metalinker->queryEntry(result, version, language, os);
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
CPPUNIT_ASSERT_EQUAL(std::string("0.5.1"), result.at(0)->version);
CPPUNIT_ASSERT_EQUAL(std::string("ja-JP"), result.at(0)->language);
CPPUNIT_ASSERT_EQUAL(std::string("Linux-m68k"), result.at(0)->os);
}
version = "0.6.0";
language = "";
os = "";
CPPUNIT_ASSERT_EQUAL((size_t)0,
metalinker->queryEntry(version, language, os).size());
{
std::deque<SharedHandle<MetalinkEntry> > result;
metalinker->queryEntry(result, version, language, os);
CPPUNIT_ASSERT_EQUAL((size_t)0, result.size());
}
version = "0.5.2";
language = "";
os = "";
entries = metalinker->queryEntry(version, language, os);
CPPUNIT_ASSERT_EQUAL((size_t)1, entries.size());
CPPUNIT_ASSERT_EQUAL(std::string("0.5.2"), entries.at(0)->version);
CPPUNIT_ASSERT_EQUAL(std::string("en-US"), entries.at(0)->language);
CPPUNIT_ASSERT_EQUAL(std::string("Linux-x86"), entries.at(0)->os);
{
std::deque<SharedHandle<MetalinkEntry> > result;
metalinker->queryEntry(result, version, language, os);
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
CPPUNIT_ASSERT_EQUAL(std::string("0.5.2"), result.at(0)->version);
CPPUNIT_ASSERT_EQUAL(std::string("en-US"), result.at(0)->language);
CPPUNIT_ASSERT_EQUAL(std::string("Linux-x86"), result.at(0)->os);
}
}
} // namespace aria2