mirror of
https://github.com/transmission/transmission
synced 2024-12-21 23:32:35 +00:00
refactor: new tr_variant
API in transmission-remote
and other cleanup (#6798)
* refactor: remove `Arguments` * refactor: replace pointer args with lvalue reference * refactor: use `uint16_t` for port number * chore: housekeeping * refactor: replace `char*` with `std::string_view` * refactor: simplify argument parsing code * refactor: use new `tr_variant` API in remote * chore: rename function to snake_case * chore: move `break` statements in switches outside of compound statements * chore: use `std::string` literals * refactor: extract tor start/stop to `MODE_TORRENT_START_STOP` * refactor: extract tor actions to `MODE_TORRENT_ACTION` * chore: iwyu * fix: msvc build failure * chore: misc cleanup * fix: dereference optional * chore: misc cleanup * ui: fix minor formatting errors * fix: remove redundant if branches for response string * code review: remove `o` prefix for optionals * code review: add condition clause * code review: check `left_until_done` instead * fix: unchecked nullptr * code review: don't reassign method name * code review: revert accidentally renaming `addIdArg` to `get_id_arg` * code review: use `TR_ASSERT` instead of `assert` * refactor: fix static auto constexpr naming * code review: assert array size * code review: assert that `arguments` key exists
This commit is contained in:
parent
fea9a8efb7
commit
1e16912ae4
5 changed files with 1714 additions and 1659 deletions
|
@ -552,7 +552,7 @@ std::string tr_strpercent(double x)
|
|||
return fmt::format("{:.0Lf}", x);
|
||||
}
|
||||
|
||||
std::string tr_strratio(double ratio, char const* infinity)
|
||||
std::string tr_strratio(double ratio, std::string_view infinity)
|
||||
{
|
||||
if ((int)ratio == TR_RATIO_NA)
|
||||
{
|
||||
|
@ -561,7 +561,7 @@ std::string tr_strratio(double ratio, char const* infinity)
|
|||
|
||||
if ((int)ratio == TR_RATIO_INF)
|
||||
{
|
||||
return infinity != nullptr ? infinity : "";
|
||||
return std::string{ infinity };
|
||||
}
|
||||
|
||||
return tr_strpercent(ratio);
|
||||
|
|
|
@ -256,7 +256,7 @@ template<typename T, std::enable_if_t<std::is_floating_point_v<T>, bool> = true>
|
|||
|
||||
/** @param ratio the ratio to convert to a string
|
||||
@param infinity the string representation of "infinity" */
|
||||
[[nodiscard]] std::string tr_strratio(double ratio, char const* infinity);
|
||||
[[nodiscard]] std::string tr_strratio(double ratio, std::string_view infinity);
|
||||
|
||||
// ---
|
||||
|
||||
|
|
|
@ -76,8 +76,7 @@ template<typename T>
|
|||
|
||||
if (auto* const map = var != nullptr ? var->get_if<tr_variant::MapIndex>() : nullptr; map != nullptr)
|
||||
{
|
||||
map->erase(key);
|
||||
return &map->try_emplace(key, std::forward<T>(val)).first;
|
||||
return &map->insert_or_assign(key, std::forward<T>(val)).first;
|
||||
}
|
||||
|
||||
return {};
|
||||
|
|
|
@ -148,8 +148,26 @@ public:
|
|||
return { vec_.emplace_back(key, tr_variant{ std::forward<Val>(val) }).second, true };
|
||||
}
|
||||
|
||||
template<typename Val>
|
||||
std::pair<tr_variant&, bool> insert_or_assign(tr_quark const key, Val&& val)
|
||||
{
|
||||
auto res = try_emplace(key, std::forward<Val>(val));
|
||||
if (!res.second)
|
||||
{
|
||||
res.first = std::forward<Val>(val);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// --- custom functions
|
||||
|
||||
template<typename Type>
|
||||
[[nodiscard]] TR_CONSTEXPR20 auto find_if(tr_quark const key) noexcept
|
||||
{
|
||||
auto const iter = find(key);
|
||||
return iter != end() ? iter->second.get_if<Type>() : nullptr;
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
[[nodiscard]] TR_CONSTEXPR20 auto find_if(tr_quark const key) const noexcept
|
||||
{
|
||||
|
|
3346
utils/remote.cc
3346
utils/remote.cc
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue