diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2013-06-22 23:19:54 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2013-06-22 23:19:54 +0900 |
| commit | 09c597fbb83fcd4fd958dae38ab0f2c7718da570 (patch) | |
| tree | d5558b3498e671afa20022c6e7b32a6f93680fb3 /src | |
| parent | d1a17e5ef3408a53627dfc3007c8ffde1540d418 (diff) | |
ParameterOptionHandler: Use initializer lists for params
Diffstat (limited to 'src')
| -rw-r--r-- | src/OptionHandlerFactory.cc | 75 | ||||
| -rw-r--r-- | src/OptionHandlerImpl.cc | 46 | ||||
| -rw-r--r-- | src/OptionHandlerImpl.h | 20 |
3 files changed, 35 insertions, 106 deletions
diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index 9e0e3cec..57b052d1 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -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); diff --git a/src/OptionHandlerImpl.cc b/src/OptionHandlerImpl.cc index 8efc62c8..6ac425ac 100644 --- a/src/OptionHandlerImpl.cc +++ b/src/OptionHandlerImpl.cc @@ -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) diff --git a/src/OptionHandlerImpl.h b/src/OptionHandlerImpl.h index e8b6d2cd..b2c5817f 100644 --- a/src/OptionHandlerImpl.h +++ b/src/OptionHandlerImpl.h @@ -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; |
