mirror of https://github.com/aria2/aria2
ParameterOptionHandler: Use initializer lists for params
parent
d1a17e5ef3
commit
09c597fbb8
|
@ -282,8 +282,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
|
|||
(PREF_DOWNLOAD_RESULT,
|
||||
TEXT_DOWNLOAD_RESULT,
|
||||
A2_V_DEFAULT,
|
||||
A2_V_DEFAULT,
|
||||
A2_V_FULL));
|
||||
{ A2_V_DEFAULT, A2_V_FULL}));
|
||||
op->addTag(TAG_ADVANCED);
|
||||
op->setChangeGlobalOption(true);
|
||||
handlers.push_back(op);
|
||||
|
@ -328,24 +327,6 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
|
|||
handlers.push_back(op);
|
||||
}
|
||||
{
|
||||
std::string params[] = {
|
||||
#ifdef HAVE_EPOLL
|
||||
V_EPOLL,
|
||||
#endif // HAVE_EPOLL
|
||||
#ifdef HAVE_KQUEUE
|
||||
V_KQUEUE,
|
||||
#endif // HAVE_KQUEUE
|
||||
#ifdef HAVE_PORT_ASSOCIATE
|
||||
V_PORT,
|
||||
#endif // HAVE_PORT_ASSOCIATE
|
||||
#ifdef HAVE_LIBUV
|
||||
V_LIBUV,
|
||||
#endif // HAVE_LIBUV
|
||||
#ifdef HAVE_POLL
|
||||
V_POLL,
|
||||
#endif // HAVE_POLL
|
||||
V_SELECT
|
||||
};
|
||||
OptionHandler* op(new ParameterOptionHandler
|
||||
(PREF_EVENT_POLL,
|
||||
TEXT_EVENT_POLL,
|
||||
|
@ -362,23 +343,37 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
|
|||
#else // defined(HAVE_EPOLL)
|
||||
V_SELECT,
|
||||
#endif // defined(HAVE_EPOLL)
|
||||
std::vector<std::string>
|
||||
(vbegin(params), vend(params))));
|
||||
{
|
||||
#ifdef HAVE_EPOLL
|
||||
V_EPOLL,
|
||||
#endif // HAVE_EPOLL
|
||||
#ifdef HAVE_KQUEUE
|
||||
V_KQUEUE,
|
||||
#endif // HAVE_KQUEUE
|
||||
#ifdef HAVE_PORT_ASSOCIATE
|
||||
V_PORT,
|
||||
#endif // HAVE_PORT_ASSOCIATE
|
||||
#ifdef HAVE_LIBUV
|
||||
V_LIBUV,
|
||||
#endif // HAVE_LIBUV
|
||||
#ifdef HAVE_POLL
|
||||
V_POLL,
|
||||
#endif // HAVE_POLL
|
||||
V_SELECT
|
||||
}));
|
||||
op->addTag(TAG_ADVANCED);
|
||||
handlers.push_back(op);
|
||||
}
|
||||
{
|
||||
const std::string params[] = { V_NONE, V_PREALLOC, V_TRUNC,
|
||||
#ifdef HAVE_SOME_FALLOCATE
|
||||
V_FALLOC
|
||||
#endif // HAVE_SOME_FALLOCATE
|
||||
};
|
||||
OptionHandler* op(new ParameterOptionHandler
|
||||
(PREF_FILE_ALLOCATION,
|
||||
TEXT_FILE_ALLOCATION,
|
||||
V_PREALLOC,
|
||||
std::vector<std::string>
|
||||
(vbegin(params), vend(params)),
|
||||
{ V_NONE, V_PREALLOC, V_TRUNC,
|
||||
#ifdef HAVE_SOME_FALLOCATE
|
||||
V_FALLOC
|
||||
#endif // HAVE_SOME_FALLOCATE
|
||||
},
|
||||
'a'));
|
||||
op->addTag(TAG_BASIC);
|
||||
op->addTag(TAG_FILE);
|
||||
|
@ -1107,9 +1102,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
|
|||
(PREF_STREAM_PIECE_SELECTOR,
|
||||
TEXT_STREAM_PIECE_SELECTOR,
|
||||
A2_V_DEFAULT,
|
||||
A2_V_DEFAULT,
|
||||
V_INORDER,
|
||||
A2_V_GEOM));
|
||||
{ A2_V_DEFAULT, V_INORDER, A2_V_GEOM }));
|
||||
op->addTag(TAG_FTP);
|
||||
op->addTag(TAG_HTTP);
|
||||
op->setInitialOption(true);
|
||||
|
@ -1132,13 +1125,11 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
|
|||
handlers.push_back(op);
|
||||
}
|
||||
{
|
||||
const std::string params[] = { V_INORDER, V_FEEDBACK, V_ADAPTIVE };
|
||||
OptionHandler* op(new ParameterOptionHandler
|
||||
(PREF_URI_SELECTOR,
|
||||
TEXT_URI_SELECTOR,
|
||||
V_FEEDBACK,
|
||||
std::vector<std::string>
|
||||
(vbegin(params), vend(params))));
|
||||
{ V_INORDER, V_FEEDBACK, V_ADAPTIVE }));
|
||||
op->addTag(TAG_FTP);
|
||||
op->addTag(TAG_HTTP);
|
||||
op->setInitialOption(true);
|
||||
|
@ -1404,7 +1395,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
|
|||
(PREF_FTP_TYPE,
|
||||
TEXT_FTP_TYPE,
|
||||
V_BINARY,
|
||||
V_BINARY, V_ASCII));
|
||||
{ V_BINARY, V_ASCII }));
|
||||
op->addTag(TAG_FTP);
|
||||
op->setInitialOption(true);
|
||||
op->setChangeGlobalOption(true);
|
||||
|
@ -1601,7 +1592,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
|
|||
(PREF_PROXY_METHOD,
|
||||
TEXT_PROXY_METHOD,
|
||||
V_GET,
|
||||
V_GET, V_TUNNEL));
|
||||
{ V_GET, V_TUNNEL }));
|
||||
op->addTag(TAG_FTP);
|
||||
op->addTag(TAG_HTTP);
|
||||
op->setInitialOption(true);
|
||||
|
@ -1750,7 +1741,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
|
|||
(PREF_BT_MIN_CRYPTO_LEVEL,
|
||||
TEXT_BT_MIN_CRYPTO_LEVEL,
|
||||
V_PLAIN,
|
||||
V_PLAIN, V_ARC4));
|
||||
{ V_PLAIN, V_ARC4 }));
|
||||
op->addTag(TAG_BITTORRENT);
|
||||
op->setInitialOption(true);
|
||||
op->setChangeGlobalOption(true);
|
||||
|
@ -2020,7 +2011,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
|
|||
(PREF_FOLLOW_TORRENT,
|
||||
TEXT_FOLLOW_TORRENT,
|
||||
A2_V_TRUE,
|
||||
A2_V_TRUE, V_MEM, A2_V_FALSE));
|
||||
{ A2_V_TRUE, V_MEM, A2_V_FALSE }));
|
||||
op->addTag(TAG_BITTORRENT);
|
||||
op->setInitialOption(true);
|
||||
op->setChangeGlobalOption(true);
|
||||
|
@ -2148,7 +2139,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
|
|||
(PREF_FOLLOW_METALINK,
|
||||
TEXT_FOLLOW_METALINK,
|
||||
A2_V_TRUE,
|
||||
A2_V_TRUE, V_MEM, A2_V_FALSE));
|
||||
{ A2_V_TRUE, V_MEM, A2_V_FALSE }));
|
||||
op->addTag(TAG_METALINK);
|
||||
op->setInitialOption(true);
|
||||
op->setChangeGlobalOption(true);
|
||||
|
@ -2209,13 +2200,11 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
|
|||
handlers.push_back(op);
|
||||
}
|
||||
{
|
||||
const std::string params[] = { V_HTTP, V_HTTPS, V_FTP, V_NONE };
|
||||
OptionHandler* op(new ParameterOptionHandler
|
||||
(PREF_METALINK_PREFERRED_PROTOCOL,
|
||||
TEXT_METALINK_PREFERRED_PROTOCOL,
|
||||
V_NONE,
|
||||
std::vector<std::string>
|
||||
(vbegin(params), vend(params))));
|
||||
{ V_HTTP, V_HTTPS, V_FTP, V_NONE }));
|
||||
op->addTag(TAG_METALINK);
|
||||
op->setInitialOption(true);
|
||||
op->setChangeGlobalOption(true);
|
||||
|
|
|
@ -394,55 +394,13 @@ ParameterOptionHandler::ParameterOptionHandler
|
|||
(const Pref* pref,
|
||||
const char* description,
|
||||
const std::string& defaultValue,
|
||||
const std::vector<std::string>& validParamValues,
|
||||
std::vector<std::string>&& validParamValues,
|
||||
char shortName)
|
||||
: AbstractOptionHandler(pref, description, defaultValue,
|
||||
OptionHandler::REQ_ARG, shortName),
|
||||
validParamValues_(validParamValues)
|
||||
validParamValues_(std::move(validParamValues))
|
||||
{}
|
||||
|
||||
ParameterOptionHandler::ParameterOptionHandler
|
||||
(const Pref* pref,
|
||||
const char* description,
|
||||
const std::string& defaultValue,
|
||||
const std::string& validParamValue,
|
||||
char shortName)
|
||||
: AbstractOptionHandler(pref, description, defaultValue,
|
||||
OptionHandler::REQ_ARG, shortName)
|
||||
{
|
||||
validParamValues_.push_back(validParamValue);
|
||||
}
|
||||
|
||||
ParameterOptionHandler::ParameterOptionHandler
|
||||
(const Pref* pref,
|
||||
const char* description,
|
||||
const std::string& defaultValue,
|
||||
const std::string& validParamValue1,
|
||||
const std::string& validParamValue2,
|
||||
char shortName)
|
||||
: AbstractOptionHandler(pref, description, defaultValue,
|
||||
OptionHandler::REQ_ARG, shortName)
|
||||
{
|
||||
validParamValues_.push_back(validParamValue1);
|
||||
validParamValues_.push_back(validParamValue2);
|
||||
}
|
||||
|
||||
ParameterOptionHandler::ParameterOptionHandler
|
||||
(const Pref* pref,
|
||||
const char* description,
|
||||
const std::string& defaultValue,
|
||||
const std::string& validParamValue1,
|
||||
const std::string& validParamValue2,
|
||||
const std::string& validParamValue3,
|
||||
char shortName)
|
||||
: AbstractOptionHandler(pref, description, defaultValue,
|
||||
OptionHandler::REQ_ARG, shortName)
|
||||
{
|
||||
validParamValues_.push_back(validParamValue1);
|
||||
validParamValues_.push_back(validParamValue2);
|
||||
validParamValues_.push_back(validParamValue3);
|
||||
}
|
||||
|
||||
ParameterOptionHandler::~ParameterOptionHandler() {}
|
||||
|
||||
void ParameterOptionHandler::parseArg(Option& option, const std::string& optarg)
|
||||
|
|
|
@ -181,25 +181,7 @@ public:
|
|||
ParameterOptionHandler(const Pref* pref,
|
||||
const char* description,
|
||||
const std::string& defaultValue,
|
||||
const std::vector<std::string>& validParamValues,
|
||||
char shortName = 0);
|
||||
ParameterOptionHandler(const Pref* pref,
|
||||
const char* description,
|
||||
const std::string& defaultValue,
|
||||
const std::string& validParamValue,
|
||||
char shortName = 0);
|
||||
ParameterOptionHandler(const Pref* pref,
|
||||
const char* description,
|
||||
const std::string& defaultValue,
|
||||
const std::string& validParamValue1,
|
||||
const std::string& validParamValue2,
|
||||
char shortName = 0);
|
||||
ParameterOptionHandler(const Pref* pref,
|
||||
const char* description,
|
||||
const std::string& defaultValue,
|
||||
const std::string& validParamValue1,
|
||||
const std::string& validParamValue2,
|
||||
const std::string& validParamValue3,
|
||||
std::vector<std::string>&& validParamValues,
|
||||
char shortName = 0);
|
||||
virtual ~ParameterOptionHandler();
|
||||
virtual void parseArg(Option& option, const std::string& optarg) const;
|
||||
|
|
|
@ -18,9 +18,7 @@ class OptionHandlerTest:public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST(testNumberOptionHandler_max);
|
||||
CPPUNIT_TEST(testNumberOptionHandler_min_max);
|
||||
CPPUNIT_TEST(testUnitNumberOptionHandler);
|
||||
CPPUNIT_TEST(testParameterOptionHandler_1argInit);
|
||||
CPPUNIT_TEST(testParameterOptionHandler_2argsInit);
|
||||
CPPUNIT_TEST(testParameterOptionHandler_listInit);
|
||||
CPPUNIT_TEST(testParameterOptionHandler);
|
||||
CPPUNIT_TEST(testDefaultOptionHandler);
|
||||
CPPUNIT_TEST(testFloatNumberOptionHandler);
|
||||
CPPUNIT_TEST(testFloatNumberOptionHandler_min);
|
||||
|
@ -37,9 +35,7 @@ public:
|
|||
void testNumberOptionHandler_max();
|
||||
void testNumberOptionHandler_min_max();
|
||||
void testUnitNumberOptionHandler();
|
||||
void testParameterOptionHandler_1argInit();
|
||||
void testParameterOptionHandler_2argsInit();
|
||||
void testParameterOptionHandler_listInit();
|
||||
void testParameterOptionHandler();
|
||||
void testDefaultOptionHandler();
|
||||
void testFloatNumberOptionHandler();
|
||||
void testFloatNumberOptionHandler_min();
|
||||
|
@ -148,43 +144,9 @@ void OptionHandlerTest::testUnitNumberOptionHandler()
|
|||
} catch(Exception& e) {}
|
||||
}
|
||||
|
||||
void OptionHandlerTest::testParameterOptionHandler_1argInit()
|
||||
void OptionHandlerTest::testParameterOptionHandler()
|
||||
{
|
||||
ParameterOptionHandler handler(PREF_TIMEOUT, "", "", "value1");
|
||||
Option option;
|
||||
handler.parse(option, "value1");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("value1"), option.get(PREF_TIMEOUT));
|
||||
try {
|
||||
handler.parse(option, "value3");
|
||||
CPPUNIT_FAIL("exception must be thrown.");
|
||||
} catch(Exception& e) {}
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("value1"),
|
||||
handler.createPossibleValuesString());
|
||||
}
|
||||
|
||||
void OptionHandlerTest::testParameterOptionHandler_2argsInit()
|
||||
{
|
||||
ParameterOptionHandler handler(PREF_TIMEOUT, "", "", "value1", "value2");
|
||||
Option option;
|
||||
handler.parse(option, "value1");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("value1"), option.get(PREF_TIMEOUT));
|
||||
handler.parse(option, "value2");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("value2"), option.get(PREF_TIMEOUT));
|
||||
try {
|
||||
handler.parse(option, "value3");
|
||||
CPPUNIT_FAIL("exception must be thrown.");
|
||||
} catch(Exception& e) {}
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("value1, value2"),
|
||||
handler.createPossibleValuesString());
|
||||
}
|
||||
|
||||
void OptionHandlerTest::testParameterOptionHandler_listInit()
|
||||
{
|
||||
std::vector<std::string> validValues;
|
||||
validValues.push_back("value1");
|
||||
validValues.push_back("value2");
|
||||
|
||||
ParameterOptionHandler handler(PREF_TIMEOUT, "", "", validValues);
|
||||
ParameterOptionHandler handler(PREF_TIMEOUT, "", "", {"value1", "value2"});
|
||||
Option option;
|
||||
handler.parse(option, "value1");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("value1"), option.get(PREF_TIMEOUT));
|
||||
|
|
Loading…
Reference in New Issue