Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/v0.3.0/v0.9.0/cpp
DOLFINx  0.3.0
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 class TableEntry;
18 
27 
28 class Table
29 {
30 public:
33  enum class Reduction
34  {
35  average,
36  max,
37  min
38  };
39 
41  Table(std::string title = "", bool right_justify = true);
42 
44  Table(const Table& table) = default;
45 
47  Table(Table&& table) = default;
48 
50  ~Table() = default;
51 
53  Table& operator=(const Table& table) = default;
54 
56  Table& operator=(Table&& table) = default;
57 
62  void set(std::string row, std::string col,
63  std::variant<std::string, int, double> value);
64 
69  std::variant<std::string, int, double> get(std::string row,
70  std::string col) const;
71 
76  Table reduce(MPI_Comm comm, Reduction reduction) const;
77 
79  std::string name;
80 
82  std::string str() const;
83 
84 private:
85  // Row and column names
86  std::vector<std::string> _rows, _cols;
87 
88  // Table entry values
89  std::map<std::pair<std::string, std::string>,
90  std::variant<std::string, int, double>>
91  _values;
92 
93  // True if we should right-justify the table entries
94  bool _right_justify;
95 };
96 
97 } // namespace dolfinx
This class provides storage and pretty-printing for tables. Example usage:
Definition: Table.h:29
std::string name
Table name.
Definition: Table.h:79
Table reduce(MPI_Comm comm, Reduction reduction) const
Do MPI reduction on Table.
Definition: Table.cpp:70
std::string str() const
Return string representation of the table.
Definition: Table.cpp:193
Table(Table &&table)=default
Move constructor.
Table & operator=(Table &&table)=default
Move assignment.
Reduction
Types of MPI reduction available for Table, to get the max, min or average values over an MPI_Comm.
Definition: Table.h:34
Table(const Table &table)=default
Copy constructor.
void set(std::string row, std::string col, std::variant< std::string, int, double > value)
Set table entry.
Definition: Table.cpp:40
Table & operator=(const Table &table)=default
Assignment operator.
std::variant< std::string, int, double > get(std::string row, std::string col) const
Get value of table entry.
Definition: Table.cpp:56
Table(std::string title="", bool right_justify=true)
Create empty table.
Definition: Table.cpp:34
~Table()=default
Destructor.