senf::format::IndentHelper Class Reference

Helper class to easily achieve indent levels. More...

#include <senf/Utils/Format.hh>

Public Member Functions

 IndentHelper ()
 Construct new IndentHelper instance. More...
 
 ~IndentHelper ()
 Destruct IndentHelper instance. More...
 
void increase ()
 Increase the indent level. More...
 
unsigned int level () const
 return the current indent level More...
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &os, IndentHelper const &indent)
 Output indent to given ostream. More...
 

Detailed Description

Helper class to easily achieve indent levels.

This class helps to achieve indent levels across function calls. Every instance increases the static indent level. On destruction the level is decreased to the level before the instance. The following example illustrates the use of this class:

void f1() {
std::cout << indent << "f1\n";
}
void f2() {
std::cout << indent << "f2 begin\n";
f1();
std::cout << indent << "f2 end\n";
}
f2()

Output:

    f2 begin
      f1
    f2 end

Here f1() and f2() don't need to know to current indent level, they just increase the level by instantiating IndentHelper.

Definition at line 228 of file Format.hh.

Constructor & Destructor Documentation

◆ IndentHelper()

senf::format::IndentHelper::IndentHelper ( )

Construct new IndentHelper instance.

The static indent level is increased by one.

◆ ~IndentHelper()

senf::format::IndentHelper::~IndentHelper ( )

Destruct IndentHelper instance.

The static indent level will be decreased to the level before the instance.

Member Function Documentation

◆ increase()

void senf::format::IndentHelper::increase ( )

Increase the indent level.

The indent level of the instance is increases by one.

◆ level()

unsigned int senf::format::IndentHelper::level ( ) const

return the current indent level

Friends And Related Function Documentation

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
IndentHelper const &  indent 
)
related

Output indent to given ostream.


The documentation for this class was generated from the following files: