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-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0ec9c6f523bab9917d9f6c6f3076e8423f375a33;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 70c6045c3bb..94f5576ffbd 100644 --- a/src/common/cmdparse.h +++ b/src/common/cmdparse.h @@ -135,6 +135,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)