Defined in header <cparse/Indentation.hh>

class Indentation final;

Indentation is the simplest class in cparse: a uint_fast16_t for the current indent, another for the step size, left() / right() to adjust the indent by a whole number of steps, and an operator<< that streams the current indent as that many space characters.

That is the whole thing. If you already have a plain integer and a stream, you have most of what Indentation offers; the reason it exists is to give code emitters (subclasses of Generator) a common vocabulary so callers write getIndentor().right() and stream << getIndentor() instead of maintaining their own counter and formatting logic.

The class is final.

Member functions

Construction / destruction / assignment

(constructor)constructs the indentor with an optional step size
(destructor)destroys the indentor
operator=copy-assigns from another indentor

Indent adjustment

rightincrease indent by N × step size (default N = 1)
leftdecrease indent by N × step size (default N = 1)

Step-size accessors

setStepSizechange the step size
getStepSizeread the step size

Indent accessors

setIndentationset the current indent directly (raw units)
getIndentationread the current indent (raw units)

Reset

resetset step size and clear indent to zero

Static constants

DEFAULT_STEPSIZE2U — default step size when the constructor is called without an argument

Non-member functions

operator<<inserts getIndentation() space characters into an ostream

Notes

Move construction and move assignment are deleted; copy construction and copy assignment are noexcept.

There is no notion of "current column", no wrapping, no tabs, no alignment. Indentation is precisely a leading-whitespace counter. Targets that expect tabs post-process the output or write tabs directly to the stream instead of using this class.

See also