From 4a455b5afe2679171ef38415f1b0f1d43f457e7e Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 30 Oct 2011 15:08:44 +0900 Subject: [PATCH] Removed IntSequence and Sequence --- src/IntSequence.h | 46 ------------------- src/Makefile.am | 2 - src/Sequence.h | 104 ------------------------------------------- src/util.cc | 28 ------------ src/util.h | 3 -- test/Makefile.am | 1 - test/SequenceTest.cc | 81 --------------------------------- test/UtilTest.cc | 62 -------------------------- 8 files changed, 327 deletions(-) delete mode 100644 src/IntSequence.h delete mode 100644 src/Sequence.h delete mode 100644 test/SequenceTest.cc diff --git a/src/IntSequence.h b/src/IntSequence.h deleted file mode 100644 index 5060da7d..00000000 --- a/src/IntSequence.h +++ /dev/null @@ -1,46 +0,0 @@ -/* */ -#ifndef D_INT_SEQUENCE_H -#define D_INT_SEQUENCE_H - -#include "Sequence.h" - -namespace aria2 { - -typedef Sequence IntSequence; - -} // namespace aria2 - -#endif // D_INT_SEQUENCE_H diff --git a/src/Makefile.am b/src/Makefile.am index fc431fb7..eb10b1e4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -149,8 +149,6 @@ SRCS = Socket.h\ CUIDCounter.cc CUIDCounter.h\ DNSCache.cc DNSCache.h\ DownloadResult.cc DownloadResult.h\ - Sequence.h\ - IntSequence.h\ PostDownloadHandler.h\ PreDownloadHandler.h\ SingletonHolder.h\ diff --git a/src/Sequence.h b/src/Sequence.h deleted file mode 100644 index 7652e017..00000000 --- a/src/Sequence.h +++ /dev/null @@ -1,104 +0,0 @@ -/* */ -#ifndef D_SEQUENCE_H -#define D_SEQUENCE_H - -#include - -namespace aria2 { - -template -class Sequence -{ -public: - // Generates value in [first_, last_). last_ is not included. - class Value { - private: - T first_; - T last_; - public: - Value(const T& first, const T& last):first_(first), last_(last) {} - - T next() - { - return first_++; - } - - bool hasNext() const - { - return first_ != last_; - } - }; - - typedef std::vector Values; -private: - Values values_; - typename Values::iterator cur_; -public: - Sequence(const Values& values): - values_(values), cur_(values_.begin()) {} - - Sequence():cur_(values_.end()) {} - - T next() - { - if(cur_ == values_.end()) { - return T(); - } - T t = (*cur_).next(); - if(!(*cur_).hasNext()) { - ++cur_; - } - return t; - } - - bool hasNext() - { - return cur_ != values_.end(); - } - - std::vector flush() - { - std::vector r; - while(hasNext()) { - r.push_back(next()); - } - return r; - } -}; - -} // namespace aria2 - -#endif // D_SEQUENCE_H diff --git a/src/util.cc b/src/util.cc index 9ab2d613..2878aed6 100644 --- a/src/util.cc +++ b/src/util.cc @@ -746,34 +746,6 @@ uint64_t parseULLInt(const std::string& s, int base) return v; } -IntSequence parseIntRange(const std::string& src) -{ - IntSequence::Values values; - std::string temp = src; - while(temp.size()) { - std::pair p; - divide(p, temp, ','); - temp = p.second; - if(p.first.empty()) { - continue; - } - if(p.first.find("-") == std::string::npos) { - int32_t v = parseInt(p.first.c_str()); - values.push_back(IntSequence::Value(v, v+1)); - } else { - std::pair vp; - divide(vp, p.first.c_str(), '-'); - if(vp.first.empty() || vp.second.empty()) { - throw DL_ABORT_EX(fmt(MSG_INCOMPLETE_RANGE, p.first.c_str())); - } - int32_t v1 = parseInt(vp.first.c_str()); - int32_t v2 = parseInt(vp.second.c_str()); - values.push_back(IntSequence::Value(v1, v2+1)); - } - } - return values; -} - void parseIntSegments(SegList& sgl, const std::string& src) { for(std::string::const_iterator i = src.begin(), eoi = src.end(); i != eoi;) { diff --git a/src/util.h b/src/util.h index c3aec6b2..e05d3006 100644 --- a/src/util.h +++ b/src/util.h @@ -51,7 +51,6 @@ #include #include "SharedHandle.h" -#include "IntSequence.h" #include "a2time.h" #include "a2netcompat.h" #include "a2functional.h" @@ -219,8 +218,6 @@ bool parseLLIntNoThrow(int64_t& result, const std::string& s, int base = 10); uint64_t parseULLInt(const std::string& s, int base = 10); -IntSequence parseIntRange(const std::string& src); - void parseIntSegments(SegList& sgl, const std::string& src); // Parses string which specifies the range of piece index for higher diff --git a/test/Makefile.am b/test/Makefile.am index f1621171..536e92e4 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -7,7 +7,6 @@ aria2c_SOURCES = AllTest.cc\ array_funTest.cc\ Base64Test.cc\ Base32Test.cc\ - SequenceTest.cc\ a2functionalTest.cc\ FileEntryTest.cc\ PieceTest.cc\ diff --git a/test/SequenceTest.cc b/test/SequenceTest.cc deleted file mode 100644 index 8e96a16b..00000000 --- a/test/SequenceTest.cc +++ /dev/null @@ -1,81 +0,0 @@ -#include "Sequence.h" -#include - -namespace aria2 { - -class SequenceTest:public CppUnit::TestFixture { - - CPPUNIT_TEST_SUITE(SequenceTest); - CPPUNIT_TEST(testParseAndNext); - CPPUNIT_TEST(testParseAndNext2); - CPPUNIT_TEST(testFlush); - CPPUNIT_TEST_SUITE_END(); -public: - void testParseAndNext(); - void testParseAndNext2(); - void testFlush(); -}; - - -CPPUNIT_TEST_SUITE_REGISTRATION(SequenceTest); - -typedef Sequence IntSequence; - -void SequenceTest::testParseAndNext() -{ - IntSequence::Value params[] = { - IntSequence::Value(1, 2), - IntSequence::Value(3, 9), - IntSequence::Value(10, 11), - }; - IntSequence seq = IntSequence(IntSequence::Values(¶ms[0], ¶ms[3])); - CPPUNIT_ASSERT(seq.hasNext()); - CPPUNIT_ASSERT_EQUAL(1, seq.next()); - CPPUNIT_ASSERT(seq.hasNext()); - CPPUNIT_ASSERT_EQUAL(3, seq.next()); - CPPUNIT_ASSERT(seq.hasNext()); - CPPUNIT_ASSERT_EQUAL(4, seq.next()); - CPPUNIT_ASSERT(seq.hasNext()); - CPPUNIT_ASSERT_EQUAL(5, seq.next()); - CPPUNIT_ASSERT(seq.hasNext()); - CPPUNIT_ASSERT_EQUAL(6, seq.next()); - CPPUNIT_ASSERT(seq.hasNext()); - CPPUNIT_ASSERT_EQUAL(7, seq.next()); - CPPUNIT_ASSERT(seq.hasNext()); - CPPUNIT_ASSERT_EQUAL(8, seq.next()); - CPPUNIT_ASSERT(seq.hasNext()); - CPPUNIT_ASSERT_EQUAL(10, seq.next()); - CPPUNIT_ASSERT(!seq.hasNext()); - CPPUNIT_ASSERT_EQUAL(0, seq.next()); - -} - -void SequenceTest::testParseAndNext2() -{ - IntSequence::Value params[] = { - IntSequence::Value(1, 2), - }; - IntSequence seq = IntSequence(IntSequence::Values(¶ms[0], ¶ms[1])); - CPPUNIT_ASSERT(seq.hasNext()); - CPPUNIT_ASSERT_EQUAL(1, seq.next()); - CPPUNIT_ASSERT(!seq.hasNext()); - CPPUNIT_ASSERT_EQUAL(0, seq.next()); - -} - -void SequenceTest::testFlush() -{ - IntSequence::Value params[] = { - IntSequence::Value(1, 2), - IntSequence::Value(3, 9), - IntSequence::Value(10, 11), - }; - IntSequence seq = IntSequence(IntSequence::Values(¶ms[0], ¶ms[3])); - std::vector r = seq.flush(); - - int answers[] = { 1, 3, 4, 5, 6, 7, 8, 10 }; - - CPPUNIT_ASSERT(std::equal(r.begin(), r.end(), &answers[0])); -} - -} // namespace aria2 diff --git a/test/UtilTest.cc b/test/UtilTest.cc index 8a4fec75..992bcd41 100644 --- a/test/UtilTest.cc +++ b/test/UtilTest.cc @@ -45,8 +45,6 @@ class UtilTest:public CppUnit::TestFixture { CPPUNIT_TEST(testAlphaToNum); CPPUNIT_TEST(testMkdirs); CPPUNIT_TEST(testConvertBitfield); - CPPUNIT_TEST(testParseIntRange); - CPPUNIT_TEST(testParseIntRange_invalidRange); CPPUNIT_TEST(testParseIntSegments); CPPUNIT_TEST(testParseIntSegments_invalidRange); CPPUNIT_TEST(testParseInt); @@ -107,8 +105,6 @@ public: void testAlphaToNum(); void testMkdirs(); void testConvertBitfield(); - void testParseIntRange(); - void testParseIntRange_invalidRange(); void testParseIntSegments(); void testParseIntSegments_invalidRange(); void testParseInt(); @@ -688,64 +684,6 @@ void UtilTest::testConvertBitfield() destBitfield.getBitfieldLength())); } -void UtilTest::testParseIntRange() -{ - IntSequence seq = util::parseIntRange("1,3-8,10"); - - CPPUNIT_ASSERT(seq.hasNext()); - CPPUNIT_ASSERT_EQUAL((int32_t)1, seq.next()); - CPPUNIT_ASSERT(seq.hasNext()); - CPPUNIT_ASSERT_EQUAL((int32_t)3, seq.next()); - CPPUNIT_ASSERT(seq.hasNext()); - CPPUNIT_ASSERT_EQUAL((int32_t)4, seq.next()); - CPPUNIT_ASSERT(seq.hasNext()); - CPPUNIT_ASSERT_EQUAL((int32_t)5, seq.next()); - CPPUNIT_ASSERT(seq.hasNext()); - CPPUNIT_ASSERT_EQUAL((int32_t)6, seq.next()); - CPPUNIT_ASSERT(seq.hasNext()); - CPPUNIT_ASSERT_EQUAL((int32_t)7, seq.next()); - CPPUNIT_ASSERT(seq.hasNext()); - CPPUNIT_ASSERT_EQUAL((int32_t)8, seq.next()); - CPPUNIT_ASSERT(seq.hasNext()); - CPPUNIT_ASSERT_EQUAL((int32_t)10, seq.next()); - CPPUNIT_ASSERT(!seq.hasNext()); - CPPUNIT_ASSERT_EQUAL((int32_t)0, seq.next()); -} - -void UtilTest::testParseIntRange_invalidRange() -{ - try { - IntSequence seq = util::parseIntRange("-1"); - CPPUNIT_FAIL("exception must be thrown."); - } catch(Exception& e) { - std::cerr << e.stackTrace(); - } - try { - IntSequence seq = util::parseIntRange("2147483648"); - CPPUNIT_FAIL("exception must be thrown."); - } catch(Exception& e) { - std::cerr << e.stackTrace(); - } - try { - IntSequence seq = util::parseIntRange("2147483647-2147483648"); - CPPUNIT_FAIL("exception must be thrown."); - } catch(Exception& e) { - std::cerr << e.stackTrace(); - } - try { - IntSequence seq = util::parseIntRange("1-2x"); - CPPUNIT_FAIL("exception must be thrown."); - } catch(Exception& e) { - std::cerr << e.stackTrace(); - } - try { - IntSequence seq = util::parseIntRange("3x-4"); - CPPUNIT_FAIL("exception must be thrown."); - } catch(Exception& e) { - std::cerr << e.stackTrace(); - } -} - void UtilTest::testParseIntSegments() { SegList sgl;