vsl_indent Class Reference

Put indents into output streams, to produce more legible printed output. More...

#include <vsl_indent.h>

Detailed Description

Put indents into output streams, to produce more legible printed output.

Its use is best described by example:

std::cout<<vsl_indent()<<"No Indent\n";
vsl_indent_inc(std::cout);
std::cout<<vsl_indent()<<"1 Indent\n";
vsl_indent_inc(std::cout);
std::cout<<vsl_indent()<<"2 Indent\n";
vsl_indent_dec(std::cout);
std::cout<<vsl_indent()<<"1 Indent\n";
vsl_indent_dec(std::cout);
std::cout<<vsl_indent()<<"No Indent\n";

This produces output of the form

 No Indent
   1 Indent
     2 Indent
   1 Indent
 No Indent

Example of use in class output:

class Fred
{
public:
void print(std::ostream& os) const { os<<vsl_indent()<<"Fred's data"; }
};
std::ostream& operator<<(std::ostream& os, const Fred& fred)
{
os<<"Fred:\n";
fred.print(os);
return os;
}
class Jim
{
private:
Fred fred_;
public:
void print(std::ostream& os) const
{
os<<vsl_indent()<<fred_<<'\n'
<<vsl_indent()<<"Jim's other data\n";
}
};
std::ostream& operator<<(std::ostream& os, const Jim& jim)
{
os<<"Jim:\n";
jim.print(os);
return os;
}
main()
{
Jim jim;
std::cout<<jim<<std::endl;
}

This produces output:

  Jim:
    Fred's data
    Jim's other data

Definition at line 88 of file vsl_indent.h.


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