GEOS
TableData.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_TABLEDATA_HPP
21 #define GEOS_COMMON_FORMAT_TABLE_TABLEDATA_HPP
22 
23 #include "common/Units.hpp"
24 #include "common/DataTypes.hpp"
25 #include "common/format/Format.hpp"
26 
27 namespace geos
28 {
29 
33 class TableData
34 {
35 public:
41  template< typename ... Args >
42  void addRow( Args const & ... args );
43 
48  void addRow( std::vector< string > const & row );
49 
53  void clear();
54 
58  std::vector< std::vector< string > > const & getTableDataRows() const;
59 
64  std::vector< string > const & getErrorMsgs() const;
65 
66 private:
67 
69  std::vector< std::vector< string > > m_rows;
70 
72  std::vector< string > m_errorsMsg;
73 
74 };
75 
80 {
81 public:
82 
84  using RowType = real64;
86  using ColumnType = real64;
87 
90  {
93  std::vector< string > headerNames;
96  };
97 
105  template< typename T >
106  void addCell( RowType rowValue, ColumnType columnValue, T const & value );
107 
115  arraySlice1d< real64 const > columnAxisValues,
117 
127  units::Unit const valueUnit,
128  ArrayOfArraysView< real64 const > const coordinates,
129  string_view rowAxisDescription,
130  string_view columnAxisDescription );
131 
142  string_view rowFmt = "{}", string_view columnFmt = "{}" ) const;
143 
144 private:
146  std::map< RowType, std::map< ColumnType, string > > m_data;
147 
149  std::set< real64 > m_columnValues;
150 };
151 
152 template< typename ... Args >
153 void TableData::addRow( Args const &... args )
154 {
155  std::vector< string > m_cellsValue;
156  ( [&] {
157  static_assert( has_formatter_v< decltype(args) >, "Argument passed in addRow cannot be converted to string" );
158  string const cellValue = GEOS_FMT( "{}", args );
159  m_cellsValue.push_back( cellValue );
160  } (), ...);
161 
162  addRow( m_cellsValue );
163 }
164 
165 template< typename T >
166 void TableData2D::addCell( real64 const rowValue, real64 const columnValue, T const & value )
167 {
168  static_assert( has_formatter_v< decltype(value) >, "Argument passed in addCell cannot be converted to string" );
169  m_columnValues.insert( columnValue );
170  m_data[rowValue][columnValue] = GEOS_FMT( "{}", value );
171 }
172 
173 }
174 #endif /* GEOS_COMMON_FORMAT_TABLE_TABLEDATA_HPP */
Enumerates the Units that are in use in GEOS and regroups useful conversion and formatting functions.
Unit
Enumerator of available unit types. Units are in SI by default.
Definition: Units.hpp:54
Class for managing 2D table m_data.
Definition: TableData.hpp:80
real64 RowType
Type real64 for a row.
Definition: TableData.hpp:84
TableData2D::TableDataHolder convertTable2D(arrayView1d< real64 const > const values, units::Unit const valueUnit, ArrayOfArraysView< real64 const > const coordinates, string_view rowAxisDescription, string_view columnAxisDescription)
void addCell(RowType rowValue, ColumnType columnValue, T const &value)
Add a cell to the table. If necessary, create automatically the containing column & row.
Definition: TableData.hpp:166
void collectTableValues(arraySlice1d< real64 const > rowAxisValues, arraySlice1d< real64 const > columnAxisValues, arrayView1d< real64 const > values)
Collects all the values needed to build the table.
TableDataHolder buildTableData(string_view dataDescription, string_view rowFmt="{}", string_view columnFmt="{}") const
real64 ColumnType
Type real64 for a column.
Definition: TableData.hpp:86
Class for managing table data.
Definition: TableData.hpp:34
void clear()
Reset data in the table.
std::vector< std::vector< string > > const & getTableDataRows() const
void addRow(Args const &... args)
Add a row to the table. The values passed to addRow (can be any type).
Definition: TableData.hpp:153
std::vector< string > const & getErrorMsgs() const
Get all error messages.
void addRow(std::vector< string > const &row)
Add a row to the table.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:180
LvArray::ArrayOfArraysView< T, INDEX_TYPE const, CONST_SIZES, LvArray::ChaiBuffer > ArrayOfArraysView
View of array of variable-sized arrays. See LvArray::ArrayOfArraysView for details.
Definition: DataTypes.hpp:286
double real64
64-bit floating point type.
Definition: DataTypes.hpp:99
ArraySlice< T, 1, USD > arraySlice1d
Alias for 1D array slice.
Definition: DataTypes.hpp:184
std::string_view string_view
String type.
Definition: DataTypes.hpp:94
Struct containing conversion informations.
Definition: TableData.hpp:90
TableData tableData
TableData to be built.
Definition: TableData.hpp:95
std::vector< string > headerNames
Definition: TableData.hpp:93