1 | #ifndef PRETTY_PRINTER_H |
---|
2 | #define PRETTY_PRINTER_H |
---|
3 | |
---|
4 | #if defined(HAVE_MINOR) || defined(HAVE_WRAPPERS) |
---|
5 | |
---|
6 | #include <fstream> |
---|
7 | #include <string> |
---|
8 | |
---|
9 | /*! \class PrettyPrinter |
---|
10 | * \brief Class PrettyPrinter is a utility for pretty-printing any kind of |
---|
11 | * output to one or two files and/or the console. |
---|
12 | * |
---|
13 | * The user may use an instance of PrettyPrinter to define two files to |
---|
14 | * which output can be directed. Then, whenever an item is written to the |
---|
15 | * PrettyPrinter, the user can decide whether the output goes only to the |
---|
16 | * first of the files or to both. Thereby, the user may write, e.g., <em>all</em> |
---|
17 | * output to the first file, and only <em>asorted</em> parts to the second, e.g., |
---|
18 | * only the most important bits, for instance to generate some kind of overview |
---|
19 | * of the data that is written to the first file.<br> |
---|
20 | * Furthermore, the user can decide whether the output will also go to the |
---|
21 | * console. If so, he/she can decide whether the console will display |
---|
22 | * all that output which goes to the first file, or only that which goes |
---|
23 | * to the second one. |
---|
24 | * Moreover, PrettyPrinter offers functionality to easily include linefeeds |
---|
25 | * and tabs in the output to give it a better readable format. |
---|
26 | * \author Frank Seelisch, http://www.mathematik.uni-kl.de/~seelisch |
---|
27 | */ |
---|
28 | class PrettyPrinter |
---|
29 | { |
---|
30 | private: |
---|
31 | /*! the number of times, the m_baseIndent is used to make up the current |
---|
32 | indent string; see e.g. PrettyPrinter::operator> (const char* s); |
---|
33 | Example: if m_baseIndent is "~~~" and m_indents == 2, then the current |
---|
34 | indent string is set to "~~~~~~" */ |
---|
35 | int m_indents; |
---|
36 | |
---|
37 | /*! the base string to define the entire current indent string; |
---|
38 | see description of m_indents */ |
---|
39 | char* m_baseIndent; |
---|
40 | |
---|
41 | /*! the container for the entire current indent string; |
---|
42 | see descriptions of m_indents and m_baseIndent */ |
---|
43 | char* m_indent; |
---|
44 | |
---|
45 | /*! file name of primary output file m_file1; |
---|
46 | m_file1 will always contain at least as much output as m_file2 */ |
---|
47 | char* m_fileName1; |
---|
48 | |
---|
49 | /*! file name of secondary output file m_file2; |
---|
50 | m_file1 will always contain at least as much output as m_file2 */ |
---|
51 | char* m_fileName2; |
---|
52 | |
---|
53 | /*! for controlling output to the console;<br> |
---|
54 | if == -1: no output to the console<br> |
---|
55 | if == 0: just output to the console, i.e. no file output<br> |
---|
56 | if == 1: identical outputs to file1 and console<br> |
---|
57 | if == 2: identical outputs to file2 and console */ |
---|
58 | int m_console; |
---|
59 | |
---|
60 | /*! file handle to primary output file */ |
---|
61 | std::ofstream m_file1; |
---|
62 | |
---|
63 | /*! file handle to secondary output file */ |
---|
64 | std::ofstream m_file2; |
---|
65 | public: |
---|
66 | /*! |
---|
67 | * A constructor for PrettyPrinter.<br> |
---|
68 | * Set filenames equal to "" in order to omit the usage of that file. I.e., |
---|
69 | * the user should set fileName2 to "" when he/she wants to use only one |
---|
70 | * output file and set both filenames to "" when he/she does not want any file output.<br> |
---|
71 | * Set console to -1, if no console output is desired; to 0 if there should be |
---|
72 | * console output but no file output; to 1 if console output should be identical to |
---|
73 | * output to primary file; and to 2 if console output should be identical to |
---|
74 | * output to secondary file.<br> |
---|
75 | * The baseIndent will be used to build the current indent string which will be included |
---|
76 | * in the output using e.g. PrettyPrinter::operator> (const char* s). |
---|
77 | * @param fileName1 a file name for the primary output file |
---|
78 | * @param fileName2 a file name for the secondary output file |
---|
79 | * @param append1 if true, m_file1 is being appended, otherwise initially cleared |
---|
80 | * @param append2 if true, m_file2 is being appended, otherwise initially cleared |
---|
81 | * @param console control integer for setting up console output |
---|
82 | * @param baseIndent the base string for the indent string |
---|
83 | * @see PrettyPrinter::operator+ (const int i) |
---|
84 | */ |
---|
85 | PrettyPrinter (const char* fileName1, const char* fileName2, |
---|
86 | const bool append1, const bool append2, |
---|
87 | const int console, const char* baseIndent); |
---|
88 | |
---|
89 | /*! |
---|
90 | * A destructor for PrettyPrinter. |
---|
91 | */ |
---|
92 | ~PrettyPrinter (); |
---|
93 | |
---|
94 | /*! |
---|
95 | * A method for including a linefeed in the output to the primary file |
---|
96 | * (if any) and to the console (if console output has been declared accordingly). |
---|
97 | * @return a reference to the modified instance of PrettyPrinter |
---|
98 | * @see PrettyPrinter::operator++ () |
---|
99 | */ |
---|
100 | PrettyPrinter& operator+ (); |
---|
101 | |
---|
102 | /*! |
---|
103 | * A method for including a linefeed in the output to the primary file |
---|
104 | * (if any), the secondary file (if any), and to the console (if console |
---|
105 | * output has been declared accordingly). |
---|
106 | * @return a reference to the modified instance of PrettyPrinter |
---|
107 | * @see PrettyPrinter::operator+ () |
---|
108 | */ |
---|
109 | PrettyPrinter& operator++ (); |
---|
110 | |
---|
111 | /*! |
---|
112 | * A method for including the current indent string followed by the argument string |
---|
113 | * in the output to the primary file (if any) and to the console (if console output |
---|
114 | * has been declared accordingly). |
---|
115 | * @param s the string to be written to the output devices |
---|
116 | * @return a reference to the modified instance of PrettyPrinter |
---|
117 | * @see PrettyPrinter::operator>> (const char* s) |
---|
118 | */ |
---|
119 | PrettyPrinter& operator> (const char* s); |
---|
120 | |
---|
121 | /*! |
---|
122 | * A method for including the current indent string followed by the argument string |
---|
123 | * in the output to the primary file (if any), to the secondary file (if any), and to |
---|
124 | * the console (if console output has been declared accordingly). |
---|
125 | * @param s the string to be written to the output devices |
---|
126 | * @return a reference to the modified instance of PrettyPrinter |
---|
127 | * @see PrettyPrinter::operator> (const char* s) |
---|
128 | */ |
---|
129 | PrettyPrinter& operator>> (const char* s); |
---|
130 | |
---|
131 | /*! |
---|
132 | * A method for including the current indent string followed by the argument integer |
---|
133 | * in the output to the primary file (if any) and to the console (if console output |
---|
134 | * has been declared accordingly). |
---|
135 | * @param i the integer to be written to the output devices |
---|
136 | * @return a reference to the modified instance of PrettyPrinter |
---|
137 | * @see PrettyPrinter::operator>> (const int i) |
---|
138 | */ |
---|
139 | PrettyPrinter& operator> (const int i); |
---|
140 | |
---|
141 | /*! |
---|
142 | * A method for including the current indent string followed by the argument integer |
---|
143 | * in the output to the primary file (if any), to the secondary file (if any), and to |
---|
144 | * the console (if console output has been declared accordingly). |
---|
145 | * @param i the integer to be written to the output devices |
---|
146 | * @return a reference to the modified instance of PrettyPrinter |
---|
147 | * @see PrettyPrinter::operator> (const int i) |
---|
148 | */ |
---|
149 | PrettyPrinter& operator>> (const int i); |
---|
150 | |
---|
151 | /*! |
---|
152 | * A method for including the current indent string followed by the argument long |
---|
153 | * in the output to the primary file (if any) and to the console (if console output |
---|
154 | * has been declared accordingly). |
---|
155 | * @param l the long to be written to the output devices |
---|
156 | * @return a reference to the modified instance of PrettyPrinter |
---|
157 | * @see PrettyPrinter::operator>> (const long l) |
---|
158 | */ |
---|
159 | PrettyPrinter& operator> (const long l); |
---|
160 | |
---|
161 | /*! |
---|
162 | * A method for including the current indent string followed by the argument long |
---|
163 | * in the output to the primary file (if any), to the secondary file (if any), and to |
---|
164 | * the console (if console output has been declared accordingly). |
---|
165 | * @param l the long to be written to the output devices |
---|
166 | * @return a reference to the modified instance of PrettyPrinter |
---|
167 | * @see PrettyPrinter::operator> (const long l) |
---|
168 | */ |
---|
169 | PrettyPrinter& operator>> (const long l); |
---|
170 | |
---|
171 | /*! |
---|
172 | * A method for including the current indent string followed by the argument unsigned long |
---|
173 | * in the output to the primary file (if any) and to the console (if console output |
---|
174 | * has been declared accordingly). |
---|
175 | * @param ul the unsigned long to be written to the output devices |
---|
176 | * @return a reference to the modified instance of PrettyPrinter |
---|
177 | * @see PrettyPrinter::operator>> (const unsigned long ul) |
---|
178 | */ |
---|
179 | PrettyPrinter& operator> (const unsigned long ul); |
---|
180 | |
---|
181 | /*! |
---|
182 | * A method for including the current indent string followed by the argument unsigned long |
---|
183 | * in the output to the primary file (if any), to the secondary file (if any), and to |
---|
184 | * the console (if console output has been declared accordingly). |
---|
185 | * @param ul the unsigned long to be written to the output devices |
---|
186 | * @return a reference to the modified instance of PrettyPrinter |
---|
187 | * @see PrettyPrinter::operator> (const unsigned long ul) |
---|
188 | */ |
---|
189 | PrettyPrinter& operator>> (const unsigned long ul); |
---|
190 | |
---|
191 | /*! |
---|
192 | * A method for including the current indent string followed by the argument string |
---|
193 | * in the output to the primary file (if any) and to the console (if console output |
---|
194 | * has been declared accordingly). |
---|
195 | * @return a reference to the modified instance of PrettyPrinter |
---|
196 | * @see PrettyPrinter::operator>> (const std::string s) |
---|
197 | */ |
---|
198 | PrettyPrinter& operator> (const std::string s); |
---|
199 | |
---|
200 | /*! |
---|
201 | * A method for including the current indent string followed by the argument string |
---|
202 | * in the output to the primary file (if any), to the secondary file (if any), and to |
---|
203 | * the console (if console output has been declared accordingly). |
---|
204 | * @param s the string to be written to the output devices |
---|
205 | * @return a reference to the modified instance of PrettyPrinter |
---|
206 | * @see PrettyPrinter::operator> (const std::string s) |
---|
207 | */ |
---|
208 | PrettyPrinter& operator>> (const std::string s); |
---|
209 | |
---|
210 | /*! |
---|
211 | * A method for including the argument string in the output to the primary file |
---|
212 | * (if any) and to the console (if console output has been declared accordingly). |
---|
213 | * @param s the string to be written to the output devices |
---|
214 | * @return a reference to the modified instance of PrettyPrinter |
---|
215 | * @see PrettyPrinter::operator<< (const char* s) |
---|
216 | */ |
---|
217 | PrettyPrinter& operator< (const char* s); |
---|
218 | |
---|
219 | /*! |
---|
220 | * A method for including the argument string in the output to the primary file |
---|
221 | * (if any), to the secondary file (if any), and to the console (if console |
---|
222 | * output has been declared accordingly). |
---|
223 | * @param s the string to be written to the output devices |
---|
224 | * @return a reference to the modified instance of PrettyPrinter |
---|
225 | * @see PrettyPrinter::operator< (const char* s) |
---|
226 | */ |
---|
227 | PrettyPrinter& operator<< (const char* s); |
---|
228 | |
---|
229 | /*! |
---|
230 | * A method for including the argument integer in the output to the primary file |
---|
231 | * (if any) and to the console (if console output has been declared accordingly). |
---|
232 | * @param i the integer to be written to the output devices |
---|
233 | * @return a reference to the modified instance of PrettyPrinter |
---|
234 | * @see PrettyPrinter::operator<< (const int i) |
---|
235 | */ |
---|
236 | PrettyPrinter& operator< (const int i); |
---|
237 | |
---|
238 | /*! |
---|
239 | * A method for including the argument integer in the output to the primary file |
---|
240 | * (if any), to the secondary file (if any), and to the console (if console |
---|
241 | * output has been declared accordingly). |
---|
242 | * @param i the integer to be written to the output devices |
---|
243 | * @return a reference to the modified instance of PrettyPrinter |
---|
244 | * @see PrettyPrinter::operator< (const int i) |
---|
245 | */ |
---|
246 | PrettyPrinter& operator<< (const int i); |
---|
247 | |
---|
248 | /*! |
---|
249 | * A method for including the argument long in the output to the primary file |
---|
250 | * (if any) and to the console (if console output has been declared accordingly). |
---|
251 | * @param l the long to be written to the output devices |
---|
252 | * @return a reference to the modified instance of PrettyPrinter |
---|
253 | * @see PrettyPrinter::operator<< (const long l) |
---|
254 | */ |
---|
255 | PrettyPrinter& operator< (const long l); |
---|
256 | |
---|
257 | /*! |
---|
258 | * A method for including the argument long in the output to the primary file |
---|
259 | * (if any), to the secondary file (if any), and to the console (if console |
---|
260 | * output has been declared accordingly). |
---|
261 | * @param l the long to be written to the output devices |
---|
262 | * @return a reference to the modified instance of PrettyPrinter |
---|
263 | * @see PrettyPrinter::operator< (const long l) |
---|
264 | */ |
---|
265 | PrettyPrinter& operator<< (const long l); |
---|
266 | |
---|
267 | /*! |
---|
268 | * A method for including the argument unsigned long in the output to the primary file |
---|
269 | * (if any) and to the console (if console output has been declared accordingly). |
---|
270 | * @param ul the unsigned long to be written to the output devices |
---|
271 | * @return a reference to the modified instance of PrettyPrinter |
---|
272 | * @see PrettyPrinter::operator<< (const unsigned long ul) |
---|
273 | */ |
---|
274 | PrettyPrinter& operator< (const unsigned long ul); |
---|
275 | |
---|
276 | /*! |
---|
277 | * A method for including the argument unsigned long in the output to the primary file |
---|
278 | * (if any), to the secondary file (if any), and to the console (if console |
---|
279 | * output has been declared accordingly). |
---|
280 | * @param ul the unsigned long to be written to the output devices |
---|
281 | * @return a reference to the modified instance of PrettyPrinter |
---|
282 | * @see PrettyPrinter::operator< (const unsigned long ul) |
---|
283 | */ |
---|
284 | PrettyPrinter& operator<< (const unsigned long ul); |
---|
285 | |
---|
286 | /*! |
---|
287 | * A method for including the argument string in the output to the primary file |
---|
288 | * (if any) and to the console (if console output has been declared accordingly). |
---|
289 | * @param s the string to be written to the output devices |
---|
290 | * @return a reference to the modified instance of PrettyPrinter |
---|
291 | * @see PrettyPrinter::operator<< (const std::string s) |
---|
292 | */ |
---|
293 | PrettyPrinter& operator< (const std::string s); |
---|
294 | |
---|
295 | /*! |
---|
296 | * A method for including the argument string in the output to the primary file |
---|
297 | * (if any), to the secondary file (if any), and to the console (if console |
---|
298 | * output has been declared accordingly). |
---|
299 | * @param s the string to be written to the output devices |
---|
300 | * @return a reference to the modified instance of PrettyPrinter |
---|
301 | * @see PrettyPrinter::operator< (const std::string s) |
---|
302 | */ |
---|
303 | PrettyPrinter& operator<< (const std::string s); |
---|
304 | |
---|
305 | /*! |
---|
306 | * A method for incrementing the number of times the baseIndent string is |
---|
307 | * concatenated in order to form the current entire indent string. The increment equals |
---|
308 | * the argument integer.<br> |
---|
309 | * Use PrettyPrinter::setBaseIndent (const char* baseIndent) to define the |
---|
310 | * baseIndent string. If e.g. baseIndent == "~~", and the incremented number of times |
---|
311 | * this baseIndent will be used equals 3, then the current indent string will be set to |
---|
312 | * "~~~~~~". |
---|
313 | * @param i the number of times the baseIndent is use to form the current indent string |
---|
314 | * @return a reference to the modified instance of PrettyPrinter |
---|
315 | * @see PrettyPrinter::operator- (const int i) |
---|
316 | */ |
---|
317 | PrettyPrinter& operator+ (const int i); |
---|
318 | |
---|
319 | /*! |
---|
320 | * A method for decrementing the number of times the baseIndent string is |
---|
321 | * concatenated in order to form the current entire indent string. The decrement equals |
---|
322 | * the argument integer.<br> |
---|
323 | * Use PrettyPrinter::setBaseIndent (const char* baseIndent) to define the |
---|
324 | * baseIndent string. If e.g. baseIndent == "~~", and the decremented number of times |
---|
325 | * this baseIndent will be used equals 3, then the current indent string will be set to |
---|
326 | * "~~~~~~". |
---|
327 | * @param i the number of times the baseIndent is use to form the current indent string |
---|
328 | * @return a reference to the modified instance of PrettyPrinter |
---|
329 | * @see PrettyPrinter::operator+ (const int i) |
---|
330 | */ |
---|
331 | PrettyPrinter& operator- (const int i); |
---|
332 | |
---|
333 | /*! |
---|
334 | * A method for setting the baseIndent string.<br> |
---|
335 | * Note that this string is used to form the current entire indent string. |
---|
336 | * @param baseIndent the new baseIndent string |
---|
337 | * @return a reference to the modified instance of PrettyPrinter |
---|
338 | * @see PrettyPrinter::getBaseIndent () const |
---|
339 | */ |
---|
340 | void setBaseIndent (const char* baseIndent); |
---|
341 | |
---|
342 | /*! |
---|
343 | * A method for retrieving the baseIndent string.<br> |
---|
344 | * Note that this string is used to form the current entire indent string. |
---|
345 | * @return the current baseIndent string |
---|
346 | * @see PrettyPrinter::setBaseIndent (const char* baseIndent) |
---|
347 | */ |
---|
348 | char* getBaseIndent () const; |
---|
349 | |
---|
350 | /*! |
---|
351 | * A method for controling console output.<br> |
---|
352 | * Use the parameter -1, if no console output is desired; 0 if there should be |
---|
353 | * console output but no file output; 1 if console output should be identical to |
---|
354 | * output to the primary file; and 2 if console output should be identical to |
---|
355 | * output to the secondary file. |
---|
356 | * @param console the control number as described in the method comment |
---|
357 | * @see PrettyPrinter::getConsole () const |
---|
358 | */ |
---|
359 | void setConsole (const int console); |
---|
360 | |
---|
361 | /*! |
---|
362 | * A method for retrieving the console output control parameter.<br> |
---|
363 | * @see PrettyPrinter::setConsole (const int console) |
---|
364 | */ |
---|
365 | int getConsole () const; |
---|
366 | }; |
---|
367 | |
---|
368 | #endif |
---|
369 | /* defined(HAVE_MINOR) || defined(HAVE_WRAPPERS) */ |
---|
370 | |
---|
371 | #endif |
---|
372 | /* PRETTY_PRINTER_H */ |
---|