vsl_indent.h
Go to the documentation of this file.
1 // This is core/vsl/vsl_indent.h
2 #ifndef vsl_indent_h_
3 #define vsl_indent_h_
4 //:
5 // \file
6 // \author Tim Cootes
7 
8 #include <iosfwd>
9 #ifdef _MSC_VER
10 # include <vcl_msvc_warnings.h>
11 #endif
12 
13 //: Put indents into output streams, to produce more legible printed output
14 // Its use is best described by example:
15 // \code
16 // std::cout<<vsl_indent()<<"No Indent\n";
17 // vsl_indent_inc(std::cout);
18 // std::cout<<vsl_indent()<<"1 Indent\n";
19 // vsl_indent_inc(std::cout);
20 // std::cout<<vsl_indent()<<"2 Indent\n";
21 // vsl_indent_dec(std::cout);
22 // std::cout<<vsl_indent()<<"1 Indent\n";
23 // vsl_indent_dec(std::cout);
24 // std::cout<<vsl_indent()<<"No Indent\n";
25 // \endcode
26 //
27 // This produces output of the form
28 // \verbatim
29 // No Indent
30 // 1 Indent
31 // 2 Indent
32 // 1 Indent
33 // No Indent
34 // \endverbatim
35 //
36 // Example of use in class output:
37 // \code
38 // class Fred
39 // {
40 // public:
41 // void print(std::ostream& os) const { os<<vsl_indent()<<"Fred's data"; }
42 // };
43 //
44 // std::ostream& operator<<(std::ostream& os, const Fred& fred)
45 // {
46 // os<<"Fred:\n";
47 // vsl_indent_inc(os);
48 // fred.print(os);
49 // vsl_indent_dec(os);
50 // return os;
51 // }
52 //
53 // class Jim
54 // {
55 // private:
56 // Fred fred_;
57 // public:
58 // void print(std::ostream& os) const
59 // {
60 // os<<vsl_indent()<<fred_<<'\n'
61 // <<vsl_indent()<<"Jim's other data\n";
62 // }
63 // };
64 //
65 // std::ostream& operator<<(std::ostream& os, const Jim& jim)
66 // {
67 // os<<"Jim:\n";
68 // vsl_indent_inc(os);
69 // jim.print(os);
70 // vsl_indent_dec(os);
71 // return os;
72 // }
73 //
74 // main()
75 // {
76 // Jim jim;
77 // std::cout<<jim<<std::endl;
78 // }
79 // \endcode
80 //
81 // This produces output:
82 // \verbatim
83 // Jim:
84 // Fred's data
85 // Jim's other data
86 // \endverbatim
87 
89 {
90 };
91 
92 //: Increments current indent for given stream
93 void vsl_indent_inc(std::ostream& os);
94 
95 //: Decrements current indent for given stream
96 void vsl_indent_dec(std::ostream& os);
97 
98 //: Set number of spaces per increment step
99 void vsl_indent_set_tab(std::ostream& os,int);
100 
101 //: Number of spaces per increment step
102 int vsl_indent_tab(std::ostream& os);
103 
104 //: Set indentation to zero
105 void vsl_indent_clear(std::ostream& os);
106 
107 //: Outputs current indent to os
108 std::ostream& operator<<(std::ostream& os, const vsl_indent& indent);
109 
110 //: Tidy up the internal indent map to remove potential memory leaks
111 // The details of indents for each stream are stored in a static
112 // map. When testing for memory leaks, this is flagged, creating
113 // lots of noise in the output of memory leak checkers.
114 // This call empties the map, removing the potential leak.
115 // Pragmatically it is called in the vsl_delete_all_loaders()
117 
118 #endif // vsl_indent_h_
std::ostream & operator<<(std::ostream &os, const vsl_indent &indent)
Outputs current indent to os.
Definition: vsl_indent.cxx:67
void vsl_indent_set_tab(std::ostream &os, int)
Set number of spaces per increment step.
Definition: vsl_indent.cxx:50
void vsl_indent_inc(std::ostream &os)
Increments current indent for given stream.
Definition: vsl_indent.cxx:38
int vsl_indent_tab(std::ostream &os)
Number of spaces per increment step.
Definition: vsl_indent.cxx:56
Put indents into output streams, to produce more legible printed output.
Definition: vsl_indent.h:88
void vsl_indent_clear_all_data()
Tidy up the internal indent map to remove potential memory leaks.
Definition: vsl_indent.cxx:85
void vsl_indent_dec(std::ostream &os)
Decrements current indent for given stream.
Definition: vsl_indent.cxx:44
void vsl_indent_clear(std::ostream &os)
Set indentation to zero.
Definition: vsl_indent.cxx:62