From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- tiger-compiler/lib/misc/indent.cc | 57 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tiger-compiler/lib/misc/indent.cc (limited to 'tiger-compiler/lib/misc/indent.cc') diff --git a/tiger-compiler/lib/misc/indent.cc b/tiger-compiler/lib/misc/indent.cc new file mode 100644 index 0000000..03e15cd --- /dev/null +++ b/tiger-compiler/lib/misc/indent.cc @@ -0,0 +1,57 @@ +/** + ** \file misc/indent.cc + ** \brief Implementation of indentation relative functions. + **/ + +#include +#include + +#include +#include + +namespace misc +{ + namespace + { + /// The current indentation level for \a o. + inline long int& indent(std::ostream& o) + { + // The slot to store the current indentation level. + static const long int indent_index = std::ios::xalloc(); + return o.iword(indent_index); + } + + } // namespace + + std::ostream& incindent(std::ostream& o) + { + indent(o) += 2; + return o; + } + + std::ostream& decindent(std::ostream& o) + { + precondition(indent(o)); + indent(o) -= 2; + return o; + } + + std::ostream& resetindent(std::ostream& o) + { + indent(o) = 0; + return o; + } + + std::ostream& iendl(std::ostream& o) + { + o << std::endl; + // Be sure to be able to restore the stream flags. + char fill = o.fill(' '); + return o << std::setw(indent(o)) << "" << std::setfill(fill); + } + + std::ostream& incendl(std::ostream& o) { return o << incindent << iendl; } + + std::ostream& decendl(std::ostream& o) { return o << decindent << iendl; } + +} // namespace misc -- cgit v1.2.3