NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
output.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2014 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19
20#include "output.hpp"
21#include "../../kernel.hpp"
22
23using namespace std;
24
25/*
26 * Realisierung der Klasse 'Output'
27 */
28
29// --> Standardkonstruktor <--
31{
32 Output::reset(); // Aus Gruenden der Konsistenz ist es sinnvoll die Resetmethode aufzurufen, damit die Defaultwerte
33 // nur an einer Stelle im Code geaenderte werden muessen
34}
35
36// --> Allgemeiner Konstruktor <--
37Output::Output(bool bStatus, string sFile) : FileSystem()
38{
39 Output::reset(); // Hier rufen wir ebenfalls die reset()-Methode und ueberschreiben dann lieber die nicht-defaults
40 bFile = bStatus;
41
42 if (bStatus) // Wenn ein Datenfile verwendet werden soll, erzeuge dieses sogleich
43 {
44 setFileName(sFile); // sFile wird nur in diesem Fall uebernommen, damit hier so Schlauberger, die Output _out(false,0); aufrufen
45 // keinen Muell machen koennen
46 start(); // Datenfile anlegen
47 }
48
49 sPath = "save";
50 return;
51}
52
53// --> Destruktor <--
55{
56 if (bFile == true && bFileOpen == true)
57 {
58 end(); // Schliesse Datei, falls eine geoeffnet ist
59 }
60
61 return;
62}
63
64// --> Methoden <--
65void Output::setStatus(bool bStatus)
66{
67 if (bFile == true && bFileOpen == true)
68 end(); // Falls zuvor bereits ein Datenfile erzeugt wurde, schliesse dieses zuerst
69
70 bFile = bStatus; // Weise den neuen Wert an den Bool bFile zu.
71 return;
72}
73
74// --> setzt Output auf die Defaultwerte zurueck <--
76{
77 if(bFile && bFileOpen)
78 end();
79
80 bFile = false;
81 bFileOpen = false;
82 bCompact = false;
83 bSumBar = false;
84 bPrintTeX = false;
85 bPrintCSV = false;
86 sPluginName = "";
87 sFileName = "";
88 sCommentLine = "";
89 sPluginPrefix = "data";
91 return;
92}
93
94string Output::replaceTeXControls(const string& _sText)
95{
96 string sReturn = _sText;
97
98 for (unsigned int i = 0; i < sReturn.length(); i++)
99 {
100 if (sReturn[i] == 'Ä' || sReturn[i] == (char)142)
101 sReturn.replace(i,1,"\\\"A");
102
103 if (sReturn[i] == 'ä' || sReturn[i] == (char)132)
104 sReturn.replace(i,1,"\\\"a");
105
106 if (sReturn[i] == 'Ö' || sReturn[i] == (char)153)
107 sReturn.replace(i,1,"\\\"O");
108
109 if (sReturn[i] == 'ö' || sReturn[i] == (char)148)
110 sReturn.replace(i,1,"\\\"o");
111
112 if (sReturn[i] == 'Ü' || sReturn[i] == (char)154)
113 sReturn.replace(i,1,"\\\"U");
114
115 if (sReturn[i] == 'ü' || sReturn[i] == (char)129)
116 sReturn.replace(i,1,"\\\"u");
117
118 if (sReturn[i] == 'ß' || sReturn[i] == (char)225)
119 sReturn.replace(i,1,"\\ss ");
120
121 if (sReturn[i] == '°' || sReturn[i] == (char)248)
122 sReturn.replace(i,1,"$^\\circ$");
123
124 if (sReturn[i] == (char)196 || sReturn[i] == (char)249)
125 sReturn.replace(i,1,"\\pm ");
126
127 if (sReturn[i] == (char)171 || sReturn[i] == (char)174)
128 sReturn.replace(i,1,"\"<");
129
130 if (sReturn[i] == (char)187 || sReturn[i] == (char)175)
131 sReturn.replace(i,1,"\">");
132
133 if ((!i && sReturn[i] == '_') || (i && sReturn[i] == '_' && sReturn[i-1] != '\\'))
134 sReturn.insert(i,1,'\\');
135 }
136
137 return sReturn;
138}
139
140// --> Setzt den Wert des Kompakte-Ausgabe-Booleans <--
141void Output::setCompact(bool _bCompact)
142{
143 bCompact = _bCompact;
144 return;
145}
146
147bool Output::isFile() const
148{
149 return bFile; // Ausgabe an Datei: TRUE/FALSE
150}
151
152
153void Output::setFileName(string sFile)
154{
155 if (bFileOpen) // Ist bereits eine Datei offen? Besser wir schliessen sie vorher.
156 {
157 end();
158 }
159
160 if (sFile != "0") // Ist sFile != 0, pruefe und korrigiere sFile und weise dann an
161 { // sFileName zu, sonst verwende den Default
162 if (sFile.rfind('.') != string::npos
163 && (sFile.substr(sFile.rfind('.')) == ".ndat"
164 || sFile.substr(sFile.rfind('.')) == ".nprc"
165 || sFile.substr(sFile.rfind('.')) == ".nscr"))
166 sFile = sFile.substr(0,sFile.rfind('.'));
167
168 sFileName = FileSystem::ValidFileName(sFile); // Rufe die Methode der PARENT-Klasse auf, um den Namen zu pruefen
169
170 if (sFileName.substr(sFileName.rfind('.')) == ".tex")
171 bPrintTeX = true;
172 else if (sFileName.substr(sFileName.rfind('.')) == ".csv")
173 bPrintCSV = true;
174 }
175 else
176 {
177 generateFileName(); // Generiere einen Dateinamen aus data_YYYY-MM-DD-hhmmss.dat
178 }
179
180 return;
181}
182
183
185{
186 return sFileName; // Gib den aktuellen Dateinamen zurueck
187}
188
189
191{
192 if (bFile == true && bFileOpen == false)
193 {
194 file_out.open(sFileName.c_str(), ios_base::out | ios_base::trunc); // Oeffne die Datei
195 bFileOpen = true; // Setze den Boolean auf TRUE
196 print_legal(); // Schreibe das Copyright
197 }
198
199 return; // Mach nichts, wenn gar nicht in eine Datei geschrieben werden soll,
200 // oder die Datei bereits geoeffnet ist
201}
202
203
204void Output::setPluginName(string _sPluginName)
205{
206 sPluginName = _sPluginName; // Setze sPluginName = _sPluginName
207 return;
208}
209
210
211void Output::setCommentLine(string _sCommentLine)
212{
213 sCommentLine = _sCommentLine; // setze sCommentLine = _sCommentLine;
214 return;
215}
216
217
219{
220 return sPluginName; // gib sPlugin zurueck
221}
222
223
225{
226 return sCommentLine; // gib sCommentLine zurueck
227}
228
229
230void Output::print_legal() // Pro forma Kommentare in die Datei
231{
232 if (bPrintCSV)
233 return;
234
235 string sCommentSign = "#";
236
237 if (bPrintTeX)
238 sCommentSign = "%";
239
240 string sBuild = AutoVersion::YEAR;
241 sBuild += "-";
242 sBuild += AutoVersion::MONTH;
243 sBuild += "-";
244 sBuild += AutoVersion::DATE;
245 print(sCommentSign);
246 print(sCommentSign + " " + _lang.get("OUTPUT_PRINTLEGAL_LINE1"));
247 print(sCommentSign + " NumeRe: Framework für Numerische Rechnungen");
248 print(sCommentSign + "=============================================");
249 print(sCommentSign + " " + _lang.get("OUTPUT_PRINTLEGAL_LINE2", sVersion, sBuild));
250 print(sCommentSign + " " + _lang.get("OUTPUT_PRINTLEGAL_LINE3", sBuild.substr(0,4)));
251 print(sCommentSign + "");
252 print(sCommentSign + " " + _lang.get("OUTPUT_PRINTLEGAL_LINE4", getDate(false)));
253 print(sCommentSign + "");
254
255 if (bPrintTeX)
256 print(sCommentSign + " " + _lang.get("OUTPUT_PRINTLEGAL_TEX"));
257 else
258 print(sCommentSign + " " + _lang.get("OUTPUT_PRINTLEGAL_STD"));
259
260 print(sCommentSign);
261 return;
262}
263
265{
266 if (bFile == true && bFileOpen == true)
267 {
268 file_out.close(); // Schliesse die Datei
269 bFileOpen = false; // Setze den Boolean auf FALSE
270 }
271
272 return; // Mach nichts, wenn gar nicht in eine Datei geschrieben wurde,
273 // oder die Datei bereits geschlossen ist
274}
275
276
277void Output::print(string sOutput)
278{
279 if (sOutput.find("---------") != string::npos || sOutput.find("<<SUMBAR>>") != string::npos)
280 {
281 if (sOutput.find("<<SUMBAR>>") != string::npos)
282 {
283 unsigned int nLength = sOutput.length();
284
285 if (!bFile)
286 sOutput.assign(nLength, '-');
287 else
288 sOutput.assign(nLength, '-');
289 }
290 else if (!bFile)
291 sOutput.assign(sOutput.length(), '-');
292
293 if (bPrintTeX)
294 sOutput = "\\midrule";
295
296 bSumBar = true;
297 }
298
299 if (bFile)
300 {
301 if (!bFileOpen)
302 {
303 start(); // Wenn in eine Datei geschrieben werden soll, aber diese noch nicht geoeffnet wurde,
304 // rufe die Methode start() auf.
305 }
306
307 if (file_out.fail()) // Fehlermeldung, falls nicht in die Datei geschrieben werden kann
308 {
309 NumeReKernel::printPreFmt("*************************************************\n");
310 NumeReKernel::printPreFmt("|-> " + toSystemCodePage(_lang.get("OUTPUT_PRINT_INACCESSIBLE1")) + "\n");
311 NumeReKernel::printPreFmt("|-> " + toSystemCodePage(_lang.get("OUTPUT_PRINT_INACCESSIBLE2")) + "\n");
312 NumeReKernel::printPreFmt("| \"" + sFileName + "\"\n");
313 NumeReKernel::printPreFmt("| " + toSystemCodePage(_lang.get("OUTPUT_PRINT_INACCESSIBLE3")) + "\n");
314 NumeReKernel::printPreFmt("|-> " + toSystemCodePage(_lang.get("OUTPUT_PRINT_INACCESSIBLE4")) + "\n");
315 NumeReKernel::printPreFmt("*************************************************\n");
316 end(); // Schliesse ggf. die Datei
317 bFile = false; // Setze den Boolean auf FALSE
318 print(sOutput); // Wiederhole den Aufruf dieser Methode und schreibe von nun an auf die Konsole
319 }
320 else if (bSumBar && !bPrintTeX && !bPrintCSV) // Ausgabe in die Datei
321 file_out << "#" << sOutput.substr(1) << endl;
322 else
323 file_out << sOutput << endl;
324 }
325 else if (bSumBar) // Ausgabe auf die Konsole. Kann in Linux mit dem Umlenker '>' trotzdem in eine Datei ausgegeben werden.
326 {
327 NumeReKernel::printPreFmt("| " + sOutput.substr(4) + "\n");
328 }
329 else
330 NumeReKernel::printPreFmt(sOutput + "\n");
331
332 return;
333}
334
335
336void Output::generateFileName() // Generiert einen Dateinamen auf Basis des aktuellen Datums
337{ // Der Dateinamen hat das Format: data_YYYY-MM-DD_hhmmss.dat
338 string sTime;
339
340 if (sPath.find('"') != string::npos)
341 sTime = sPath.substr(1,sPath.length()-2);
342 else
343 sTime = sPath;
344
345 while (sTime.find('\\') != string::npos)
346 sTime[sTime.find('\\')] = '/';
347
348 sTime += "/" + sPluginPrefix + "_"; // Prefix laden
349 sTime += getDate(true); // Datum aus der Klasse laden
350 sTime += ".dat";
351 sFileName = sTime; // Dateinamen an sFileName zuweisen
352 return;
353}
354
355
356string Output::getDate(bool bForFile) // Der Boolean entscheidet, ob ein Dateinamen-Datum oder ein "Kommentar-Datum" gewuenscht ist
357{
358 time_t now = time(0); // Aktuelle Zeit initialisieren
359 tm *ltm = localtime(&now);
360 ostringstream Temp_str;
361 Temp_str << 1900+ltm->tm_year << "-"; //YYYY-
362
363 if(1+ltm->tm_mon < 10) // 0, falls Monat kleiner als 10
364 Temp_str << "0";
365
366 Temp_str << 1+ltm->tm_mon << "-"; // MM-
367
368 if(ltm->tm_mday < 10) // 0, falls Tag kleiner als 10
369 Temp_str << "0";
370
371 Temp_str << ltm->tm_mday; // DD
372
373 if(bForFile)
374 Temp_str << "_"; // Unterstrich im Dateinamen
375 else
376 Temp_str << ", um "; // Komma im regulaeren Datum
377
378 if(ltm->tm_hour < 10)
379 Temp_str << "0";
380
381 Temp_str << ltm->tm_hour; // hh
382
383 if(!bForFile)
384 Temp_str << ":"; // ':' im regulaeren Datum
385
386 if(ltm->tm_min < 10)
387 Temp_str << "0";
388
389 Temp_str << ltm->tm_min; // mm
390
391 if(!bForFile)
392 Temp_str << ":";
393
394 if(ltm->tm_sec < 10)
395 Temp_str << "0";
396
397 Temp_str << ltm->tm_sec; // ss
398
399 return Temp_str.str();
400}
401
402
403void Output::format(string** _sMatrix, long long int _nCol, long long int _nLine, const Settings& _option, bool bDontAsk, int nHeadLineCount)
404{
405 if (!nHeadLineCount)
406 nHeadLineCount = 1;
407
408 unsigned int nLongest[_nCol]; // Int fuer die laengste Zeichenkette: unsigned da string::length() einen unsigned zurueck gibt
409 unsigned int nLen = 0; // Int fuer die aktuelle Laenge: dito
410 string sPrint = ""; // String fuer die endgueltige Ausgabe
411 string sLabel = sFileName;
412
413 if (sLabel.find('/') != string::npos)
414 sLabel.erase(0,sLabel.rfind('/')+1);
415
416 if (sLabel.find(".tex") != string::npos)
417 sLabel.erase(sLabel.rfind(".tex"));
418
419 while (sLabel.find(' ') != string::npos)
420 sLabel[sLabel.find(' ')] = '_';
421
422 string cRerun = ""; // String fuer den erneuten Aufruf
423 // Wegen dem Rueckgabewert von string::length() sind alle Schleifenindices unsigned
424
425 if ((!bCompact || _nLine < 12) && !bPrintCSV)
426 {
427 // --> Laufe durch jedes Element der Tabelle <--
428 for (long long int j = 0; j < _nCol; j++)
429 {
430 nLongest[j] = 0;
431
432 for (long long int i = 0; i < _nLine; i++)
433 {
434 if (i >= nHeadLineCount && bPrintTeX)
435 {
436 if (_sMatrix[i][j].find('e') != string::npos)
437 {
438 _sMatrix[i][j] = _sMatrix[i][j].substr(0,_sMatrix[i][j].find('e'))
439 + "\\cdot10^{"
440 + (_sMatrix[i][j][_sMatrix[i][j].find('e')+1] == '-' ? "-" : "")
441 + _sMatrix[i][j].substr(_sMatrix[i][j].find_first_not_of('0', _sMatrix[i][j].find('e')+2))
442 + "}";
443 }
444
445 if (_sMatrix[i][j].find('%') != string::npos)
446 {
447 _sMatrix[i][j] = _sMatrix[i][j].substr(0,_sMatrix[i][j].find('%'))
448 + "\\"
449 + _sMatrix[i][j].substr(_sMatrix[i][j].find('%'));
450 }
451
452 if (_sMatrix[i][j].find("+/-") != string::npos)
453 {
454 _sMatrix[i][j] = _sMatrix[i][j].substr(0,_sMatrix[i][j].find("+/-"))
455 + "\\pm"
456 + _sMatrix[i][j].substr(_sMatrix[i][j].find("+/-")+3);
457 }
458
459 if (_sMatrix[i][j] == "inf")
460 {
461 _sMatrix[i][j] = "\\infty";
462 }
463
464 if (_sMatrix[i][j] == "-inf")
465 {
466 _sMatrix[i][j] = "-\\infty";
467 }
468 }
469
470 if (bPrintTeX)
471 _sMatrix[i][j] = replaceTeXControls(_sMatrix[i][j]);
472
473 nLen = _sMatrix[i][j].length(); // Erhalte die Laenge der aktuellen Zeichenkette
474
475 if (nLen > nLongest[j])
476 nLongest[j] = nLen; // Weise neue Laenge an nLongest zu, falls nLen > nLongest
477 }
478
479 nLongest[j] += 2;
480 }
481 }
482 else if (!bPrintCSV)
483 {
484 for (long long int j = 0; j < _nCol; j++)
485 {
486 nLongest[j] = 0;
487
488 for (long long int i = 0; i < _nLine; i++)
489 {
490 if (i < 5 || i >= _nLine - 5)
491 {
492 nLen = _sMatrix[i][j].length();
493
494 if (nLen > nLongest[j])
495 nLongest[j] = nLen;
496 }
497 }
498
499 nLongest[j] += 2;
500 }
501 }
502
503 if (bCompact)
504 {
505 for (long long int j = 0; j < _nCol; j++)
506 {
507 if (nLongest[j] < 7)
508 nLongest[j] = 7;
509 }
510 }
511
512 nLen = 0;
513
514 for (long long int j = 0; j < _nCol; j++)
515 nLen += nLongest[j];
516
517 if (bFile && !bPrintTeX && !bPrintCSV)
518 {
519 print("# " + _lang.get("OUTPUT_FORMAT_COMMENTLINE", sPluginName)); // Informative Ausgabe
520 print("#");
521 }
522 else if (bPrintTeX && !bPrintCSV)
523 {
524 print("% " + _lang.get("OUTPUT_FORMAT_COMMENTLINE", sPluginName));
525 print("%");
526 }
527
528 if (bPrintTeX)
529 {
530 if (_nLine < 30)
531 {
532 print("\\begin{table}[htb]");
533 print("\\centering");
534 sPrint = "\\begin{tabular}{";
535
536 for (long long int j = 0; j < _nCol; j++)
537 sPrint += "c";
538
539 sPrint += "}";
540 print(sPrint);
541 print("\\toprule");
542 }
543 else
544 {
545 sPrint = "\\begin{longtable}{";
546
547 for (long long int j = 0; j < _nCol; j++)
548 sPrint += "c";
549
550 sPrint += "}";
551 print(sPrint);
552 print("\\caption{" + _lang.get("OUTPUT_FORMAT_TEX_HEAD", sPluginName)+"}");
553 print("\\label{tab:" + sLabel + "}\\\\");
554 print("\\toprule");
555 sPrint = "";
556
557 for (int i = 0; i < nHeadLineCount; i++)
558 {
559 for (long long int j = 0; j < _nCol; j++)
560 sPrint += _sMatrix[i][j] + " & ";
561
562 sPrint = sPrint.substr(0,sPrint.length()-2) + "\\\\\n";
563 }
564
565 for (unsigned int i = 0; i < sPrint.length(); i++)
566 {
567 if (sPrint[i] == '_')
568 sPrint[i] = ' ';
569 }
570
571 print(sPrint);
572 print("\\midrule");
573 print("\\endfirsthead");
574 print("\\caption{"+_lang.get("OUTPUT_FORMAT_TEXLONG_CAPTION")+"}\\\\");
575 print("\\toprule");
576 print(sPrint);
577 print("\\midrule");
578 print("\\endhead");
579 print("\\midrule");
580 print("\\multicolumn{" + toString(_nCol) + "}{c}{--- \\emph{"+_lang.get("OUTPUT_FORMAT_TEXLONG_FOOT")+"} ---}\\\\");
581 print("\\bottomrule");
582 print("\\endfoot");
583 print("\\bottomrule");
584 print("\\endlastfoot");
585 }
586
587 sPrint = "";
588 }
589
590 if (bPrintCSV)
591 {
592 for (long long int i = 0; i < _nLine; i++)
593 {
594 for (long long int j = 0; j < _nCol; j++)
595 {
596 if (_sMatrix[i][j] != "---")
597 sPrint += _sMatrix[i][j];
598
599 sPrint += ",";
600 }
601
602 print(sPrint);
603 sPrint = "";
604 }
605 }
606 else
607 {
608 long long int nCol_0 = 0;
609 long long int nCol_1 = _nCol;
610 unsigned int nLine = 0;
611 int nNotRepeatFirstCol = 1;
612
613 if (!bFile && _option.getWindow()-4 < nLen)
614 {
615 for (long long int j = 0; j < _nCol; j++)
616 {
617 if (_option.getWindow()-4 < nLine+nLongest[j])
618 {
619 nCol_1 = j;
620 break;
621 }
622
623 nLine += nLongest[j];
624 }
625 }
626 else
627 nLine = nLen;
628
629 do
630 {
631 if (nCol_0 == nCol_1)
632 nCol_1 = _nCol;
633
634 for (long long int i = 0; i < _nLine; i++)
635 {
636 if (bPrintTeX && _nLine >= 30 && i < nHeadLineCount)
637 continue;
638
639 if (!bCompact || _nLine < 12 || (bCompact && _nLine >= 12 && (i < 5 || i >= _nLine - 5)))
640 {
641 for (long long int j = nCol_0*nNotRepeatFirstCol; j < nCol_1; j++)
642 {
643 if (i < nHeadLineCount && j == nCol_0*nNotRepeatFirstCol) // Erstes Element, erste Zeile?
644 {
645
646 if (bFile && !bPrintTeX)
647 sPrint = "#"; // Tabellenheader, Auskommentierung fuer GNUPlot
648 else if (!bFile)
649 sPrint = "| ";
650
651 for (unsigned int n = 0; n < nLongest[j] - _sMatrix[i][j].length() - 1; n++)
652 {
653 sPrint += " "; // Auf jeden Fall die Leerstellen zum Ausrichten ergaenzen
654 }
655 }
656 else // In allen anderen Faellen: ergaenze die fehlenden Leerstellen vor dem String
657 {
658 if (!bFile && j == nCol_0*nNotRepeatFirstCol)
659 sPrint = "| ";
660 else if (bPrintTeX && j)
661 sPrint += " &";
662
663 for (unsigned int n = 0; n < nLongest[j] - _sMatrix[i][j].length(); n++)
664 {
665 sPrint += " ";
666 }
667 }
668
669 if (bPrintTeX && i >= nHeadLineCount && _sMatrix[i][j] != "---" && !bSumBar)
670 sPrint += "$";
671 else if (bPrintTeX && !bSumBar)
672 sPrint += " ";
673
674 if (bPrintTeX && bSumBar)
675 {
676 if (_sMatrix[i][j].find(':') == string::npos)
677 sPrint += '$' + _sMatrix[i][j];
678 else
679 sPrint += _sMatrix[i][j].substr(0,_sMatrix[i][j].find(':')+2) + "$" + _sMatrix[i][j].substr(_sMatrix[i][j].find(':')+2);
680 }
681 else
682 sPrint += _sMatrix[i][j]; // Verknuepfe alle Elemente einer Zeile zu einem einzigen String
683
684 if (!nCol_0 && nCol_1 != _nCol && nNotRepeatFirstCol && i >= nHeadLineCount)
685 {
686 if (_sMatrix[i][0].find(':') != string::npos)
687 nNotRepeatFirstCol = 0;
688 }
689
690 if (bPrintTeX && i >= nHeadLineCount && _sMatrix[i][j] != "---")
691 sPrint += "$";
692
693 if (!nNotRepeatFirstCol && nCol_0 && !j)
694 j = nCol_0-1;
695 }
696
697 if (bPrintTeX && i < nHeadLineCount)
698 {
699 for (unsigned int k = 0; k < sPrint.length(); k++)
700 {
701 if (sPrint[k] == '_')
702 sPrint[k] = ' ';
703 }
704 }
705
706 if (bPrintTeX)
707 sPrint += "\\\\";
708
709 print(sPrint); // Ende der Zeile: Ausgabe in das Ziel
710 }
711 else if (bCompact && _nLine >= 10 && i == 5)
712 {
713 if (!bFile)
714 sPrint = "| ";
715
716 for (long long int j = nCol_0*nNotRepeatFirstCol; j < nCol_1; j++)
717 {
718 for (unsigned int k = 0; k < nLongest[j] - 5; k++)
719 {
720 if (j == nCol_0*nNotRepeatFirstCol && k == nLongest[j]-6)
721 break;
722
723 sPrint += " ";
724 }
725
726 sPrint += "[...]";
727
728 if (!nNotRepeatFirstCol && nCol_0 && !j)
729 j = nCol_0-1;
730 }
731
732 print(sPrint);
733 }
734
735 if (i == nHeadLineCount-1) // War das die erste Zeile? Mach' darunter eine schoene, auskommentierte Doppellinie
736 {
737 if (bFile)
738 {
739 if (bPrintTeX && _nLine < 30)
740 sPrint = "\\midrule";
741 else if (!bPrintTeX)
742 sPrint = "#";
743 }
744 else
745 sPrint = "| ";
746
747 if (!bPrintTeX)
748 {
749 if (!bFile)
750 {
751 sPrint.assign(nLine+2, '-');
752 }
753 else
754 {
755 sPrint.assign(nLen-1, '=');
756 sPrint.insert(0, "#");
757 }
758 }
759
760 print(sPrint);
761 }
762
763 sPrint = ""; // WICHTIG: sPrint auf einen leeren String setzen, sonst verknuepft man alle Zeilen iterativ miteinander... LOL
764 }
765
766 if (nCol_1 != _nCol)
767 {
768 if (nLine > 2)
769 {
770 sPrint.assign(nLine+2, '-');
771 print(sPrint);
772 sPrint.clear();
773 }
774
775 nCol_0 = nCol_1;
776 nLine = 0;
777
778 if (!nNotRepeatFirstCol)
779 {
780 nLine = nLongest[0];
781 }
782
783 for (long long int j = nCol_1; j < _nCol; j++)
784 {
785 if (_option.getWindow()-4 < nLine + nLongest[j])
786 {
787 nCol_1 = j;
788 break;
789 }
790
791 nLine += nLongest[j];
792 }
793 }
794 }
795 while (nCol_1 != _nCol);
796 }
797
798 if (sCommentLine.length() && !bPrintCSV)
799 {
800 if (bSumBar)
801 bSumBar = false;
802
803 if (bFile)
804 {
805 if (bPrintTeX)
806 {
807 print("%");
808 print("% " + sCommentLine);
809 }
810 else
811 {
812 print("#");
813 print("# " + sCommentLine); // Kommentarzeile fuer eventuell zusaetzliche Informationen
814 }
815 }
816 else
817 {
818 print("|");
820 }
821 }
822
823 if (bPrintTeX && _nLine < 30)
824 {
825 print("\\bottomrule");
826 print("\\end{tabular}");
827 print("\\caption{"+ _lang.get("OUTPUT_FORMAT_TEX_HEAD", sPluginName)+"}");
828 print("\\label{tab:" + sLabel + "}");
829 print("\\end{table}");
830 }
831 else if (bPrintTeX)
832 {
833 print("\\end{longtable}");
834 }
835
836 string sConsoleOut = "";
837
838 if (!bFile)
839 {
840 sConsoleOut += "| -- " + toSystemCodePage(_lang.get("OUTPUT_FORMAT_SUMMARY", toString(_nCol), toString(_nLine-nHeadLineCount), toString(_nCol*(_nLine-nHeadLineCount)))) + " --";
841 }
842 else
843 sConsoleOut += "|-> "+toSystemCodePage(_lang.get("OUTPUT_FORMAT_SUMMARY_FILE", toString(_nCol*(_nLine-nHeadLineCount)), sFileName));
844
845 if (_option.systemPrints())
846 NumeReKernel::printPreFmt(LineBreak(sConsoleOut, _option) + "\n");
847
848 if (bFile)
849 {
850 end();
851 return;
852 }
853 else
854 {
855 if (!bDontAsk)
856 {
857 NumeReKernel::print(toSystemCodePage(_lang.get("OUTPUT_FORMAT_ASK_FILEOUT")));
858 NumeReKernel::printPreFmt("|\n|<- ");
859 NumeReKernel::getline(cRerun);
860 }
861
862
863 if (cRerun == _lang.YES())
864 {
865 setCompact(false);
866 generateFileName(); // Im Voraus schon einmal den Dateinamen generieren
867 NumeReKernel::print(LineBreak(_lang.get("OUTPUT_FORMAT_ASK_FILENAME"), _option));
868 NumeReKernel::printPreFmt("| (-> " + sFileName + ")\n");
869 NumeReKernel::print(toSystemCodePage(_lang.get("COMMON_FILENAME")) + ":");
870 NumeReKernel::printPreFmt("|\n|<- " + sPath + "/");
871
872 NumeReKernel::getline(sPrint);
873
874 bFile = true;
875
876 if (sPrint != "0") // WICHTIG: Diese Bedingung liefert FALSE, wenn sPrint == "0";
877 {
878 setFileName(sPrint); // WICHTIG: Durch das Aufrufen dieser Funktion wird auch geprueft, ob der Dateiname moeglich ist
879 }
880 else
881 {
882 NumeReKernel::print(toSystemCodePage(_lang.get("OUTPUT_FORMAT_CONFIRMDEFAULT")));
883 }
884
885 format(_sMatrix, _nCol, _nLine, _option); // Nochmal dieselbe Funktion mit neuen Parametern aufrufen
886 }
887 else if (!bDontAsk)
888 {
889 NumeReKernel::print(LineBreak(_lang.get("OUTPUT_FORMAT_NOFILECREATED"), _option));
890 }
891 }
892
893 return;
894}
895
896// --> setzt sPluginPrefix auf _sPrefix <--
897void Output::setPrefix(string _sPrefix)
898{
899 sPluginPrefix = _sPrefix;
900 return;
901}
902
903// --> gibt sPluginPrefix zureuck <--
904string Output::getPrefix() const
905{
906 return sPluginPrefix;
907}
908
909
const std::string sVersion
This class implements the basic input/ output file system and provides functionalities to work with f...
Definition: filesystem.hpp:92
std::string sPath
Definition: filesystem.hpp:98
std::string ValidFileName(std::string _sFileName, const std::string sExtension=".dat", bool checkExtension=true, bool doCleanPath=true) const
This member function evaluates, whether the passed filename is a valid filename. One may supply a pre...
Definition: filesystem.cpp:280
std::string YES() const
Definition: language.hpp:197
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
Definition: language.cpp:292
static void getline(std::string &sLine)
This function is an implementation replacing the std::getline() function.
Definition: kernel.cpp:3621
static void printPreFmt(const std::string &__sLine, bool printingEnabled=true)
This member function appends the pre- formatted string to the buffer and informs the terminal that we...
Definition: kernel.cpp:2683
static void print(const std::string &__sLine, bool printingEnabled=true)
This member function appends the passed string as a new output line to the buffer and informs the ter...
Definition: kernel.cpp:2636
void print_legal()
Definition: output.cpp:230
std::string sCommentLine
Definition: output.hpp:43
void format(std::string **_sMatrix, long long int _nCol, long long int _nLine, const Settings &_option, bool bDontAsk=false, int nHeadLineCount=1)
Definition: output.cpp:403
std::string sPluginName
Definition: output.hpp:42
std::ofstream file_out
Definition: output.hpp:51
void start()
Definition: output.cpp:190
Output()
Definition: output.cpp:30
bool bPrintTeX
Definition: output.hpp:49
std::string getFileName() const
Definition: output.cpp:184
~Output()
Definition: output.cpp:54
std::string getPrefix() const
Definition: output.cpp:904
bool bPrintCSV
Definition: output.hpp:50
bool bFileOpen
Definition: output.hpp:46
std::string replaceTeXControls(const std::string &_sText)
Definition: output.cpp:94
void print(std::string sOutput)
Definition: output.cpp:277
void setPrefix(std::string _sPrefix)
Definition: output.cpp:897
void setPluginName(std::string _sPluginName)
Definition: output.cpp:204
bool bFile
Definition: output.hpp:45
bool isFile() const
Definition: output.cpp:147
void setStatus(bool bStatus)
Definition: output.cpp:65
std::string getCommentLine() const
Definition: output.cpp:224
std::string sFileName
Definition: output.hpp:41
bool bCompact
Definition: output.hpp:47
void end()
Definition: output.cpp:264
void generateFileName()
Definition: output.cpp:336
void reset()
Definition: output.cpp:75
std::string getPluginName() const
Definition: output.cpp:218
void setCompact(bool _bCompact)
Definition: output.cpp:141
std::string getDate(bool bForFile)
Definition: output.cpp:356
void setCommentLine(std::string _sCommentLine)
Definition: output.cpp:211
std::string sPluginPrefix
Definition: output.hpp:44
bool bSumBar
Definition: output.hpp:48
void setFileName(std::string sFile)
Definition: output.cpp:153
This class manages the setting values of the internal (kernel) settings of this application.
Definition: settings.hpp:663
bool systemPrints() const
Returns, whether system messages shall be printed to the terminal.
Definition: settings.hpp:1140
size_t getWindow(int nWindow=0) const
Returns the current window size of the terminal.
Definition: settings.hpp:1101
Language _lang
Definition: kernel.cpp:39
std::string toSystemCodePage(std::string)
Converts an internal to an external string. Does nothing currently.
static const char DATE[]
Definition: version.h:7
static const char MONTH[]
Definition: version.h:8
static const char YEAR[]
Definition: version.h:9
CONSTCD11 std::enable_if<!std::chrono::treat_as_floating_point< T >::value, T >::type trunc(T t) NOEXCEPT
Definition: date.h:1113
std::string toString(int)
Converts an integer to a string without the Settings bloat.
std::string LineBreak(std::string sOutput, const Settings &_option, bool bAllowDashBreaks, int nFirstIndent, int nIndent)
This function takes a string, splits it into multiple lines if it is too long and returns the result.
Definition: tools.cpp:2205