From 28bc88b7cd5988bd9df722b1382833c8890a7e79 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 15 Jan 2018 14:22:07 -0800 Subject: [PATCH] formatter: add two utility classes For automatic section scoping Signed-off-by: Yehuda Sadeh --- src/common/Formatter.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/common/Formatter.h b/src/common/Formatter.h index 8cfcc0b0a7731..4a9ac3210e083 100644 --- a/src/common/Formatter.h +++ b/src/common/Formatter.h @@ -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); -- 2.39.5