source: git/Singular/PrettyPrinter.cc @ 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: 5.6 KB
Line 
1#include "mod2.h"
2
3#if defined(HAVE_MINOR) || defined(HAVE_WRAPPERS)
4
5#include <string>
6#include <fstream>
7#include "febase.h"
8#include "PrettyPrinter.h"
9
10PrettyPrinter::PrettyPrinter (const char* fileName1, const char* fileName2,
11                              const bool append1, const bool append2,
12                              const int console, const char* baseIndent)
13{
14  m_baseIndent = new char[200];
15  m_fileName1 = new char[200];
16  m_fileName2 = new char[200];
17  m_indent = new char[10];
18
19  strcpy(m_baseIndent, baseIndent);
20  strcpy(m_fileName1, fileName1);
21  strcpy(m_fileName2, fileName2);
22  strcpy(m_indent, "");
23  if (strcmp(m_fileName1, "") != 0)
24  {
25    if (append1) m_file1.open(m_fileName1, std::fstream::app);
26    else         m_file1.open(m_fileName1);
27  }
28  if (strcmp(m_fileName2, "") != 0)
29  { 
30    if (append2) m_file2.open(m_fileName2, std::fstream::app);
31    else         m_file2.open(m_fileName2);
32  }
33  m_console = console;
34  m_indents = 0;
35}
36
37PrettyPrinter::~PrettyPrinter ()
38{
39  if (strcmp(m_fileName1, "") != 0) m_file1.close();
40  if (strcmp(m_fileName2, "") != 0) m_file2.close();
41  delete m_baseIndent;
42  delete m_fileName1;
43  delete m_fileName2;
44  delete m_indent;
45}
46
47void PrettyPrinter::flush ()
48{
49  if (strcmp(m_fileName1, "") != 0) m_file1.close();
50  if (strcmp(m_fileName2, "") != 0) m_file2.close();
51  m_file1.open(m_fileName1, std::fstream::app);
52  m_file2.open(m_fileName2, std::fstream::app);
53}
54
55PrettyPrinter& PrettyPrinter::operator< (const char* s)
56{
57  if (strcmp(m_fileName1, "") != 0)
58    m_file1 << s;
59  if (m_console == 0 || m_console == 1)
60    PrintS(s);
61  return *this;
62}
63
64PrettyPrinter& PrettyPrinter::operator<< (const char* s)
65{
66  if (strcmp(m_fileName1, "") != 0)
67    m_file1 << s;
68  if (strcmp(m_fileName2, "") != 0)
69    m_file2 << s;
70  if (m_console == 0 || m_console == 1 || m_console == 2)
71    PrintS(s);
72  return *this;
73}
74
75PrettyPrinter& PrettyPrinter::operator< (const std::string s)
76{
77  return (*this) < s.c_str();
78}
79
80PrettyPrinter& PrettyPrinter::operator<< (const std::string s)
81{
82  return (*this) << s.c_str();
83}
84
85PrettyPrinter& PrettyPrinter::operator> (const std::string s)
86{
87  return (*this) > s.c_str();
88}
89
90PrettyPrinter& PrettyPrinter::operator>> (const std::string s)
91{
92  return (*this) >> s.c_str();
93}
94
95PrettyPrinter& PrettyPrinter::operator< (const int i)
96{
97  char h[10];
98  sprintf(h, "%d", i);
99  return (*this) < h;
100}
101
102PrettyPrinter& PrettyPrinter::operator<< (const int i)
103{
104  char h[10];
105  sprintf(h, "%d", i);
106  return (*this) << h;
107}
108
109PrettyPrinter& PrettyPrinter::operator> (const int i)
110{
111  char h[10];
112  sprintf(h, "%d", i);
113  return (*this) > h;
114}
115
116PrettyPrinter& PrettyPrinter::operator>> (const int i)
117{
118  char h[10];
119  sprintf(h, "%d", i);
120  return (*this) >> h;
121}
122
123PrettyPrinter& PrettyPrinter::operator< (const long l)
124{
125  char h[10];
126  sprintf(h, "%ld", l);
127  return (*this) < h;
128}
129
130PrettyPrinter& PrettyPrinter::operator<< (const long l)
131{
132  char h[10];
133  sprintf(h, "%ld", l);
134  return (*this) << h;
135}
136
137PrettyPrinter& PrettyPrinter::operator> (const long l)
138{
139  char h[10];
140  sprintf(h, "%ld", l);
141  return (*this) > h;
142}
143
144PrettyPrinter& PrettyPrinter::operator>> (const long l)
145{
146  char h[10];
147  sprintf(h, "%ld", l);
148  return (*this) >> h;
149}
150
151PrettyPrinter& PrettyPrinter::operator< (const unsigned long ul)
152{
153  char h[10];
154  sprintf(h, "%lu", ul);
155  return (*this) < h;
156}
157
158PrettyPrinter& PrettyPrinter::operator<< (const unsigned long ul)
159{
160  char h[10];
161  sprintf(h, "%lu", ul);
162  return (*this) << h;
163}
164
165PrettyPrinter& PrettyPrinter::operator> (const unsigned long ul)
166{
167  char h[10];
168  sprintf(h, "%lu", ul);
169  return (*this) > h;
170}
171
172PrettyPrinter& PrettyPrinter::operator>> (const unsigned long ul)
173{
174  char h[10];
175  sprintf(h, "%lu", ul);
176  return (*this) >> h;
177}
178
179PrettyPrinter& PrettyPrinter::operator+ ()
180{                                                                 
181  if (strcmp(m_fileName1, "") != 0)
182    m_file1 << "\n";
183  if (m_console == 0 || m_console == 1)
184    PrintLn();
185  return *this;
186}
187
188PrettyPrinter& PrettyPrinter::operator++ ()
189{
190  if (strcmp(m_fileName1, "") != 0)
191    m_file1 << "\n";
192  if (strcmp(m_fileName2, "") != 0)
193    m_file2 << "\n";
194  if (m_console == 0 || m_console == 1 || m_console == 2)
195    PrintLn();
196  return *this;
197}
198
199PrettyPrinter& PrettyPrinter::operator> (const char* s)
200{
201  if (strcmp(m_fileName1, "") != 0)
202  {
203    m_file1 << m_indent;
204    m_file1 << s;
205  }
206  if (m_console == 0 || m_console == 1)
207  {
208    PrintS(m_indent);
209    PrintS(s);
210  }
211  return *this;
212}
213
214PrettyPrinter& PrettyPrinter::operator>> (const char* s)
215{
216  if (strcmp(m_fileName1, "") != 0)
217  {
218    m_file1 << m_indent;
219    m_file1 << s;
220  }
221  if (strcmp(m_fileName2, "") != 0)
222  {
223    m_file2 << m_indent;
224    m_file2 << s;
225  }
226  if (m_console == 0 || m_console == 1 || m_console == 2)
227  {
228    PrintS(m_indent);
229    PrintS(s);
230  }
231  return *this;
232}
233
234PrettyPrinter& PrettyPrinter::operator+ (const int i)
235{
236  m_indents += i;
237  if (m_indents < 0) m_indents = 0;
238  delete m_indent;
239  m_indent = new char[0];
240  strcpy(m_indent, "");
241  for (int j = 0; j < m_indents; j++) strcat(m_indent, m_baseIndent);
242  return *this;
243}
244
245PrettyPrinter& PrettyPrinter::operator- (const int i)
246{
247  m_indents -= i;
248  if (m_indents < 0) m_indents = 0;
249  delete m_indent;
250  m_indent = new char[0];
251  strcpy(m_indent, "");
252  for (int j = 0; j < m_indents; j++) strcat(m_indent, m_baseIndent);
253  return *this;
254}
255
256void PrettyPrinter::setBaseIndent (const char* baseIndent)
257{
258  strcpy(m_baseIndent, baseIndent);
259}
260
261char* PrettyPrinter::getBaseIndent () const
262{
263  return m_baseIndent;
264}
265
266void PrettyPrinter::setConsole (const int console)
267{
268  m_console = console;
269}
270
271int PrettyPrinter::getConsole () const
272{
273  return m_console;
274}
275
276#endif
277/* defined(HAVE_MINOR) || defined(HAVE_WRAPPERS) */
Note: See TracBrowser for help on using the repository browser.