]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
formatter: add two utility classes
authorYehuda Sadeh <yehuda@redhat.com>
Mon, 15 Jan 2018 22:22:07 +0000 (14:22 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Thu, 12 Apr 2018 22:38:38 +0000 (15:38 -0700)
For automatic section scoping

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

index 8cfcc0b0a773139933151b59385e11d5617b34a3..4a9ac3210e083104ff3538affbeb8c8f6cb1570b 100644 (file)
@@ -23,6 +23,29 @@ namespace ceph {
 
   class Formatter {
   public:
+    class ObjectSection {
+      Formatter& formatter;
+
+    public:
+      ObjectSection(Formatter& f, const char *name) : formatter(f) {
+        formatter.open_object_section(name);
+      }
+      ~ObjectSection() {
+        formatter.close_section();
+      }
+    };
+    class ArraySection {
+      Formatter& formatter;
+
+    public:
+      ArraySection(Formatter& f, const char *name) : formatter(f) {
+        formatter.open_array_section(name);
+      }
+      ~ArraySection() {
+        formatter.close_section();
+      }
+    };
+
     static Formatter *create(std::string_view type,
                             std::string_view default_type,
                             std::string_view fallback);