diff --git a/ChangeLog b/ChangeLog index ff6c55db..4b4bc810 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2008-05-12 Tatsuhiro Tsujikawa + + Changed method signature: + BtRequestFactory::createRequestMessages, + BtRequestFactory::createRequestMessagesOnEndGame + * src/BtRequestFactory.h + * src/DefaultBtInteractive.cc + * src/DefaultBtRequestFactory.cc + * src/DefaultBtRequestFactory.h + * test/DefaultBtRequestFactoryTest.cc + * test/MockBtRequestFactory.h + 2008-05-11 Tatsuhiro Tsujikawa Changed method signature: diff --git a/src/BtRequestFactory.h b/src/BtRequestFactory.h index 6d823419..bba4cfc2 100644 --- a/src/BtRequestFactory.h +++ b/src/BtRequestFactory.h @@ -65,15 +65,15 @@ public: * addTargetPiece() and returns them. * The number of objects returned is capped by max. */ - virtual std::deque > - createRequestMessages(size_t max) = 0; + virtual void createRequestMessages + (std::deque >& requests, size_t max) = 0; /** * Use this method in end game mode. * */ - virtual std::deque > - createRequestMessagesOnEndGame(size_t max) = 0; + virtual void createRequestMessagesOnEndGame + (std::deque >& requests, size_t max) = 0; }; typedef SharedHandle BtRequestFactoryHandle; diff --git a/src/DefaultBtInteractive.cc b/src/DefaultBtInteractive.cc index 7e6d1c0a..6f6d7870 100644 --- a/src/DefaultBtInteractive.cc +++ b/src/DefaultBtInteractive.cc @@ -332,9 +332,9 @@ void DefaultBtInteractive::addRequests() { if(reqNumToCreate > 0) { BtMessages requests; if(pieceStorage->isEndGame()) { - requests = btRequestFactory->createRequestMessagesOnEndGame(reqNumToCreate); + btRequestFactory->createRequestMessagesOnEndGame(requests, reqNumToCreate); } else { - requests = btRequestFactory->createRequestMessages(reqNumToCreate); + btRequestFactory->createRequestMessages(requests, reqNumToCreate); } dispatcher->addMessageToQueue(requests); } diff --git a/src/DefaultBtRequestFactory.cc b/src/DefaultBtRequestFactory.cc index 22e13868..f9317917 100644 --- a/src/DefaultBtRequestFactory.cc +++ b/src/DefaultBtRequestFactory.cc @@ -105,9 +105,9 @@ void DefaultBtRequestFactory::removeAllTargetPiece() { pieces.clear(); } -BtMessages DefaultBtRequestFactory::createRequestMessages(size_t max) +void DefaultBtRequestFactory::createRequestMessages +(std::deque >& requests, size_t max) { - BtMessages requests; for(Pieces::iterator itr = pieces.begin(); itr != pieces.end() && requests.size() < max; itr++) { PieceHandle& piece = *itr; @@ -117,12 +117,11 @@ BtMessages DefaultBtRequestFactory::createRequestMessages(size_t max) requests.push_back(messageFactory->createRequestMessage(piece, blockIndex)); } } - return requests; } -BtMessages DefaultBtRequestFactory::createRequestMessagesOnEndGame(size_t max) +void DefaultBtRequestFactory::createRequestMessagesOnEndGame +(std::deque >& requests, size_t max) { - BtMessages requests; for(Pieces::iterator itr = pieces.begin(); itr != pieces.end() && requests.size() < max; itr++) { PieceHandle& piece = *itr; @@ -138,7 +137,6 @@ BtMessages DefaultBtRequestFactory::createRequestMessagesOnEndGame(size_t max) } } } - return requests; } std::deque >& DefaultBtRequestFactory::getTargetPieces() diff --git a/src/DefaultBtRequestFactory.h b/src/DefaultBtRequestFactory.h index 0c2976ae..9fb714f1 100644 --- a/src/DefaultBtRequestFactory.h +++ b/src/DefaultBtRequestFactory.h @@ -74,11 +74,11 @@ public: virtual void doChokedAction(); - virtual std::deque > - createRequestMessages(size_t max); + virtual void createRequestMessages + (std::deque >& requests, size_t max); - virtual std::deque > - createRequestMessagesOnEndGame(size_t max); + virtual void createRequestMessagesOnEndGame + (std::deque >& requests, size_t max); std::deque >& getTargetPieces(); diff --git a/test/DefaultBtRequestFactoryTest.cc b/test/DefaultBtRequestFactoryTest.cc index b725ee1e..3fae76c1 100644 --- a/test/DefaultBtRequestFactoryTest.cc +++ b/test/DefaultBtRequestFactoryTest.cc @@ -147,7 +147,8 @@ void DefaultBtRequestFactoryTest::testCreateRequestMessages() { btRequestFactory->addTargetPiece(piece1); btRequestFactory->addTargetPiece(piece2); - std::deque > msgs = btRequestFactory->createRequestMessages(3); + std::deque > msgs; + btRequestFactory->createRequestMessages(msgs, 3); CPPUNIT_ASSERT_EQUAL((size_t)3, msgs.size()); std::deque >::iterator itr = msgs.begin(); @@ -163,7 +164,11 @@ void DefaultBtRequestFactoryTest::testCreateRequestMessages() { CPPUNIT_ASSERT_EQUAL((size_t)1, msg->index); CPPUNIT_ASSERT_EQUAL((size_t)0, msg->blockIndex); - CPPUNIT_ASSERT_EQUAL((size_t)1, btRequestFactory->createRequestMessages(3).size()); + { + std::deque > msgs; + btRequestFactory->createRequestMessages(msgs, 3); + CPPUNIT_ASSERT_EQUAL((size_t)1, msgs.size()); + } } void DefaultBtRequestFactoryTest::testCreateRequestMessages_onEndGame() { @@ -178,7 +183,8 @@ void DefaultBtRequestFactoryTest::testCreateRequestMessages_onEndGame() { btRequestFactory->addTargetPiece(piece1); btRequestFactory->addTargetPiece(piece2); - std::deque > msgs = btRequestFactory->createRequestMessagesOnEndGame(3); + std::deque > msgs; + btRequestFactory->createRequestMessagesOnEndGame(msgs, 3); std::deque > mmsgs; for(std::deque >::iterator i = msgs.begin(); diff --git a/test/MockBtRequestFactory.h b/test/MockBtRequestFactory.h index 3a31a77f..5a9fa7ee 100644 --- a/test/MockBtRequestFactory.h +++ b/test/MockBtRequestFactory.h @@ -21,11 +21,11 @@ public: virtual void doChokedAction() {} - virtual std::deque > - createRequestMessages(size_t max) { return std::deque >(); } + virtual void createRequestMessages + (std::deque >& requests, size_t max) {} - virtual std::deque > - createRequestMessagesOnEndGame(size_t max) { return std::deque >(); } + virtual void createRequestMessagesOnEndGame + (std::deque >& requests, size_t max) {} }; } // namespace aria2