Put indents into output streams, to produce more legible printed output. More...
#include <vsl_indent.h>
Put indents into output streams, to produce more legible printed output.
Its use is best described by example:
vcl_cout<<vsl_indent()<<"No Indent\n"; vsl_indent_inc(vcl_cout); vcl_cout<<vsl_indent()<<"1 Indent\n"; vsl_indent_inc(vcl_cout); vcl_cout<<vsl_indent()<<"2 Indent\n"; vsl_indent_dec(vcl_cout); vcl_cout<<vsl_indent()<<"1 Indent\n"; vsl_indent_dec(vcl_cout); vcl_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(vcl_ostream& os) const { os<<vsl_indent()<<"Fred's data"; } }; vcl_ostream& operator<<(vcl_ostream& os, const Fred& fred) { os<<"Fred:\n"; vsl_indent_inc(os); fred.print(os); vsl_indent_dec(os); return os; } class Jim { private: Fred fred_; public: void print(vcl_ostream& os) const { os<<vsl_indent()<<fred_<<'\n' <<vsl_indent()<<"Jim's other data\n"; } }; vcl_ostream& operator<<(vcl_ostream& os, const Jim& jim) { os<<"Jim:\n"; vsl_indent_inc(os); jim.print(os); vsl_indent_dec(os); return os; } main() { Jim jim; vcl_cout<<jim<<vcl_endl; }
This produces output:
Jim: Fred's data Jim's other data
Definition at line 88 of file vsl_indent.h.