GEOS
TableFormatter.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 TotalEnergies
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
20 #ifndef GEOS_COMMON_FORMAT_TABLE_TABLEFORMATTER_HPP
21 #define GEOS_COMMON_FORMAT_TABLE_TABLEFORMATTER_HPP
22 
23 #include "TableData.hpp"
24 #include "TableLayout.hpp"
25 #include "TableTypes.hpp"
26 
27 namespace geos
28 {
29 
34 {
35 
36 public:
38  using RowsCellInput = std::vector< std::vector< TableData::CellData > >;
40  using CellLayoutRows = std::vector< std::vector< TableLayout::CellLayout > >;
41 
42 
43 protected:
44 
47 
48  TableFormatter() = default;
49 
54  TableFormatter( TableLayout const & tableLayout );
55 };
56 
61 {
62 public:
63 
69  {}
70 
75  TableCSVFormatter( TableLayout const & tableLayout );
76 
80  string headerToString() const;
81 
87  string dataToString( TableData const & tableData ) const;
88 
95  template< typename DATASOURCE >
96  string toString( DATASOURCE const & tableData ) const;
97 
98 };
99 
105 template<>
106 string TableCSVFormatter::toString< TableData >( TableData const & tableData ) const;
107 
108 
113 {
114 public:
115 
121  {}
122 
127  TableTextFormatter( TableLayout const & tableLayout );
128 
133  string toString() const;
134 
140  template< typename DATASOURCE >
141  string toString( DATASOURCE const & tableData ) const;
142 
143 private:
144 
146  static constexpr char m_verticalLine = '|';
148  static constexpr char m_horizontalLine = '-';
149 
150 
159  void initalizeTableLayout( TableLayout & tableLayout,
160  TableData const & tableData,
161  CellLayoutRows & cellsDataLayout,
162  CellLayoutRows & cellsHeaderLayout,
163  string & separatorLine,
164  size_t & nbEnabledColumn ) const;
173  void outputTable( TableLayout & tableLayout,
174  std::ostringstream & tableOutput,
175  CellLayoutRows const & cellsHeader,
176  CellLayoutRows const & cellsData,
177  string_view separatorLine,
178  size_t & nbEnabledColumn ) const;
179 
184  void setLinks( std::vector< TableLayout::Column > & columns ) const;
185 
191  void populateHeaderCellsLayout( TableLayout & tableLayout,
192  CellLayoutRows & cellsDataLayout ) const;
193 
200  void populateDataCellsLayout( TableLayout & tableLayout,
201  CellLayoutRows & cellsDataLayout,
202  RowsCellInput & inputDataValues ) const;
203 
214  void updateColumnMaxLength( TableLayout & tableLayout,
215  CellLayoutRows & cellHeaderLength,
216  CellLayoutRows & cellsDataLayout ) const;
217 
226  void adjustTableWidth( TableLayout & tableLayout,
227  CellLayoutRows & cellsHeaderLayout,
228  CellLayoutRows & cellsDataLayout,
229  string & separatorLine,
230  size_t & nbEnabledColumn ) const;
231 
238  void adjustColumnWidth( CellLayoutRows & cells,
239  size_t nbHiddenColumns,
240  size_t const paddingCharacters ) const;
241 
248  void outputTitleRow( TableLayout & tableLayout,
249  std::ostringstream & tableOutput,
250  string_view separatorLine ) const;
251 
259  void formatCell( TableLayout & tableLayout,
260  std::ostringstream & tableOutput,
261  TableLayout::CellLayout const & cell,
262  size_t idxLine ) const;
263 
273  void outputLines( TableLayout & tableLayout,
274  CellLayoutRows const & cellsLayout,
275  std::ostringstream & tableOutput,
276  std::vector< size_t > const & nbLinesRow,
277  CellType sectionType,
278  string_view separatorLine,
279  size_t & nbEnabledColumn ) const;
280 };
281 
287 template<>
288 string TableTextFormatter::toString< TableData >( TableData const & tableData ) const;
289 }
290 
291 #endif /* GEOS_COMMON_FORMAT_TABLE_TABLEFORMATTER_HPP */
class for CSV formatting
string toString(DATASOURCE const &tableData) const
Convert a data source to a CSV string.
TableCSVFormatter()
Construct a new Table Formatter.
string headerToString() const
string dataToString(TableData const &tableData) const
Convert the table data to a CSV string..
TableCSVFormatter(TableLayout const &tableLayout)
Construct a new Table Formatter from a tableLayout.
Class for managing table data.
Definition: TableData.hpp:35
abstract class for formatting table data
TableFormatter(TableLayout const &tableLayout)
Construct a new Table Formatter from a tableLayout.
TableLayout m_tableLayout
Layout for a table.
std::vector< std::vector< TableLayout::CellLayout > > CellLayoutRows
Represent the Table (header or values) structured.
std::vector< std::vector< TableData::CellData > > RowsCellInput
Represent the TableData values.
Class for setup the table layout.
Definition: TableLayout.hpp:36
class for log formatting
TableTextFormatter()
Construct a new TableFormatter.
TableTextFormatter(TableLayout const &tableLayout)
Construct a new TableFormatter from a tableLayout.
string toString(DATASOURCE const &tableData) const
Convert a data source to a table string.
string toString() const
CellType
The different type a cell can handle.
Definition: TableTypes.hpp:33
std::string_view string_view
String type.
Definition: DataTypes.hpp:94
Structure grouping the cell information to display it in a table (content, type, alignment,...
Definition: TableLayout.hpp:73