From d852a26c5d2ef9f295b1613647e2052e69f5081a Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 17 Dec 2018 14:18:01 -0600 Subject: [PATCH] common/options: expand type helpers and make them static - make str_to_type and type_to_str symmetric - keep the variant that provides C++ types, even though there are no users Signed-off-by: Sage Weil --- src/common/options.h | 50 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/common/options.h b/src/common/options.h index 8b55ac33969..bc1fa6a9e2c 100644 --- a/src/common/options.h +++ b/src/common/options.h @@ -25,7 +25,7 @@ struct Option { TYPE_SECS = 9, }; - const char *type_to_str(type_t t) const { + static const char *type_to_c_type_str(type_t t) { switch (t) { case TYPE_UINT: return "uint64_t"; case TYPE_INT: return "int64_t"; @@ -40,6 +40,54 @@ struct Option { default: return "unknown"; } } + static const char *type_to_str(type_t t) { + switch (t) { + case TYPE_UINT: return "uint"; + case TYPE_INT: return "int"; + case TYPE_STR: return "str"; + case TYPE_FLOAT: return "float"; + case TYPE_BOOL: return "bool"; + case TYPE_ADDR: return "addr"; + case TYPE_ADDRVEC: return "addrvec"; + case TYPE_UUID: return "uuid"; + case TYPE_SIZE: return "size"; + case TYPE_SECS: return "secs"; + default: return "unknown"; + } + } + static int str_to_type(const std::string& s) { + if (s == "uint") { + return TYPE_UINT; + } + if (s == "int") { + return TYPE_INT; + } + if (s == "str") { + return TYPE_STR; + } + if (s == "float") { + return TYPE_FLOAT; + } + if (s == "bool") { + return TYPE_BOOL; + } + if (s == "addr") { + return TYPE_ADDR; + } + if (s == "addrvec") { + return TYPE_ADDRVEC; + } + if (s == "uuid") { + return TYPE_UUID; + } + if (s == "size") { + return TYPE_SIZE; + } + if (s == "secs") { + return TYPE_SECS; + } + return -1; + } /** * Basic: for users, configures some externally visible functional aspect -- 2.39.5