From 4561aff746ecc9e09b7a09284f98ae3ac76f5c27 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 3 Nov 2014 01:32:56 -0800 Subject: [PATCH] move get_conf_str_map_helper to str_map.h (from Monitor.h) Signed-off-by: Sage Weil --- src/common/str_map.cc | 29 +++++++++++++++++++++++++++++ src/include/str_map.h | 13 +++++++++++++ src/mon/Monitor.h | 43 ------------------------------------------- 3 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/common/str_map.cc b/src/common/str_map.cc index 719f94fc2cc32..b731af334d40a 100644 --- a/src/common/str_map.cc +++ b/src/common/str_map.cc @@ -128,3 +128,32 @@ string get_str_map_key( } return string(); } + +// This function's only purpose is to check whether a given map has only +// ONE key with an empty value (which would mean that 'get_str_map()' read +// a map in the form of 'VALUE', without any KEY/VALUE pairs) and, in such +// event, to assign said 'VALUE' to a given 'def_key', such that we end up +// with a map of the form "m = { 'def_key' : 'VALUE' }" instead of the +// original "m = { 'VALUE' : '' }". +int get_conf_str_map_helper( + const string &str, + ostringstream &oss, + map *m, + const string &def_key) +{ + int r = get_str_map(str, m); + + if (r < 0) { + return r; + } + + if (r >= 0 && m->size() == 1) { + map::iterator p = m->begin(); + if (p->second.empty()) { + string s = p->first; + m->erase(s); + (*m)[def_key] = s; + } + } + return r; +} diff --git a/src/include/str_map.h b/src/include/str_map.h index c2a8778583f15..4b739ef584ff1 100644 --- a/src/include/str_map.h +++ b/src/include/str_map.h @@ -134,4 +134,17 @@ extern std::string get_str_map_key( const std::string &key, const std::string *fallback_key = NULL); + +// This function's only purpose is to check whether a given map has only +// ONE key with an empty value (which would mean that 'get_str_map()' read +// a map in the form of 'VALUE', without any KEY/VALUE pairs) and, in such +// event, to assign said 'VALUE' to a given 'def_key', such that we end up +// with a map of the form "m = { 'def_key' : 'VALUE' }" instead of the +// original "m = { 'VALUE' : '' }". +int get_conf_str_map_helper( + const std::string &str, + std::ostringstream &oss, + std::map *m, + const std::string &def_key); + #endif diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index 1a3d98bd7abb2..45a1a714238ad 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -1020,47 +1020,4 @@ struct MonCommand { }; WRITE_CLASS_ENCODER(MonCommand) -// Having this here is less than optimal, but we needed to keep it -// somewhere as to avoid code duplication, as it will be needed both -// on the Monitor class and the LogMonitor class. -// -// We are attempting to avoid code duplication in the event that -// changing how the mechanisms currently work will lead to unnecessary -// issues, resulting from the need of changing this function in multiple -// places. -// -// This function is just a helper to perform a task that should not be -// needed anywhere else besides the two functions that shall call it. -// -// This function's only purpose is to check whether a given map has only -// ONE key with an empty value (which would mean that 'get_str_map()' read -// a map in the form of 'VALUE', without any KEY/VALUE pairs) and, in such -// event, to assign said 'VALUE' to a given 'def_key', such that we end up -// with a map of the form "m = { 'def_key' : 'VALUE' }" instead of the -// original "m = { 'VALUE' : '' }". -static inline int get_conf_str_map_helper( - const string &str, - ostringstream &oss, - map *m, - const string &def_key) -{ - int r = get_str_map(str, m); - - if (r < 0) { - generic_derr << __func__ << " error: " << oss.str() << dendl; - return r; - } - - if (r >= 0 && m->size() == 1) { - map::iterator p = m->begin(); - if (p->second.empty()) { - string s = p->first; - m->erase(s); - (*m)[def_key] = s; - } - } - return r; -} - - #endif -- 2.39.5