ComPWA
Common Partial-Wave-Analysis Framework
TableFormatter.cpp
Go to the documentation of this file.
1 // Copyright (c) 2015 The ComPWA Team.
2 // This file is part of the ComPWA framework, check
3 // https://github.com/ComPWA/ComPWA/license.txt for details.
4 
5 #include "TableFormatter.hpp"
6 
7 namespace ComPWA {
8 
10  *OutputStream << sep;
11  for (unsigned int i = 0; i < TotalWidth - 1; i++)
12  *OutputStream << "-";
13  *OutputStream << sep << std::endl;
14 }
15 
17 
19  delim();
20  for (unsigned int i = 0; i < ColumnTitle.size(); i++)
21  *OutputStream << "| " << std::setw(ColumnWidth.at(i)) << ColumnTitle.at(i)
22  << " ";
23  *OutputStream << "|" << std::endl;
24  delim();
25 }
26 
27 void TableFormatter::addColumn(std::string title, unsigned int fixlength) {
28  unsigned int length;
29  if (fixlength != 999)
30  length = fixlength;
31  else
32  length = title.length();
33  ColumnWidth.push_back(length);
34  TotalWidth += length + 3;
35  ColumnTitle.push_back(title);
36 }
37 
39  CurCol = 0;
40  CurRow = 0;
41  TotalWidth = 0;
42  ColumnWidth.clear();
43  ColumnTitle.clear();
44 }
45 
46 void TableFormatter::trimString(std::string &src) {
47  // remove all final zeros
48  char chr = '0';
49  std::string::size_type pos2 = src.find_last_not_of(chr, src.length());
50  if (pos2 + 1 < src.length())
51  src.erase(pos2 + 1, src.length());
52 }
53 
54 } // namespace ComPWA
void trimString(std::string &src)
std::ostream * OutputStream
std::vector< std::string > ColumnTitle
std::vector< unsigned int > ColumnWidth
virtual void addColumn(std::string title, unsigned int fixlength=999)