Dune Core Modules (2.6.0)

indent.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_COMMON_INDENT_HH
4#define DUNE_COMMON_INDENT_HH
5
6#include <ostream>
7#include <string>
8
9namespace Dune {
20
50 class Indent
51 {
52 const Indent* parent;
53 std::string basic_indent;
54 unsigned level;
55
56 public:
58
61 inline Indent(const std::string& basic_indent_ = " ", unsigned level_ = 0)
62 : parent(0), basic_indent(basic_indent_), level(level_)
63 { }
64
66 inline Indent(unsigned level_)
67 : parent(0), basic_indent(" "), level(level_)
68 { }
69
71
74 inline Indent(const Indent* parent_,
75 const std::string& basic_indent_ = " ", unsigned level_ = 1)
76 : parent(parent_), basic_indent(basic_indent_), level(level_)
77 { }
78
80 inline Indent(const Indent* parent_, unsigned level_)
81 : parent(parent_), basic_indent(" "), level(level_)
82 { }
83
85 inline Indent operator+(const std::string& newindent) const {
86 return Indent(this, newindent);
87 }
89 inline Indent operator+(unsigned morelevel) const {
90 return Indent(parent, basic_indent, level+morelevel);
91 }
93 inline Indent& operator++() { ++level; return *this; }
95 inline Indent& operator--() { if ( level > 0 ) --level; return *this; }
96
98 friend inline std::ostream& operator<<(std::ostream& s,
99 const Indent& indent);
100 };
101
103 inline std::ostream& operator<<(std::ostream& s, const Indent& indent) {
104 if(indent.parent)
105 s << *indent.parent;
106 for(unsigned i = 0; i < indent.level; ++i)
107 s << indent.basic_indent;
108 return s;
109 }
110
113} // namespace Dune
114
115#endif // DUNE_COMMON_INDENT_HH
Utility class for handling nested indentation in output.
Definition: indent.hh:51
Indent operator+(const std::string &newindent) const
create new indentation object with this one as parent
Definition: indent.hh:85
Indent(unsigned level_)
setup without parent and basic_indentation of two spaces
Definition: indent.hh:66
Indent operator+(unsigned morelevel) const
create a copy of this indentation object with raised level
Definition: indent.hh:89
Indent(const Indent *parent_, unsigned level_)
setup with parent
Definition: indent.hh:80
Indent & operator++()
raise indentation level
Definition: indent.hh:93
Indent(const std::string &basic_indent_=" ", unsigned level_=0)
setup without parent
Definition: indent.hh:61
Indent & operator--()
lower indentation level
Definition: indent.hh:95
friend std::ostream & operator<<(std::ostream &s, const Indent &indent)
write indentation to a stream
Definition: indent.hh:103
Indent(const Indent *parent_, const std::string &basic_indent_=" ", unsigned level_=1)
setup with parent
Definition: indent.hh:74
Dune namespace.
Definition: alignedallocator.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)