]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/options: expand type helpers and make them static
authorSage Weil <sage@redhat.com>
Mon, 17 Dec 2018 20:18:01 +0000 (14:18 -0600)
committerSage Weil <sage@redhat.com>
Tue, 18 Dec 2018 20:13:03 +0000 (14:13 -0600)
- 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 <sage@redhat.com>
src/common/options.h

index 8b55ac33969d92a1fffe8c6fc974d9ed01653b17..bc1fa6a9e2cd61e50bb73d9ecd714fcd9808973a 100644 (file)
@@ -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