From 94bd3aef3b48de7ed7a77bf21d90576630bad1a7 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Fri, 16 Aug 2013 13:48:25 +0100 Subject: [PATCH] Put nested_output in it's own file --- base/nested_output.h | 94 +++++++++++++++++++++++++++++++++ thin-provisioning/thin_check.cc | 85 +---------------------------- 2 files changed, 95 insertions(+), 84 deletions(-) create mode 100644 base/nested_output.h diff --git a/base/nested_output.h b/base/nested_output.h new file mode 100644 index 0000000..7bb6947 --- /dev/null +++ b/base/nested_output.h @@ -0,0 +1,94 @@ +#ifndef BASE_NESTED_OUTPUT_H +#define BASE_NESTED_OUTPUT_H + +#include + +//---------------------------------------------------------------- + +namespace base { + class end_message {}; + + class nested_output { + public: + nested_output(std::ostream &out, unsigned step) + : out_(out), + step_(step), + beginning_of_line_(true), + enabled_(true), + indent_(0) { + } + + template + nested_output &operator <<(T const &t) { + if (beginning_of_line_) { + beginning_of_line_ = false; + indent(); + } + + if (enabled_) + out_ << t; + + return *this; + } + + nested_output &operator <<(end_message const &m) { + beginning_of_line_ = true; + + if (enabled_) + out_ << std::endl; + + return *this; + } + + void inc_indent() { + indent_ += step_; + } + + void dec_indent() { + indent_ -= step_; + } + + struct nest { + nest(nested_output &out) + : out_(out) { + out_.inc_indent(); + } + + ~nest() { + out_.dec_indent(); + } + + nested_output &out_; + }; + + nest push() { + return nest(*this); + } + + void enable() { + enabled_ = true; + } + + void disable() { + enabled_ = false; + } + + private: + void indent() { + if (enabled_) + for (unsigned i = 0; i < indent_; i++) + out_ << ' '; + } + + std::ostream &out_; + unsigned step_; + + bool beginning_of_line_; + bool enabled_; + unsigned indent_; + }; +} + +//---------------------------------------------------------------- + +#endif diff --git a/thin-provisioning/thin_check.cc b/thin-provisioning/thin_check.cc index b5826df..bf27e70 100644 --- a/thin-provisioning/thin_check.cc +++ b/thin-provisioning/thin_check.cc @@ -22,6 +22,7 @@ #include "version.h" +#include "base/nested_output.h" #include "persistent-data/space-maps/core.h" #include "thin-provisioning/device_tree.h" #include "thin-provisioning/file_utils.h" @@ -35,90 +36,6 @@ using namespace thin_provisioning; namespace { - class end_message {}; - - class nested_output { - public: - nested_output(ostream &out, unsigned step) - : out_(out), - step_(step), - beginning_of_line_(true), - enabled_(true), - indent_(0) { - } - - template - nested_output &operator <<(T const &t) { - if (beginning_of_line_) { - beginning_of_line_ = false; - indent(); - } - - if (enabled_) - out_ << t; - - return *this; - } - - nested_output &operator <<(end_message const &m) { - beginning_of_line_ = true; - - if (enabled_) - out_ << endl; - - return *this; - } - - void inc_indent() { - indent_ += step_; - } - - void dec_indent() { - indent_ -= step_; - } - - struct nest { - nest(nested_output &out) - : out_(out) { - out_.inc_indent(); - } - - ~nest() { - out_.dec_indent(); - } - - nested_output &out_; - }; - - nest push() { - return nest(*this); - } - - void enable() { - enabled_ = true; - } - - void disable() { - enabled_ = false; - } - - private: - void indent() { - if (enabled_) - for (unsigned i = 0; i < indent_; i++) - out_ << ' '; - } - - ostream &out_; - unsigned step_; - - bool beginning_of_line_; - bool enabled_; - unsigned indent_; - }; - - //-------------------------------- - enum error_state { NO_ERROR, NON_FATAL, // eg, lost blocks