Loading...
Searching...
No Matches
indent.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_COMMON_INDENT_HH
#define DUNE_COMMON_INDENT_HH
#include <ostream>
#include <string>
namespace Dune {
class Indent
{
const Indent* parent;
std::string basic_indent;
unsigned level;
public:
inline Indent(const std::string& basic_indent_ = " ", unsigned level_ = 0)
: parent(0), basic_indent(basic_indent_), level(level_)
{ }
inline Indent(unsigned level_)
: parent(0), basic_indent(" "), level(level_)
{ }
inline Indent(const Indent* parent_,
const std::string& basic_indent_ = " ", unsigned level_ = 1)
: parent(parent_), basic_indent(basic_indent_), level(level_)
{ }
inline Indent(const Indent* parent_, unsigned level_)
: parent(parent_), basic_indent(" "), level(level_)
{ }
inline Indent operator+(const std::string& newindent) const {
return Indent(this, newindent);
}
inline Indent operator+(unsigned morelevel) const {
return Indent(parent, basic_indent, level+morelevel);
}
inline Indent& operator++() { ++level; return *this; }
inline Indent& operator--() { if ( level > 0 ) --level; return *this; }
friend inline std::ostream& operator<<(std::ostream& s,
const Indent& indent);
};
inline std::ostream& operator<<(std::ostream& s, const Indent& indent) {
if(indent.parent)
s << *indent.parent;
for(unsigned i = 0; i < indent.level; ++i)
s << indent.basic_indent;
return s;
}
} // namespace Dune
#endif // DUNE_COMMON_INDENT_HH
Dune::Indent::operator+
Indent operator+(const std::string &newindent) const
create new indentation object with this one as parent
Definition indent.hh:87
Dune::Indent::Indent
Indent(unsigned level_)
setup without parent and basic_indentation of two spaces
Definition indent.hh:68
Dune::Indent::operator+
Indent operator+(unsigned morelevel) const
create a copy of this indentation object with raised level
Definition indent.hh:91
Dune::Indent::Indent
Indent(const Indent *parent_, unsigned level_)
setup with parent
Definition indent.hh:82
Dune::Indent::operator++
Indent & operator++()
raise indentation level
Definition indent.hh:95
Dune::Indent::Indent
Indent(const std::string &basic_indent_=" ", unsigned level_=0)
setup without parent
Definition indent.hh:63
Dune::Indent::operator--
Indent & operator--()
lower indentation level
Definition indent.hh:97
Dune::Indent::operator<<
friend std::ostream & operator<<(std::ostream &s, const Indent &indent)
write indentation to a stream
Definition indent.hh:105
Dune::Indent::Indent
Indent(const Indent *parent_, const std::string &basic_indent_=" ", unsigned level_=1)
setup with parent
Definition indent.hh:76
Dune::operator<<
std::ostream & operator<<(std::ostream &s, const bigunsignedint< k > &x)
Definition bigunsignedint.hh:301
Dune
Dune namespace
Definition alignedallocator.hh:13
Dune::Indent
Utility class for handling nested indentation in output.
Definition indent.hh:53