DOLFIN-X
DOLFIN-X C++ interface
Table.h
1 // Copyright (C) 2008-2011 Anders Logg
2 //
3 // This file is part of DOLFINX (https://www.fenicsproject.org)
4 //
5 // SPDX-License-Identifier: LGPL-3.0-or-later
6 
7 #pragma once
8 
9 #include <map>
10 #include <mpi.h>
11 #include <set>
12 #include <string>
13 #include <variant>
14 #include <vector>
15 
16 namespace dolfinx
17 {
18 class TableEntry;
19 
28 
29 class Table
30 {
31 public:
34  enum class Reduction
35  {
36  average,
37  max,
38  min
39  };
40 
42  Table(std::string title = "", bool right_justify = true);
43 
45  Table(const Table& table) = default;
46 
48  Table(Table&& table) = default;
49 
51  ~Table() = default;
52 
54  Table& operator=(const Table& table) = default;
55 
57  Table& operator=(Table&& table) = default;
58 
63  void set(std::string row, std::string col,
64  std::variant<std::string, int, double> value);
65 
70  std::variant<std::string, int, double> get(std::string row,
71  std::string col) const;
72 
77  Table reduce(MPI_Comm comm, Reduction reduction) const;
78 
80  std::string name;
81 
83  std::string str() const;
84 
85 private:
86  // Row and column names
87  std::vector<std::string> _rows, _cols;
88 
89  // Table entry values
90  std::map<std::pair<std::string, std::string>,
91  std::variant<std::string, int, double>>
92  _values;
93 
94  // True if we should right-justify the table entries
95  bool _right_justify;
96 };
97 
98 } // namespace dolfinx
dolfinx::Table::operator=
Table & operator=(const Table &table)=default
Assignment operator.
dolfinx::Table::str
std::string str() const
Return string representation of the table.
Definition: Table.cpp:196
dolfinx::Table::Table
Table(std::string title="", bool right_justify=true)
Create empty table.
Definition: Table.cpp:37
dolfinx::Table::Table
Table(const Table &table)=default
Copy constructor.
dolfinx::Table
This class provides storage and pretty-printing for tables. Example usage:
Definition: Table.h:30
dolfinx::Table::reduce
Table reduce(MPI_Comm comm, Reduction reduction) const
Do MPI reduction on Table.
Definition: Table.cpp:73
dolfinx::Table::operator=
Table & operator=(Table &&table)=default
Move assignment.
dolfinx::Table::~Table
~Table()=default
Destructor.
dolfinx::Table::Reduction
Reduction
Types of MPI reduction available for Table, to get the max, min or average values over an MPI_Comm.
Definition: Table.h:35
dolfinx::Table::get
std::variant< std::string, int, double > get(std::string row, std::string col) const
Get value of table entry.
Definition: Table.cpp:59
dolfinx::Table::Table
Table(Table &&table)=default
Move constructor.
dolfinx::Table::name
std::string name
Table name.
Definition: Table.h:80
dolfinx::Table::set
void set(std::string row, std::string col, std::variant< std::string, int, double > value)
Set table entry.
Definition: Table.cpp:43