00001
00002
00003 #ifndef DUNE_COMMON_INDENT_HH
00004 #define DUNE_COMMON_INDENT_HH
00005
00006 #include <ostream>
00007 #include <string>
00008
00009 namespace Dune {
00019
00020
00050 class Indent
00051 {
00052 const Indent* parent;
00053 std::string basic_indent;
00054 unsigned level;
00055
00056 public:
00058
00061 inline Indent(const std::string& basic_indent_ = " ", unsigned level_ = 0)
00062 : parent(0), basic_indent(basic_indent_), level(level_)
00063 { }
00064
00066 inline Indent(unsigned level_)
00067 : parent(0), basic_indent(" "), level(level_)
00068 { }
00069
00071
00074 inline Indent(const Indent* parent_,
00075 const std::string& basic_indent_ = " ", unsigned level_ = 1)
00076 : parent(parent_), basic_indent(basic_indent_), level(level_)
00077 { }
00078
00080 inline Indent(const Indent* parent_, unsigned level_)
00081 : parent(parent_), basic_indent(" "), level(level_)
00082 { }
00083
00085 inline Indent operator+(const std::string& newindent) const {
00086 return Indent(this, newindent);
00087 }
00089 inline Indent operator+(unsigned morelevel) const {
00090 return Indent(parent, basic_indent, level+morelevel);
00091 }
00093 inline Indent& operator++() { ++level; return *this; }
00095 inline Indent& operator--() { --level; return *this; }
00096
00098 friend inline std::ostream& operator<<(std::ostream& s,
00099 const Indent& indent);
00100 };
00101
00103 inline std::ostream& operator<<(std::ostream& s, const Indent& indent) {
00104 if(indent.parent)
00105 s << *indent.parent;
00106 for(unsigned i = 0; i < indent.level; ++i)
00107 s << indent.basic_indent;
00108 return s;
00109 }
00110
00113 }
00114
00115 #endif // DUNE_COMMON_INDENT_HH