Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/dolfinx/v0.9.0/cpp/doxygen/da/d75/Table_8h_source.html
DOLFINx  0.5.1
DOLFINx 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 <string>
12 #include <variant>
13 #include <vector>
14 
15 namespace dolfinx
16 {
17 
26 
27 class Table
28 {
29 public:
32  enum class Reduction
33  {
34  average,
35  max,
36  min
37  };
38 
40  Table(std::string title = "", bool right_justify = true);
41 
43  Table(const Table& table) = default;
44 
46  Table(Table&& table) = default;
47 
49  ~Table() = default;
50 
52  Table& operator=(const Table& table) = default;
53 
55  Table& operator=(Table&& table) = default;
56 
61  void set(std::string row, std::string col,
62  std::variant<std::string, int, double> value);
63 
68  std::variant<std::string, int, double> get(std::string row,
69  std::string col) const;
70 
75  Table reduce(MPI_Comm comm, Reduction reduction) const;
76 
78  std::string name;
79 
81  std::string str() const;
82 
83 private:
84  // Row and column names
85  std::vector<std::string> _rows, _cols;
86 
87  // Table entry values
88  std::map<std::pair<std::string, std::string>,
89  std::variant<std::string, int, double>>
90  _values;
91 
92  // True if we should right-justify the table entries
93  bool _right_justify;
94 };
95 
96 } // namespace dolfinx
This class provides storage and pretty-printing for tables. Example usage:
Definition: Table.h:28
Table(const Table &table)=default
Copy constructor.
Reduction
Types of MPI reduction available for Table, to get the max, min or average values over an MPI_Comm.
Definition: Table.h:33
std::variant< std::string, int, double > get(std::string row, std::string col) const
Get value of table entry.
Definition: Table.cpp:55
Table & operator=(const Table &table)=default
Assignment operator.
~Table()=default
Destructor.
std::string name
Table name.
Definition: Table.h:78
void set(std::string row, std::string col, std::variant< std::string, int, double > value)
Set table entry.
Definition: Table.cpp:39
Table(Table &&table)=default
Move constructor.
Table(std::string title="", bool right_justify=true)
Create empty table.
Definition: Table.cpp:33
std::string str() const
Return string representation of the table.
Definition: Table.cpp:192
Table reduce(MPI_Comm comm, Reduction reduction) const
Do MPI reduction on Table.
Definition: Table.cpp:69
Table & operator=(Table &&table)=default
Move assignment.