2008-02-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Added std namespace to copy, remove_copy, back_inserter,
	front_inserter.
	* src/RequestGroupMan.cc
	* src/DefaultPieceStorage.cc
	* src/StreamFileAllocationEntry.cc
	* src/BtFileAllocationEntry.cc
	* src/RequestGroup.cc
	* src/MetalinkEntry.cc
	* src/DelegatingPeerListProcessor.cc
	* src/DefaultBtRequestFactory.cc
	* src/DefaultBtMessageDispatcher.cc
	* src/version_usage.cc: Included <algorithm>
	* src/main.cc
	* src/MetalinkParserController.cc
	* src/DefaultBtContext.cc
	* src/DownloadEngineFactory.cc
	* src/a2algo.h

	Removed.
	* test/StreamUriListParserTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-02-08 18:39:26 +00:00
parent 7fdbd0e104
commit 04a7052013
17 changed files with 65 additions and 77 deletions

View File

@ -1,3 +1,34 @@
2008-02-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added std namespace to copy, remove_copy, back_inserter,
front_inserter.
* src/RequestGroupMan.cc
* src/DefaultPieceStorage.cc
* src/StreamFileAllocationEntry.cc
* src/BtFileAllocationEntry.cc
* src/RequestGroup.cc
* src/MetalinkEntry.cc
* src/DelegatingPeerListProcessor.cc
* src/DefaultBtRequestFactory.cc
* src/DefaultBtMessageDispatcher.cc
* src/version_usage.cc: Included <algorithm>
* src/main.cc
* src/MetalinkParserController.cc
* src/DefaultBtContext.cc
* src/DownloadEngineFactory.cc
* src/a2algo.h
Removed.
* test/StreamUriListParserTest.cc
2008-02-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Use PREF_MAX_DOWNLOAD_LIMIT as a threshold for
ActivePeerConnectionCommand when it is given and
PREF_MAX_DOWNLOAD_LIMIT < default threshold.
* src/ActivePeerConnectionCommand.{h, cc}
* src/BtSetup.cc
2008-02-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Only add socket to DownloadEngine's select routine when peer or

View File

@ -37,6 +37,7 @@
#include "RequestGroup.h"
#include "Command.h"
#include "DownloadEngine.h"
#include <algorithm>
namespace aria2 {
@ -50,7 +51,7 @@ Commands BtFileAllocationEntry::prepareForNextAction(DownloadEngine* e)
Commands commands = BtSetup().setup(_requestGroup, e, e->option);
if(!_requestGroup->downloadFinished()) {
Commands streamCommands = _requestGroup->createNextCommandWithAdj(e, 0);
copy(streamCommands.begin(), streamCommands.end(), back_inserter(commands));
std::copy(streamCommands.begin(), streamCommands.end(), std::back_inserter(commands));
}
return commands;
}

View File

