source: git/Singular/PrettyPrinter.cc @ a388ae

spielwiese
Last change on this file since a388ae was a388ae, checked in by Frank Seelisch <seelisch@…>, 15 years ago
added doxygen-like comments git-svn-id: file:///usr/local/Singular/svn/trunk@12198 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.4 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
47PrettyPrinter& PrettyPrinter::operator< (const char* s)
48{
49  if (strcmp(m_fileName1, "") != 0)
50    m_file1 << s;
51  if (m_console == 0 || m_console == 1)
52    PrintS(s);
53  return *this;
54}
55
56PrettyPrinter& PrettyPrinter::operator<< (const char* s)
57{
58  if (strcmp(m_fileName1, "") != 0)
59    m_file1 << s;
60  if (strcmp(m_fileName2, "") != 0)
61    m_file2 << s;
62  if (m_console == 0 || m_console == 1 || m_console == 2)
63    PrintS(s);
64  return *this;
65}
66
67PrettyPrinter& PrettyPrinter::operator< (const std::string s)
68{
69  return (*this) < s.c_str();
70}
71
72PrettyPrinter& PrettyPrinter::operator<< (const std::string s)
73{
74  return (*this) << s.c_str();
75}
76
77PrettyPrinter& PrettyPrinter::operator> (const std::string s)
78{
79  return (*this) > s.c_str();
80}
81
82PrettyPrinter& PrettyPrinter::operator>> (const std::string s)
83{
84  return (*this) >> s.c_str();
85}
86
87PrettyPrinter& PrettyPrinter::operator< (const int i)
88{
89  char h[10];
90  sprintf(h, "%d", i);
91  return (*this) < h;
92}
93
94PrettyPrinter& PrettyPrinter::operator<< (const int i)
95{
96  char h[10];
97  sprintf(h, "%d", i);
98  return (*this) << h;
99}
100
101PrettyPrinter& PrettyPrinter::operator> (const int i)
102{
103  char h[10];
104  sprintf(h, "%d", i);
105  return (*this) > h;
106}
107
108PrettyPrinter& PrettyPrinter::operator>> (const int i)
109{
110  char h[10];
111  sprintf(h, "%d", i);
112  return (*this) >> h;
113}
114
115PrettyPrinter& PrettyPrinter::operator< (const long l)
116{
117  char h[10];
118  sprintf(h, "%ld", l);
119  return (*this) < h;
120}
121
122PrettyPrinter& PrettyPrinter::operator<< (const long l)
123{
124  char h[10];
125  sprintf(h, "%ld", l);
126  return (*this) << h;
127}
128
129PrettyPrinter& PrettyPrinter::operator> (const long l)
130{
131  char h[10];
132  sprintf(h, "%ld", l);
133  return (*this) > h;
134}
135
136PrettyPrinter& PrettyPrinter::operator>> (const long l)
137{
138  char h[10];
139  sprintf(h, "%ld", l);
140  return (*this) >> h;
141}
142
143PrettyPrinter& PrettyPrinter::operator< (const unsigned long ul)
144{
145  char h[10];
146  sprintf(h, "%lu", ul);
147  return (*this) < h;
148}
149
150PrettyPrinter& PrettyPrinter::operator<< (const unsigned long ul)
151{
152  char h[10];
153  sprintf(h, "%lu", ul);
154  return (*this) << h;
155}
156
157PrettyPrinter& PrettyPrinter::operator> (const unsigned long ul)
158{
159  char h[10];
160  sprintf(h, "%lu", ul);
161  return (*this) > h;
162}
163
164PrettyPrinter& PrettyPrinter::operator>> (const unsigned long ul)
165{
166  char h[10];
167  sprintf(h, "%lu", ul);
168  return (*this) >> h;
169}
170
171PrettyPrinter& PrettyPrinter::operator+ ()
172{                                                                 
173  if (strcmp(m_fileName1, "") != 0)
174    m_file1 << "\n";
175  if (m_console == 0 || m_console == 1)
176    PrintLn();
177  return *this;
178}
179
180PrettyPrinter& PrettyPrinter::operator++ ()
181{
182  if (strcmp(m_fileName1, "") != 0)
183    m_file1 << "\n";
184  if (strcmp(m_fileName2, "") != 0)
185    m_file2 << "\n";
186  if (m_console == 0 || m_console == 1 || m_console == 2)
187    PrintLn();
188  return *this;
189}
190
191PrettyPrinter& PrettyPrinter::operator> (const char* s)
192{
193  if (strcmp(m_fileName1, "") != 0)
194  {
195    m_file1 << m_indent;
196    m_file1 << s;
197  }
198  if (m_console == 0 || m_console == 1)
199  {
200    PrintS(m_indent);
201    PrintS(s);
202  }
203  return *this;
204}
205
206PrettyPrinter& PrettyPrinter::operator>> (const char* s)
207{
208  if (strcmp(m_fileName1, "") != 0)
209  {
210    m_file1 << m_indent;
211    m_file1 << s;
212  }
213  if (strcmp(m_fileName2, "") != 0)
214  {
215    m_file2 << m_indent;
216    m_file2 << s;
217  }
218  if (m_console == 0 || m_console == 1 || m_console == 2)
219  {
220    PrintS(m_indent);
221    PrintS(s);
222  }
223  return *this;
224}
225
226PrettyPrinter& PrettyPrinter::operator+ (const int i)
227{
228  m_indents += i;
229  if (m_indents < 0) m_indents = 0;
230  delete m_indent;
231  m_indent = new char[0];
232  strcpy(m_indent, "");
233  for (int j = 0; j < m_indents; j++) strcat(m_indent, m_baseIndent);
234  return *this;
235}
236
237PrettyPrinter& PrettyPrinter::operator- (const int i)
238{
239  m_indents -= i;
240  if (m_indents < 0) m_indents = 0;
241  delete m_indent;
242  m_indent = new char[0];
243  strcpy(m_indent, "");
244  for (int j = 0; j < m_indents; j++) strcat(m_indent, m_baseIndent);
245  return *this;
246}
247
248void PrettyPrinter::setBaseIndent (const char* baseIndent)
249{
250  strcpy(m_baseIndent, baseIndent);
251}
252
253char* PrettyPrinter::getBaseIndent () const
254{
255  return m_baseIndent;
256}
257
258void PrettyPrinter::setConsole (const int console)
259{
260  m_console = console;
261}
262
263int PrettyPrinter::getConsole () const
264{
265  return m_console;
266}
267
268#endif
269/* defined(HAVE_MINOR) || defined(HAVE_WRAPPERS) */
Note: See TracBrowser for help on using the repository browser.