CbmRoot
Loading...
Searching...
No Matches
CbmQaReportTable.h
Go to the documentation of this file.
1/* Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10#pragma once
11
12#include "CbmQaReportElement.h"
13#include "CbmQaReportEngine.h"
14
15class CbmQaTable;
16
17namespace cbm::qa::report
18{
21 class Table : public Element {
22 private:
23 static constexpr std::string_view kDefaultFormat = "{:.3}";
24
25 public:
29 explicit Table(std::string_view label, std::string_view title = "");
30
36 Table(std::string_view label, int nRows, int nCols, std::string_view title = "");
37
39 virtual ~Table(){};
40
44 const std::string& operator()(int iRow, int iCol) const { return fvsTable[GetIndex(iRow, iCol)]; }
45
49 std::string& operator()(int iRow, int iCol) { return fvsTable[GetIndex(iRow, iCol)]; }
50
53 std::string GetBody(const Engine& engine) const override { return engine.TableBody(*this); }
54
56 const std::string& GetCaption() const { return fsCaption; }
57
61 const std::string& GetCell(int iRow, int iCol) const { return fvsTable[GetIndex(iRow, iCol)]; }
62
65 const std::string& GetColumnTitle(int iCol) const { return fvsTableHeader[iCol]; }
66
68 int GetNofRows() const { return fNofRows; }
69
71 int GetNofCols() const { return fNofCols; }
72
75 void SetCaption(std::string_view caption) { fsCaption = caption; }
76
88 void Set(const CbmQaTable* pQaTable, const std::string& cellFormat = std::string(kDefaultFormat));
89
94 void SetCell(int iRow, int iCol, std::string_view cell) { fvsTable[GetIndex(iRow, iCol)] = cell; }
95
98 void SetColumnTitle(int iCol, std::string_view title) { fvsTableHeader[iCol] = title; };
99
100 protected:
102 inline int GetIndex(int iRow, int iCol) const { return iRow * fNofCols + iCol; }
103
104 private:
105 std::vector<std::string> fvsTable;
106 std::vector<std::string> fvsTableHeader;
107 std::string fsCaption = "";
108 int fNofRows = 0;
109 int fNofCols = 0;
110 };
111} // namespace cbm::qa::report
Base class for the report element (header)
TODO: SZh, 30.01.2023: Override THistPainter::PaintText() to add zeroes in tables.
Definition CbmQaTable.h:24
Interface for the report element.
A base abstract class to provide an interface for element body (a visitor in the Visitor pattern)
virtual std::string TableBody(const Table &table) const =0
Creates a body for table.
Table element in the report.
Table(std::string_view label, std::string_view title="")
Constructor.
const std::string & operator()(int iRow, int iCol) const
Cell access operator.
const std::string & GetColumnTitle(int iCol) const
Gets column title.
int GetNofRows() const
Gets number of rows.
void SetCell(int iRow, int iCol, std::string_view cell)
Sets cell.
void Set(const CbmQaTable *pQaTable, const std::string &cellFormat=std::string(kDefaultFormat))
Sets a table from CbmQaTable.
virtual ~Table()
Destructor.
std::vector< std::string > fvsTable
int GetNofCols() const
Gets number of columns.
const std::string & GetCaption() const
Gets caption.
std::vector< std::string > fvsTableHeader
std::string GetBody(const Engine &engine) const override
Gets body of the element.
const std::string & GetCell(int iRow, int iCol) const
Gets cell.
int GetIndex(int iRow, int iCol) const
Gets index of cell in the table vector.
void SetColumnTitle(int iCol, std::string_view title)
Sets column title.
std::string & operator()(int iRow, int iCol)
Cell access operator.
static constexpr std::string_view kDefaultFormat
Default format of double entries.
void SetCaption(std::string_view caption)
Sets caption.