]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_json: formattable fix, api changes
authorYehuda Sadeh <yehuda@redhat.com>
Wed, 13 Dec 2017 11:38:09 +0000 (03:38 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Thu, 12 Apr 2018 22:38:36 +0000 (15:38 -0700)
add implicit casts

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/common/ceph_json.h

index 4e203e01d313ad6fdc46b4413b8277744a4d39b9..a3b3a8b307a8604f397ff07ac49ef2a287d722bb 100644 (file)
@@ -474,10 +474,10 @@ struct JSONFormattable {
     FMT_ARRAY,
     FMT_OBJ,
   } type{FMT_NONE};
-  std::string str;
+
+  string str;
   vector<JSONFormattable> arr;
   map<std::string, JSONFormattable> obj;
-
   void decode_json(JSONObj *jo) {
     if (jo->is_array()) {
       type = JSONFormattable::FMT_ARRAY;
@@ -485,7 +485,7 @@ struct JSONFormattable {
     } else if (jo->is_object()) {
       type = JSONFormattable::FMT_OBJ;
       auto iter = jo->find_first();
-      while (!iter.end()) {
+      for (;!iter.end(); ++iter) {
         JSONObj *field = *iter;
         decode_json_obj(obj[field->get_name()], field);
       }
@@ -514,6 +514,7 @@ struct JSONFormattable {
     decode(obj, bl);
     DECODE_FINISH(bl);
   }
+
   const std::string& val() const {
     return str;
   }
@@ -530,6 +531,23 @@ struct JSONFormattable {
     return this->operator[](std::string(name));
   }
 
+  operator std::string() const {
+    return str;
+  }
+
+  explicit operator int() const {
+    return val_int();
+  }
+
+  explicit operator bool() const {
+    return val_bool();
+  }
+
+  template<class T>
+  T operator[](const std::string& name) const {
+    return this->operator[](name)(T());
+  }
+
   string operator ()(const char *def_val) const {
     return def(string(def_val));
   }