mirror of https://github.com/aria2/aria2
Removed IntSequence and Sequence<T>
parent
95586f594f
commit
4a455b5afe
|
@ -1,46 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef D_INT_SEQUENCE_H
|
||||
#define D_INT_SEQUENCE_H
|
||||
|
||||
#include "Sequence.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
typedef Sequence<int32_t> IntSequence;
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif // D_INT_SEQUENCE_H
|
|
@ -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\
|
||||
|
|
104
src/Sequence.h
104
src/Sequence.h
|
@ -1,104 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef D_SEQUENCE_H
|
||||
#define D_SEQUENCE_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
template<typename T>
|
||||
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<Value> 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<T> flush()
|
||||
{
|
||||
std::vector<T> r;
|
||||
while(hasNext()) {
|
||||
r.push_back(next());
|
||||
}
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif // D_SEQUENCE_H
|
28
src/util.cc
28
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<std::string, std::string> 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<std::string, std::string> 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<int>& sgl, const std::string& src)
|
||||
{
|
||||
for(std::string::const_iterator i = src.begin(), eoi = src.end(); i != eoi;) {
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
#include <vector>
|
||||
|
||||
#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<int>& sgl, const std::string& src);
|
||||
|
||||
// Parses string which specifies the range of piece index for higher
|
||||
|
|
|
@ -7,7 +7,6 @@ aria2c_SOURCES = AllTest.cc\
|
|||
array_funTest.cc\
|
||||
Base64Test.cc\
|
||||
Base32Test.cc\
|
||||
SequenceTest.cc\
|
||||
a2functionalTest.cc\
|
||||
FileEntryTest.cc\
|
||||
PieceTest.cc\
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
#include "Sequence.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
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<int> 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<int> 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
|
|
@ -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<int> sgl;
|
||||
|
|
Loading…
Reference in New Issue