@ -162,7 +162,7 @@ void DefaultBtContext::extractFileEntries(const Dictionary* infoDic,
}
std::deque<std::string> uris;
std::transform(urlList.begin(), urlList.end(), back_inserter(uris),
std::transform(urlList.begin(), urlList.end(), std::back_inserter(uris),
std::bind2nd(std::plus<std::string>(), "/"+name+"/"+path));
FileEntryHandle fileEntry(new FileEntry(path,
lengthData->toLLInt(),

View File

@ -49,6 +49,7 @@
#include "Piece.h"
#include "LogFactory.h"
#include "Logger.h"
#include <algorithm>
namespace aria2 {
@ -100,7 +101,7 @@ void DefaultBtMessageDispatcher::sendMessages() {
break;
}
}
copy(tempQueue.begin(), tempQueue.end(), back_inserter(messageQueue));
std::copy(tempQueue.begin(), tempQueue.end(), std::back_inserter(messageQueue));
}
// Cancel sending piece message to peer.
@ -254,7 +255,7 @@ DefaultBtMessageDispatcher::getOutstandingRequest(int32_t index, int32_t begin,
void DefaultBtMessageDispatcher::removeOutstandingRequest(const RequestSlot& slot)
{
RequestSlots temp;
std::remove_copy(requestSlots.begin(), requestSlots.end(), back_inserter(temp), slot);
std::remove_copy(requestSlots.begin(), requestSlots.end(), std::back_inserter(temp), slot);
requestSlots = temp;
}

View File

@ -43,6 +43,7 @@
#include "BtMessageFactory.h"
#include "BtMessage.h"
#include "BtRegistry.h"
#include <algorithm>
namespace aria2 {
@ -80,7 +81,7 @@ void DefaultBtRequestFactory::removeCompletedPiece() {
void DefaultBtRequestFactory::removeTargetPiece(const PieceHandle& piece) {
Pieces temp;
remove_copy(pieces.begin(), pieces.end(), back_inserter(temp), piece);
std::remove_copy(pieces.begin(), pieces.end(), std::back_inserter(temp), piece);
pieces = temp;
dispatcher->doAbortOutstandingRequestAction(piece);
pieceStorage->cancelPiece(piece);

View File

@ -579,7 +579,7 @@ void DefaultPieceStorage::markPieceMissing(int32_t index)
void DefaultPieceStorage::addInFlightPiece(const Pieces& pieces)
{
copy(pieces.begin(), pieces.end(), back_inserter(usedPieces));
std::copy(pieces.begin(), pieces.end(), std::back_inserter(usedPieces));
}
int32_t DefaultPieceStorage::countInFlightPiece()

View File

@ -35,6 +35,7 @@
#include "DefaultPeerListProcessor.h"
#include "CompactPeerListProcessor.h"
#include "Peer.h"
#include <algorithm>
namespace aria2 {
@ -55,7 +56,7 @@ Peers DelegatingPeerListProcessor::extractPeer(const MetaEntry* peersEntry) {
PeerListProcessorHandle processor = *itr;
if(processor->canHandle(peersEntry)) {
Peers tempPeers = processor->extractPeer(peersEntry);
copy(tempPeers.begin(), tempPeers.end(), back_inserter(peers));
std::copy(tempPeers.begin(), tempPeers.end(), std::back_inserter(peers));
break;
}
}

View File

@ -50,6 +50,7 @@
#include "AutoSaveCommand.h"
#include "HaveEraseCommand.h"
#include "DownloadResult.h"
#include <algorithm>
namespace aria2 {
@ -63,9 +64,9 @@ DownloadEngineFactory::newDownloadEngine(Option* op,
RequestGroups workingSet;
RequestGroups reservedSet;
if(op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS) < (int32_t)requestGroups.size()) {
copy(requestGroups.begin(), requestGroups.begin()+op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS), back_inserter(workingSet));
copy(requestGroups.begin()+op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS),
requestGroups.end(), back_inserter(reservedSet));
std::copy(requestGroups.begin(), requestGroups.begin()+op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS), std::back_inserter(workingSet));
std::copy(requestGroups.begin()+op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS),
requestGroups.end(), std::back_inserter(reservedSet));
} else {
workingSet = requestGroups;
}

View File

@ -175,7 +175,7 @@ std::deque<SharedHandle<FileEntry> >
MetalinkEntry::toFileEntry(const std::deque<SharedHandle<MetalinkEntry> >& metalinkEntries)
{
std::deque<SharedHandle<FileEntry> > entries;
std::transform(metalinkEntries.begin(), metalinkEntries.end(), back_inserter(entries),
std::transform(metalinkEntries.begin(), metalinkEntries.end(), std::back_inserter(entries),
mem_fun_sh(&MetalinkEntry::getFile));
return entries;
}

View File

@ -366,7 +366,7 @@ void MetalinkParserController::commitChunkChecksumTransaction()
std::sort(_tempChunkChecksums.begin(), _tempChunkChecksums.end(), Ascend1st<std::pair<int32_t, std::string> >());
std::deque<std::string> checksums;
std::transform(_tempChunkChecksums.begin(), _tempChunkChecksums.end(),
back_inserter(checksums), select2nd<std::pair<int32_t, std::string> >());
std::back_inserter(checksums), select2nd<std::pair<int32_t, std::string> >());
_tChunkChecksum->setChecksums(checksums);
_tEntry->chunkChecksum = _tChunkChecksum;
}

View File

@ -443,7 +443,7 @@ Commands RequestGroup::createNextCommand(DownloadEngine* e, int32_t numCommand,
_logger->error(MSG_UNRECOGNIZED_URI, req->getUrl().c_str());
}
}
copy(pendingURIs.begin(), pendingURIs.end(), front_inserter(_uris));
std::copy(pendingURIs.begin(), pendingURIs.end(), std::front_inserter(_uris));
return commands;
}

View File

@ -45,6 +45,7 @@
#include <iomanip>
#include <sstream>
#include <numeric>
#include <algorithm>
namespace aria2 {
@ -119,7 +120,7 @@ void RequestGroupMan::removeStoppedGroup()
RequestGroups nextGroups = (*itr)->postDownloadProcessing();
if(nextGroups.size() > 0) {
_logger->debug("Adding %d RequestGroups as a result of PostDownloadHandler.", (int32_t)nextGroups.size());
copy(nextGroups.rbegin(), nextGroups.rend(), front_inserter(_reservedGroups));
std::copy(nextGroups.rbegin(), nextGroups.rend(), std::front_inserter(_reservedGroups));
}
} else {
(*itr)->getProgressInfoFile()->save();
@ -163,7 +164,7 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
_downloadResults.push_back(groupToAdd->createDownloadResult());
}
}
copy(temp.begin(), temp.end(), front_inserter(_reservedGroups));
std::copy(temp.begin(), temp.end(), std::front_inserter(_reservedGroups));
if(count > 0) {
_logger->debug("%d RequestGroup(s) added.", count);
}
@ -177,7 +178,7 @@ Commands RequestGroupMan::getInitialCommands(DownloadEngine* e)
try {
if((*itr)->isDependencyResolved()) {
Commands nextCommands = (*itr)->createInitialCommand(e);
copy(nextCommands.begin(), nextCommands.end(), back_inserter(commands));
std::copy(nextCommands.begin(), nextCommands.end(), std::back_inserter(commands));
++itr;
} else {
_reservedGroups.push_front((*itr));

View File

@ -40,6 +40,7 @@
#include "prefs.h"
#include "RequestGroup.h"
#include "InitiateConnectionCommandFactory.h"
#include <algorithm>
namespace aria2 {
@ -59,7 +60,7 @@ Commands StreamFileAllocationEntry::prepareForNextAction(DownloadEngine* e)
commands.push_back(popNextCommand());
// try remaining uris
Commands streamCommands = _requestGroup->createNextCommandWithAdj(e, -1);
copy(streamCommands.begin(), streamCommands.end(), back_inserter(commands));
std::copy(streamCommands.begin(), streamCommands.end(), std::back_inserter(commands));
} else {
if(_currentRequest.isNull()) {
commands = _requestGroup->createNextCommandWithAdj(e, 0);
@ -69,7 +70,7 @@ Commands StreamFileAllocationEntry::prepareForNextAction(DownloadEngine* e)
_currentRequest, _requestGroup, e);
commands.push_back(command);
copy(streamCommands.begin(), streamCommands.end(), back_inserter(commands));
std::copy(streamCommands.begin(), streamCommands.end(), std::back_inserter(commands));
}
}
return commands;

View File

@ -35,6 +35,8 @@
#ifndef _D_A2_ALGO_H_
#define _D_A2_ALGO_H_
#include <algorithm>
namespace aria2 {
template<typename InputIterator, typename OutputIterator>
@ -43,7 +45,7 @@ OutputIterator ncopy(InputIterator first, InputIterator last,
{
OutputIterator x = destination;
for(int32_t i = 0; i < count; ++i) {
x = copy(first, last, destination);
x = std::copy(first, last, destination);
}
return x;
}

View File

@ -127,7 +127,7 @@ void downloadBitTorrent(Option* op, const std::deque<std::string>& uri)
}
std::deque<std::string> xargs;
ncopy(nargs.begin(), nargs.end(), op->getAsInt(PREF_SPLIT),
back_inserter(xargs));
std::back_inserter(xargs));
RequestGroupHandle rg = new RequestGroup(op, xargs);
DefaultBtContextHandle btContext = new DefaultBtContext();
@ -167,14 +167,14 @@ void downloadUriList(Option* op, std::istream& in)
for(std::deque<std::string>::const_iterator itr = unfoldedURIs.begin();
itr != unfoldedURIs.end(); ++itr) {
std::deque<std::string> xuris;
ncopy(itr, itr+1, op->getAsInt(PREF_SPLIT), back_inserter(xuris));
ncopy(itr, itr+1, op->getAsInt(PREF_SPLIT), std::back_inserter(xuris));
SharedHandle<RequestGroup> rg = createRequestGroup(op, xuris);
groups.push_back(rg);
}
} else if(uris.size() > 0) {
std::deque<std::string> xuris;
ncopy(uris.begin(), uris.end(), op->getAsInt(PREF_SPLIT),
back_inserter(xuris));
std::back_inserter(xuris));
SharedHandle<RequestGroup> rg = createRequestGroup(op, xuris);
groups.push_back(rg);
}
@ -209,14 +209,14 @@ void downloadUri(Option* op, const std::deque<std::string>& uris)
itr != nargs.end(); ++itr) {
std::deque<std::string> xuris;
ncopy(itr, itr+1, op->getAsInt(PREF_SPLIT),
back_inserter(xuris));
std::back_inserter(xuris));
RequestGroupHandle rg = createRequestGroup(op, xuris);
groups.push_back(rg);
}
} else {
std::deque<std::string> xargs;
ncopy(nargs.begin(), nargs.end(), op->getAsInt(PREF_SPLIT),
back_inserter(xargs));
std::back_inserter(xargs));
RequestGroupHandle rg = createRequestGroup(op, xargs, op->get(PREF_OUT));
groups.push_back(rg);
}

