ComPWA
Common Partial-Wave-Analysis Framework
TableFormatter.hpp
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 #ifndef CORE_TABLEFORMATER_HPP_
6 #define CORE_TABLEFORMATER_HPP_
7 
8 #include <iomanip>
9 #include <ostream>
10 #include <string>
11 #include <vector>
12 
13 #include "Core/FitParameter.hpp"
14 
15 namespace ComPWA {
16 
18 public:
19  TableFormatter(std::ostream *output)
20  : OutputStream(output), CurRow(0), CurCol(0), TotalWidth(0) {
21  sep = "|";
22  pm = "+-";
23  firstSep = sep;
24  lastSep = sep;
25  };
26 
27  virtual ~TableFormatter() {}
28 
29  virtual void reset();
30 
31  virtual void delim();
32 
33  virtual void footer();
34 
35  virtual void header();
36 
37  virtual void addColumn(std::string title, unsigned int fixlength = 999);
38 
39  void trimString(std::string &src);
40 
41  template <typename T> TableFormatter &operator<<(T in) {
42  if (CurCol == 0)
43  *OutputStream << firstSep + " ";
44  else
45  *OutputStream << " " << sep << " ";
46  *OutputStream << std::setw(ColumnWidth.at(CurCol)) << in;
47  CurCol++;
48  if (CurCol == ColumnWidth.size()) {
49  *OutputStream << " " << lastSep << std::endl;
50  CurRow++;
51  CurCol = 0;
52  }
53  return *this;
54  };
55 
56 protected:
57  std::ostream *OutputStream;
58  std::vector<unsigned int> ColumnWidth;
59  std::vector<std::string> ColumnTitle;
60 
61  unsigned int CurRow;
62  unsigned int CurCol;
63  unsigned int TotalWidth;
64  std::string sep;
65  std::string firstSep;
66  std::string lastSep;
67  std::string pm;
68 };
69 
70 } // namespace ComPWA
71 
72 #endif
void trimString(std::string &src)
std::ostream * OutputStream
TableFormatter(std::ostream *output)
TableFormatter & operator<<(T in)
std::vector< std::string > ColumnTitle
std::vector< unsigned int > ColumnWidth
virtual void addColumn(std::string title, unsigned int fixlength=999)