diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2016-03-16 21:26:15 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2016-03-16 21:26:15 +0900 |
| commit | 1d9a4a8aec2483b112f4b8ec6d8f3d2f527c05ff (patch) | |
| tree | 42b368c158a1574202de9a28efa53e497b159c49 /src/OptionHandlerImpl.cc | |
| parent | f0f1b8ef47c391550ff99982f1cad3dd4e1d410d (diff) | |
| parent | 60d0cb0e24974534c10f63cf6833119b6af7be2b (diff) | |
Merge branch 'oliviercommelarbre-optimize-concurrent-downloads'
Diffstat (limited to 'src/OptionHandlerImpl.cc')
| -rw-r--r-- | src/OptionHandlerImpl.cc | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/OptionHandlerImpl.cc b/src/OptionHandlerImpl.cc index a01c111e..305493a2 100644 --- a/src/OptionHandlerImpl.cc +++ b/src/OptionHandlerImpl.cc @@ -586,6 +586,61 @@ std::string PrioritizePieceOptionHandler::createPossibleValuesString() const return "head[=SIZE], tail[=SIZE]"; } +OptimizeConcurrentDownloadsOptionHandler::OptimizeConcurrentDownloadsOptionHandler( + PrefPtr pref, const char* description, const std::string& defaultValue, char shortName) + : AbstractOptionHandler(pref, description, defaultValue, + OptionHandler::OPT_ARG, shortName) +{ +} + +void OptimizeConcurrentDownloadsOptionHandler::parseArg(Option& option, + const std::string& optarg) const +{ + if (optarg == "true" || optarg.empty()) { + option.put(pref_, A2_V_TRUE); + } + else if (optarg == "false") { + option.put(pref_, A2_V_FALSE); + } + else { + auto p = util::divide(std::begin(optarg), std::end(optarg), ':'); + + std::string coeff_b(p.second.first,p.second.second); + if(coeff_b.empty()) { + std::string msg = pref_->k; + msg += " "; + msg += _("must be either 'true', 'false' or a pair numeric coefficients A and B under the form 'A:B'."); + throw DL_ABORT_EX(msg); + } + + std::string coeff_a(p.first.first,p.first.second); + + + PrefPtr pref=PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFA; + std::string *sptr = &coeff_a; + for(;;) { + try { + double dbl = std::stod(*sptr); + } catch(std::invalid_argument & ex) { + throw DL_ABORT_EX(fmt("Bad number '%s'", sptr->c_str())); + } + option.put(pref,*sptr); + + if(pref == PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFB) { + break; + } + pref = PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFB; + sptr = &coeff_b; + } + option.put(pref_, A2_V_TRUE); + } +} + +std::string OptimizeConcurrentDownloadsOptionHandler::createPossibleValuesString() const +{ + return "true, false, A:B"; +} + DeprecatedOptionHandler::DeprecatedOptionHandler( OptionHandler* depOptHandler, const OptionHandler* repOptHandler, bool stillWork, std::string additionalMessage) |