View File

@ -46,6 +46,7 @@
#include "prefs.h"
#include <iostream>
#include <iterator>
#include <algorithm>
namespace aria2 {

View File

@ -1,53 +0,0 @@
#include "StreamUriListParser.h"
#include "Exception.h"
#include "Util.h"
#include <sstream>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <cppunit/extensions/HelperMacros.h>
using namespace std;
class StreamUriListParserTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(StreamUriListParserTest);
CPPUNIT_TEST(testHasNext);
CPPUNIT_TEST_SUITE_END();
private:
std::stringlist2String(const Strings& src);
public:
void setUp() {
}
void testHasNext();
};
CPPUNIT_TEST_SUITE_REGISTRATION( StreamUriListParserTest );
std::stringStreamUriListParserTest::list2String(const Strings& src)
{
ostringstream strm;
copy(src.begin(), src.end(), ostream_iterator<string>(strm, " "));
return Util::trim(strm.str());
}
void StreamUriListParserTest::testHasNext()
{
stringstream s;
s << "http://localhost/index.html http://localhost2/index.html\n"
<< "ftp://localhost/aria2.tar.bz2";
StreamUriListParser flp(s);
CPPUNIT_ASSERT(flp.hasNext());
CPPUNIT_ASSERT_EQUAL(std::string("http://localhost/index.html http://localhost2/index.html"), list2String(flp.next()));
CPPUNIT_ASSERT(flp.hasNext());
CPPUNIT_ASSERT_EQUAL(std::string("ftp://localhost/aria2.tar.bz2"),
list2String(flp.next()));
CPPUNIT_ASSERT(flp.hasNext());
CPPUNIT_ASSERT_EQUAL(std::string(""),
list2String(flp.next()));
CPPUNIT_ASSERT(!flp.hasNext());
}