From: Patrick Donnelly Date: Fri, 21 Mar 2025 16:57:25 +0000 (-0400) Subject: common/cmdparse: add another template cmd_getval_or helper X-Git-Tag: testing/wip-pdonnell-testing-20260210.212535~87 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=46d666d10cafce3d25c1adfa1a400f6452e8fa4c;p=ceph-ci.git common/cmdparse: add another template cmd_getval_or helper To mimic the conventional signature where you pass the lvalue you want to set. Signed-off-by: Patrick Donnelly --- diff --git a/src/common/cmdparse.h b/src/common/cmdparse.h index 3dd1c82a895..40d1e5af034 100644 --- a/src/common/cmdparse.h +++ b/src/common/cmdparse.h @@ -136,6 +136,23 @@ T cmd_getval_cast_or(const cmdmap_t& cmdmap, std::string_view k, T defval) } } +template +void cmd_getval_or(const cmdmap_t& cmdmap, std::string_view k, + V& val, const V& defval) +{ + auto found = cmdmap.find(k); + if (found == cmdmap.end()) { + val = T(defval); + } else { + try { + val = boost::get(cmdmap.find(k)->second); + } catch (boost::bad_get&) { + throw bad_cmd_get(k, cmdmap); + } + } +} + + template void cmd_putval(CephContext *cct, cmdmap_t& cmdmap, std::string_view k, const T& val)