source: git/Singular/PrettyPrinter.h @ 822e655

spielwiese
Last change on this file since 822e655 was 822e655, checked in by Frank Seelisch <seelisch@…>, 14 years ago
new method flush() git-svn-id: file:///usr/local/Singular/svn/trunk@12254 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 16.5 KB
Line 
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 */
28class PrettyPrinter
29{
30private:
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;
65public:
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 writing all pending output to all defined output files.
96   *  This works simply by closing all output files and re-opening them in
97   *  append mode.
98   */
99  void flush ();
100
101  /*!
102   *  A method for including a linefeed in the output to the primary file
103   *  (if any) and to the console (if console output has been declared accordingly).
104   *  @return a reference to the modified instance of PrettyPrinter
105   *  @see PrettyPrinter::operator++ ()
106   */
107  PrettyPrinter& operator+ ();
108 
109  /*!
110   *  A method for including a linefeed in the output to the primary file
111   *  (if any), the secondary file (if any), and to the console (if console
112   *  output has been declared accordingly).
113   *  @return a reference to the modified instance of PrettyPrinter
114   *  @see PrettyPrinter::operator+ ()
115   */
116  PrettyPrinter& operator++ ();
117 
118  /*!
119   *  A method for including the current indent string followed by the argument string
120   *  in the output to the primary file (if any) and to the console (if console output
121   *  has been declared accordingly).
122   *  @param s the string to be written to the output devices
123   *  @return a reference to the modified instance of PrettyPrinter
124   *  @see PrettyPrinter::operator>> (const char* s)
125   */
126  PrettyPrinter& operator> (const char* s);
127
128  /*!
129   *  A method for including the current indent string followed by the argument string
130   *  in the output to the primary file (if any), to the secondary file (if any), and to
131   *  the console (if console output has been declared accordingly).
132   *  @param s the string to be written to the output devices
133   *  @return a reference to the modified instance of PrettyPrinter
134   *  @see PrettyPrinter::operator> (const char* s)
135   */
136  PrettyPrinter& operator>> (const char* s);
137
138  /*!
139   *  A method for including the current indent string followed by the argument integer
140   *  in the output to the primary file (if any) and to the console (if console output
141   *  has been declared accordingly).
142   *  @param i the integer to be written to the output devices
143   *  @return a reference to the modified instance of PrettyPrinter
144   *  @see PrettyPrinter::operator>> (const int i)
145   */
146  PrettyPrinter& operator> (const int i);
147 
148  /*!
149   *  A method for including the current indent string followed by the argument integer
150   *  in the output to the primary file (if any), to the secondary file (if any), and to
151   *  the console (if console output has been declared accordingly).
152   *  @param i the integer to be written to the output devices
153   *  @return a reference to the modified instance of PrettyPrinter
154   *  @see PrettyPrinter::operator> (const int i)
155   */
156  PrettyPrinter& operator>> (const int i);
157 
158  /*!
159   *  A method for including the current indent string followed by the argument long
160   *  in the output to the primary file (if any) and to the console (if console output
161   *  has been declared accordingly).
162   *  @param l the long to be written to the output devices
163   *  @return a reference to the modified instance of PrettyPrinter
164   *  @see PrettyPrinter::operator>> (const long l)
165   */
166  PrettyPrinter& operator> (const long l);
167 
168  /*!
169   *  A method for including the current indent string followed by the argument long
170   *  in the output to the primary file (if any), to the secondary file (if any), and to
171   *  the console (if console output has been declared accordingly).
172   *  @param l the long to be written to the output devices
173   *  @return a reference to the modified instance of PrettyPrinter
174   *  @see PrettyPrinter::operator> (const long l)
175   */
176  PrettyPrinter& operator>> (const long l);
177 
178  /*!
179   *  A method for including the current indent string followed by the argument unsigned long
180   *  in the output to the primary file (if any) and to the console (if console output
181   *  has been declared accordingly).
182   *  @param ul the unsigned long to be written to the output devices
183   *  @return a reference to the modified instance of PrettyPrinter
184   *  @see PrettyPrinter::operator>> (const unsigned long ul)
185   */
186  PrettyPrinter& operator> (const unsigned long ul);
187 
188  /*!
189   *  A method for including the current indent string followed by the argument unsigned long
190   *  in the output to the primary file (if any), to the secondary file (if any), and to
191   *  the console (if console output has been declared accordingly).
192   *  @param ul the unsigned long to be written to the output devices
193   *  @return a reference to the modified instance of PrettyPrinter
194   *  @see PrettyPrinter::operator> (const unsigned long ul)
195   */
196  PrettyPrinter& operator>> (const unsigned long ul);
197 
198  /*!
199   *  A method for including the current indent string followed by the argument string
200   *  in the output to the primary file (if any) and to the console (if console output
201   *  has been declared accordingly).
202   *  @return a reference to the modified instance of PrettyPrinter
203   *  @see PrettyPrinter::operator>> (const std::string s)
204   */
205  PrettyPrinter& operator> (const std::string s);
206 
207  /*!
208   *  A method for including the current indent string followed by the argument string
209   *  in the output to the primary file (if any), to the secondary file (if any), and to
210   *  the console (if console output has been declared accordingly).
211   *  @param s the string to be written to the output devices
212   *  @return a reference to the modified instance of PrettyPrinter
213   *  @see PrettyPrinter::operator> (const std::string s)
214   */
215  PrettyPrinter& operator>> (const std::string s);
216 
217  /*!
218   *  A method for including the argument string in the output to the primary file
219   *  (if any) and to the console (if console output has been declared accordingly).
220   *  @param s the string to be written to the output devices
221   *  @return a reference to the modified instance of PrettyPrinter
222   *  @see PrettyPrinter::operator<< (const char* s)
223   */
224  PrettyPrinter& operator< (const char* s);
225 
226  /*!
227   *  A method for including the argument string in the output to the primary file
228   *  (if any), to the secondary file (if any), and to the console (if console
229   *  output has been declared accordingly).
230   *  @param s the string to be written to the output devices
231   *  @return a reference to the modified instance of PrettyPrinter
232   *  @see PrettyPrinter::operator< (const char* s)
233   */
234  PrettyPrinter& operator<< (const char* s);
235 
236  /*!
237   *  A method for including the argument integer in the output to the primary file
238   *  (if any) and to the console (if console output has been declared accordingly).
239   *  @param i the integer to be written to the output devices
240   *  @return a reference to the modified instance of PrettyPrinter
241   *  @see PrettyPrinter::operator<< (const int i)
242   */
243  PrettyPrinter& operator< (const int i);
244 
245  /*!
246   *  A method for including the argument integer in the output to the primary file
247   *  (if any), to the secondary file (if any), and to the console (if console
248   *  output has been declared accordingly).
249   *  @param i the integer to be written to the output devices
250   *  @return a reference to the modified instance of PrettyPrinter
251   *  @see PrettyPrinter::operator< (const int i)
252   */
253  PrettyPrinter& operator<< (const int i);
254 
255  /*!
256   *  A method for including the argument long in the output to the primary file
257   *  (if any) and to the console (if console output has been declared accordingly).
258   *  @param l the long to be written to the output devices
259   *  @return a reference to the modified instance of PrettyPrinter
260   *  @see PrettyPrinter::operator<< (const long l)
261   */
262  PrettyPrinter& operator< (const long l);
263
264  /*!
265   *  A method for including the argument long in the output to the primary file
266   *  (if any), to the secondary file (if any), and to the console (if console
267   *  output has been declared accordingly).
268   *  @param l the long to be written to the output devices
269   *  @return a reference to the modified instance of PrettyPrinter
270   *  @see PrettyPrinter::operator< (const long l)
271   */
272  PrettyPrinter& operator<< (const long l);
273 
274  /*!
275   *  A method for including the argument unsigned long in the output to the primary file
276   *  (if any) and to the console (if console output has been declared accordingly).
277   *  @param ul the unsigned long to be written to the output devices
278   *  @return a reference to the modified instance of PrettyPrinter
279   *  @see PrettyPrinter::operator<< (const unsigned long ul)
280   */
281  PrettyPrinter& operator< (const unsigned long ul);
282 
283  /*!
284   *  A method for including the argument unsigned long in the output to the primary file
285   *  (if any), to the secondary file (if any), and to the console (if console
286   *  output has been declared accordingly).
287   *  @param ul the unsigned long to be written to the output devices
288   *  @return a reference to the modified instance of PrettyPrinter
289   *  @see PrettyPrinter::operator< (const unsigned long ul)
290   */
291  PrettyPrinter& operator<< (const unsigned long ul);
292 
293  /*!
294   *  A method for including the argument string in the output to the primary file
295   *  (if any) and to the console (if console output has been declared accordingly).
296   *  @param s the string to be written to the output devices
297   *  @return a reference to the modified instance of PrettyPrinter
298   *  @see PrettyPrinter::operator<< (const std::string s)
299   */
300  PrettyPrinter& operator< (const std::string s);
301 
302  /*!
303   *  A method for including the argument string in the output to the primary file
304   *  (if any), to the secondary file (if any), and to the console (if console
305   *  output has been declared accordingly).
306   *  @param s the string to be written to the output devices
307   *  @return a reference to the modified instance of PrettyPrinter
308   *  @see PrettyPrinter::operator< (const std::string s)
309   */
310  PrettyPrinter& operator<< (const std::string s);
311
312  /*!
313   *  A method for incrementing the number of times the baseIndent string is
314   *  concatenated in order to form the current entire indent string. The increment equals
315   *  the argument integer.<br>
316   *  Use PrettyPrinter::setBaseIndent (const char* baseIndent) to define the
317   *  baseIndent string. If e.g. baseIndent == "~~", and the incremented number of times
318   *  this baseIndent will be used equals 3, then the current indent string will be set to
319   *  "~~~~~~".
320   *  @param i the number of times the baseIndent is use to form the current indent string
321   *  @return a reference to the modified instance of PrettyPrinter
322   *  @see PrettyPrinter::operator- (const int i)
323   */
324  PrettyPrinter& operator+ (const int i);
325 
326  /*!
327   *  A method for decrementing the number of times the baseIndent string is
328   *  concatenated in order to form the current entire indent string. The decrement equals
329   *  the argument integer.<br>
330   *  Use PrettyPrinter::setBaseIndent (const char* baseIndent) to define the
331   *  baseIndent string. If e.g. baseIndent == "~~", and the decremented number of times
332   *  this baseIndent will be used equals 3, then the current indent string will be set to
333   *  "~~~~~~".
334   *  @param i the number of times the baseIndent is use to form the current indent string
335   *  @return a reference to the modified instance of PrettyPrinter
336   *  @see PrettyPrinter::operator+ (const int i)
337   */
338  PrettyPrinter& operator- (const int i);
339
340  /*!
341   *  A method for setting the baseIndent string.<br>
342   *  Note that this string is used to form the current entire indent string.
343   *  @param baseIndent the new baseIndent string
344   *  @return a reference to the modified instance of PrettyPrinter
345   *  @see PrettyPrinter::getBaseIndent () const
346   */
347  void setBaseIndent (const char* baseIndent);
348 
349  /*!
350   *  A method for retrieving the baseIndent string.<br>
351   *  Note that this string is used to form the current entire indent string.
352   *  @return the current baseIndent string
353   *  @see PrettyPrinter::setBaseIndent (const char* baseIndent)
354   */
355  char* getBaseIndent () const;
356
357  /*!
358   *  A method for controling console output.<br>
359   *  Use the parameter -1, if no console output is desired; 0 if there should be
360   *  console output but no file output; 1 if console output should be identical to
361   *  output to the primary file; and 2 if console output should be identical to
362   *  output to the secondary file.
363   *  @param console the control number as described in the method comment
364   *  @see PrettyPrinter::getConsole () const
365   */
366  void setConsole (const int console);
367 
368  /*!
369   *  A method for retrieving the console output control parameter.<br>
370   *  @see PrettyPrinter::setConsole (const int console)
371   */
372  int getConsole () const;
373};
374
375#endif
376/* defined(HAVE_MINOR) || defined(HAVE_WRAPPERS) */
377
378#endif
379/* PRETTY_PRINTER_H */
Note: See TracBrowser for help on using the repository browser.