mirror of https://github.com/aria2/aria2
Cleanup a2functional.h
Remove mem_fun_sh in favor of std::mem_fun. Remove unused functions. Use std::mem_fn instead of mem_fun_shpull/103/head
parent
50dcd6394c
commit
e791eb9ca3
|
@ -222,7 +222,8 @@ void DHTBucket::getGoodNodes
|
||||||
{
|
{
|
||||||
goodNodes.insert(goodNodes.end(), nodes_.begin(), nodes_.end());
|
goodNodes.insert(goodNodes.end(), nodes_.begin(), nodes_.end());
|
||||||
goodNodes.erase(std::remove_if(goodNodes.begin(), goodNodes.end(),
|
goodNodes.erase(std::remove_if(goodNodes.begin(), goodNodes.end(),
|
||||||
mem_fun_sh(&DHTNode::isBad)), goodNodes.end());
|
std::mem_fn(&DHTNode::isBad)),
|
||||||
|
goodNodes.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<DHTNode> DHTBucket::getNode(const unsigned char* nodeID, const std::string& ipaddr, uint16_t port) const
|
std::shared_ptr<DHTNode> DHTBucket::getNode(const unsigned char* nodeID, const std::string& ipaddr, uint16_t port) const
|
||||||
|
|
|
@ -53,7 +53,7 @@ DHTTaskExecutor::~DHTTaskExecutor() {}
|
||||||
void DHTTaskExecutor::update()
|
void DHTTaskExecutor::update()
|
||||||
{
|
{
|
||||||
execTasks_.erase(std::remove_if(execTasks_.begin(), execTasks_.end(),
|
execTasks_.erase(std::remove_if(execTasks_.begin(), execTasks_.end(),
|
||||||
mem_fun_sh(&DHTTask::finished)),
|
std::mem_fn(&DHTTask::finished)),
|
||||||
execTasks_.end());
|
execTasks_.end());
|
||||||
int r;
|
int r;
|
||||||
if(static_cast<size_t>(numConcurrent_) > execTasks_.size()) {
|
if(static_cast<size_t>(numConcurrent_) > execTasks_.size()) {
|
||||||
|
|
|
@ -408,7 +408,7 @@ void DefaultBtMessageDispatcher::addOutstandingRequest
|
||||||
size_t DefaultBtMessageDispatcher::countOutstandingUpload()
|
size_t DefaultBtMessageDispatcher::countOutstandingUpload()
|
||||||
{
|
{
|
||||||
return std::count_if(messageQueue_.begin(), messageQueue_.end(),
|
return std::count_if(messageQueue_.begin(), messageQueue_.end(),
|
||||||
mem_fun_sh(&BtMessage::isUploading));
|
std::mem_fn(&BtMessage::isUploading));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtMessageDispatcher::setPeer(const std::shared_ptr<Peer>& peer)
|
void DefaultBtMessageDispatcher::setPeer(const std::shared_ptr<Peer>& peer)
|
||||||
|
|
|
@ -86,7 +86,7 @@ void DefaultBtRequestFactory::removeCompletedPiece() {
|
||||||
std::for_each(pieces_.begin(), pieces_.end(),
|
std::for_each(pieces_.begin(), pieces_.end(),
|
||||||
AbortCompletedPieceRequest(dispatcher_));
|
AbortCompletedPieceRequest(dispatcher_));
|
||||||
pieces_.erase(std::remove_if(pieces_.begin(), pieces_.end(),
|
pieces_.erase(std::remove_if(pieces_.begin(), pieces_.end(),
|
||||||
mem_fun_sh(&Piece::pieceComplete)),
|
std::mem_fn(&Piece::pieceComplete)),
|
||||||
pieces_.end());
|
pieces_.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ void DefaultBtRequestFactory::getTargetPieceIndexes
|
||||||
(std::vector<size_t>& indexes) const
|
(std::vector<size_t>& indexes) const
|
||||||
{
|
{
|
||||||
std::transform(pieces_.begin(), pieces_.end(), std::back_inserter(indexes),
|
std::transform(pieces_.begin(), pieces_.end(), std::back_inserter(indexes),
|
||||||
mem_fun_sh(&Piece::getIndex));
|
std::mem_fn(&Piece::getIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtRequestFactory::setPieceStorage
|
void DefaultBtRequestFactory::setPieceStorage
|
||||||
|
|
|
@ -125,9 +125,11 @@ void DownloadContext::setFilePathWithIndex
|
||||||
|
|
||||||
void DownloadContext::setFileFilter(SegList<int>& sgl)
|
void DownloadContext::setFileFilter(SegList<int>& sgl)
|
||||||
{
|
{
|
||||||
|
using namespace std::placeholders;
|
||||||
|
|
||||||
if(!sgl.hasNext() || fileEntries_.size() == 1) {
|
if(!sgl.hasNext() || fileEntries_.size() == 1) {
|
||||||
std::for_each(fileEntries_.begin(), fileEntries_.end(),
|
std::for_each(fileEntries_.begin(), fileEntries_.end(),
|
||||||
std::bind2nd(mem_fun_sh(&FileEntry::setRequested), true));
|
std::bind(&FileEntry::setRequested, _1, true));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert(sgl.peek() >= 1);
|
assert(sgl.peek() >= 1);
|
||||||
|
|
|
@ -201,7 +201,7 @@ Metalink2RequestGroup::createRequestGroup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::for_each(selectedEntries.begin(), selectedEntries.end(),
|
std::for_each(selectedEntries.begin(), selectedEntries.end(),
|
||||||
mem_fun_sh(&MetalinkEntry::reorderMetaurlsByPriority));
|
std::mem_fn(&MetalinkEntry::reorderMetaurlsByPriority));
|
||||||
std::vector<std::pair<std::string,
|
std::vector<std::pair<std::string,
|
||||||
std::vector<std::shared_ptr<MetalinkEntry> > > > entryGroups;
|
std::vector<std::shared_ptr<MetalinkEntry> > > > entryGroups;
|
||||||
metalink::groupEntryByMetaurlName(entryGroups, selectedEntries);
|
metalink::groupEntryByMetaurlName(entryGroups, selectedEntries);
|
||||||
|
|
|
@ -196,7 +196,7 @@ void MetalinkEntry::toFileEntry
|
||||||
{
|
{
|
||||||
std::transform(metalinkEntries.begin(), metalinkEntries.end(),
|
std::transform(metalinkEntries.begin(), metalinkEntries.end(),
|
||||||
std::back_inserter(fileEntries),
|
std::back_inserter(fileEntries),
|
||||||
mem_fun_sh(&MetalinkEntry::getFile));
|
std::mem_fn(&MetalinkEntry::getFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetalinkEntry::setSignature(const std::shared_ptr<Signature>& signature)
|
void MetalinkEntry::setSignature(const std::shared_ptr<Signature>& signature)
|
||||||
|
|
|
@ -493,12 +493,12 @@ void MetalinkParserController::commitChunkChecksumTransaction()
|
||||||
if(!tEntry_->chunkChecksum ||
|
if(!tEntry_->chunkChecksum ||
|
||||||
MessageDigest::isStronger(tChunkChecksum_->getHashType(),
|
MessageDigest::isStronger(tChunkChecksum_->getHashType(),
|
||||||
tEntry_->chunkChecksum->getHashType())) {
|
tEntry_->chunkChecksum->getHashType())) {
|
||||||
std::sort(tempChunkChecksums_.begin(), tempChunkChecksums_.end(),
|
std::sort(tempChunkChecksums_.begin(), tempChunkChecksums_.end());
|
||||||
Ascend1st<std::pair<size_t, std::string> >());
|
|
||||||
std::vector<std::string> pieceHashes;
|
std::vector<std::string> pieceHashes;
|
||||||
std::transform(tempChunkChecksums_.begin(), tempChunkChecksums_.end(),
|
std::transform(tempChunkChecksums_.begin(), tempChunkChecksums_.end(),
|
||||||
std::back_inserter(pieceHashes),
|
std::back_inserter(pieceHashes),
|
||||||
select2nd<std::pair<size_t, std::string> >());
|
[](const std::pair<size_t, std::string>& p)
|
||||||
|
{ return p.second; });
|
||||||
tChunkChecksum_->setPieceHashes(pieceHashes);
|
tChunkChecksum_->setPieceHashes(pieceHashes);
|
||||||
tEntry_->chunkChecksum = tChunkChecksum_;
|
tEntry_->chunkChecksum = tChunkChecksum_;
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,7 +300,7 @@ void MultiDiskAdaptor::openExistingFile()
|
||||||
void MultiDiskAdaptor::closeFile()
|
void MultiDiskAdaptor::closeFile()
|
||||||
{
|
{
|
||||||
std::for_each(diskWriterEntries_.begin(), diskWriterEntries_.end(),
|
std::for_each(diskWriterEntries_.begin(), diskWriterEntries_.end(),
|
||||||
mem_fun_sh(&DiskWriterEntry::closeFile));
|
std::mem_fn(&DiskWriterEntry::closeFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -520,7 +520,7 @@ void MultiDiskAdaptor::writeCache(const WrDiskCacheEntry* entry)
|
||||||
bool MultiDiskAdaptor::fileExists()
|
bool MultiDiskAdaptor::fileExists()
|
||||||
{
|
{
|
||||||
return std::find_if(getFileEntries().begin(), getFileEntries().end(),
|
return std::find_if(getFileEntries().begin(), getFileEntries().end(),
|
||||||
mem_fun_sh(&FileEntry::exists)) !=
|
std::mem_fn(&FileEntry::exists)) !=
|
||||||
getFileEntries().end();
|
getFileEntries().end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -801,7 +801,7 @@ bool RequestGroupMan::isSameFileBeingDownloaded(RequestGroup* requestGroup) cons
|
||||||
rg->getDownloadContext()->getFileEntries();
|
rg->getDownloadContext()->getFileEntries();
|
||||||
std::transform(entries.begin(), entries.end(),
|
std::transform(entries.begin(), entries.end(),
|
||||||
std::back_inserter(files),
|
std::back_inserter(files),
|
||||||
mem_fun_sh(&FileEntry::getPath));
|
std::mem_fn(&FileEntry::getPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::sort(files.begin(), files.end());
|
std::sort(files.begin(), files.end());
|
||||||
|
|
|
@ -46,129 +46,6 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
// mem_fun_t for SharedHandle
|
|
||||||
template <class ReturnType, typename ClassType>
|
|
||||||
class mem_fun_sh_t:public std::unary_function< std::shared_ptr<ClassType>, ReturnType>
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
ReturnType (ClassType::*f)();
|
|
||||||
|
|
||||||
public:
|
|
||||||
mem_fun_sh_t(ReturnType (ClassType::*f)()):f(f) {}
|
|
||||||
|
|
||||||
ReturnType operator()(const std::shared_ptr<ClassType>& x) const
|
|
||||||
{
|
|
||||||
return (x.get()->*f)();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// const_mem_fun_t for SharedHandle
|
|
||||||
template <class ReturnType, typename ClassType>
|
|
||||||
class const_mem_fun_sh_t:public std::unary_function< std::shared_ptr<ClassType>, ReturnType>
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
ReturnType (ClassType::*f)() const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
const_mem_fun_sh_t(ReturnType (ClassType::*f)() const):f(f) {}
|
|
||||||
|
|
||||||
ReturnType operator()(const std::shared_ptr<ClassType>& x) const
|
|
||||||
{
|
|
||||||
return (x.get()->*f)();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class ReturnType, typename ClassType>
|
|
||||||
mem_fun_sh_t<ReturnType, ClassType>
|
|
||||||
mem_fun_sh(ReturnType (ClassType::*f)())
|
|
||||||
{
|
|
||||||
return mem_fun_sh_t<ReturnType, ClassType>(f);
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class ReturnType, typename ClassType>
|
|
||||||
const_mem_fun_sh_t<ReturnType, ClassType>
|
|
||||||
mem_fun_sh(ReturnType (ClassType::*f)() const)
|
|
||||||
{
|
|
||||||
return const_mem_fun_sh_t<ReturnType, ClassType>(f);
|
|
||||||
};
|
|
||||||
|
|
||||||
// mem_fun1_t for SharedHandle
|
|
||||||
template<typename ReturnType, typename ClassType, typename ArgType>
|
|
||||||
class mem_fun1_sh_t:public std::binary_function<std::shared_ptr<ClassType>,
|
|
||||||
ArgType,
|
|
||||||
ReturnType>
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
ReturnType (ClassType::*f)(ArgType);
|
|
||||||
|
|
||||||
public:
|
|
||||||
mem_fun1_sh_t(ReturnType (ClassType::*f)(ArgType)):f(f) {}
|
|
||||||
|
|
||||||
ReturnType operator()(const std::shared_ptr<ClassType>& x, ArgType a) const
|
|
||||||
{
|
|
||||||
return (x.get()->*f)(a);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename ReturnType, typename ClassType, typename ArgType>
|
|
||||||
mem_fun1_sh_t<ReturnType, ClassType, ArgType>
|
|
||||||
mem_fun_sh(ReturnType (ClassType::*f)(ArgType))
|
|
||||||
{
|
|
||||||
return mem_fun1_sh_t<ReturnType, ClassType, ArgType>(f);
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class BinaryOp, class UnaryOp>
|
|
||||||
class adopt2nd_t:public std::binary_function<typename BinaryOp::first_argument_type,
|
|
||||||
typename UnaryOp::argument_type,
|
|
||||||
typename BinaryOp::result_type> {
|
|
||||||
private:
|
|
||||||
BinaryOp binaryOp_;
|
|
||||||
UnaryOp unaryOp_;
|
|
||||||
public:
|
|
||||||
adopt2nd_t(const BinaryOp& b, const UnaryOp& u):
|
|
||||||
binaryOp_(b), unaryOp_(u) {}
|
|
||||||
|
|
||||||
typename BinaryOp::result_type
|
|
||||||
operator()(const typename BinaryOp::first_argument_type& x,
|
|
||||||
const typename UnaryOp::argument_type& y)
|
|
||||||
{
|
|
||||||
return binaryOp_(x, unaryOp_(y));
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class BinaryOp, class UnaryOp>
|
|
||||||
inline adopt2nd_t<BinaryOp, UnaryOp>
|
|
||||||
adopt2nd(const BinaryOp& binaryOp, const UnaryOp& unaryOp)
|
|
||||||
{
|
|
||||||
return adopt2nd_t<BinaryOp, UnaryOp>(binaryOp, unaryOp);
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Pair>
|
|
||||||
class Ascend1st:public std::binary_function<Pair, Pair, bool>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool operator()(const Pair& p1, const Pair& p2) const
|
|
||||||
{
|
|
||||||
return p1.first < p2.first;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Pair>
|
|
||||||
class select2nd
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typename Pair::second_type operator()(const Pair& p) const
|
|
||||||
{
|
|
||||||
return p.second;
|
|
||||||
}
|
|
||||||
|
|
||||||
typename Pair::second_type operator()(Pair& p) const
|
|
||||||
{
|
|
||||||
return p.second;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class Deleter {
|
class Deleter {
|
||||||
public:
|
public:
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|
|
@ -11,42 +11,13 @@ namespace aria2 {
|
||||||
class a2functionalTest:public CppUnit::TestFixture {
|
class a2functionalTest:public CppUnit::TestFixture {
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE(a2functionalTest);
|
CPPUNIT_TEST_SUITE(a2functionalTest);
|
||||||
CPPUNIT_TEST(testMemFunSh);
|
|
||||||
CPPUNIT_TEST(testAdopt2nd);
|
|
||||||
CPPUNIT_TEST(testStrjoin);
|
CPPUNIT_TEST(testStrjoin);
|
||||||
CPPUNIT_TEST(testLeastRecentAccess);
|
CPPUNIT_TEST(testLeastRecentAccess);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
public:
|
public:
|
||||||
void testMemFunSh();
|
|
||||||
void testAdopt2nd();
|
|
||||||
void testStrjoin();
|
void testStrjoin();
|
||||||
void testLeastRecentAccess();
|
void testLeastRecentAccess();
|
||||||
|
|
||||||
class Greeting {
|
|
||||||
public:
|
|
||||||
virtual ~Greeting() {}
|
|
||||||
|
|
||||||
virtual std::string sayGreeting() = 0;
|
|
||||||
|
|
||||||
virtual std::string sayGreetingConst() const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::shared_ptr<Greeting> GreetingHandle;
|
|
||||||
|
|
||||||
class JapaneseGreeting:public Greeting
|
|
||||||
{
|
|
||||||
virtual std::string sayGreeting()
|
|
||||||
{
|
|
||||||
return "HAROO WAARUDO";
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual std::string sayGreetingConst() const
|
|
||||||
{
|
|
||||||
return "HAROO WAARUDO";
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
struct LastAccess {
|
struct LastAccess {
|
||||||
time_t lastAccess_;
|
time_t lastAccess_;
|
||||||
LastAccess(time_t lastAccess):lastAccess_(lastAccess) {}
|
LastAccess(time_t lastAccess):lastAccess_(lastAccess) {}
|
||||||
|
@ -58,27 +29,8 @@ public:
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION(a2functionalTest);
|
CPPUNIT_TEST_SUITE_REGISTRATION(a2functionalTest);
|
||||||
|
|
||||||
void a2functionalTest::testMemFunSh()
|
|
||||||
{
|
|
||||||
GreetingHandle greeting(new JapaneseGreeting());
|
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("HAROO WAARUDO"), mem_fun_sh(&Greeting::sayGreeting)(greeting));
|
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("HAROO WAARUDO"), mem_fun_sh(&Greeting::sayGreetingConst)(greeting));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void a2functionalTest::testAdopt2nd()
|
|
||||||
{
|
|
||||||
GreetingHandle greeting(new JapaneseGreeting());
|
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("A Japanese said:HAROO WAARUDO"),
|
|
||||||
adopt2nd(std::plus<std::string>(), mem_fun_sh(&Greeting::sayGreeting))("A Japanese said:", greeting));
|
|
||||||
}
|
|
||||||
|
|
||||||
void a2functionalTest::testStrjoin()
|
void a2functionalTest::testStrjoin()
|
||||||
{
|
{
|
||||||
std::vector<std::string> v;
|
std::vector<std::string> v;
|
||||||
|
|
Loading…
Reference in New Issue