DOLFINx 0.12.0.0
DOLFINx C++
Loading...
Searching...
No Matches
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 <cstdint>
10#include <map>
11#include <mpi.h>
12#include <string>
13#include <string_view>
14#include <variant>
15#include <vector>
16
17namespace dolfinx
18{
19
29class Table
30{
31public:
34 enum class Reduction : std::uint8_t
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_view row, std::string_view col,
64 std::variant<std::string, int, double> value);
65
70 std::variant<std::string, int, double> get(std::string_view row,
71 std::string_view col) const;
72
77 Table reduce(MPI_Comm comm, Reduction reduction) const;
78
80 std::string name;
81
83 std::string str() const;
84
85private:
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
void set(std::string_view row, std::string_view col, std::variant< std::string, int, double > value)
Definition Table.cpp:41
Table & operator=(Table &&table)=default
Move assignment.
Table(const Table &table)=default
Copy constructor.
std::variant< std::string, int, double > get(std::string_view row, std::string_view col) const
Definition Table.cpp:57
~Table()=default
Destructor.
Reduction
Definition Table.h:35
std::string name
Table name.
Definition Table.h:80
Table(Table &&table)=default
Move constructor.
Table(std::string title="", bool right_justify=true)
Create empty table.
Definition Table.cpp:35
std::string str() const
Return string representation of the table.
Definition Table.cpp:202
Table reduce(MPI_Comm comm, Reduction reduction) const
Definition Table.cpp:71
Table & operator=(const Table &table)=default
Assignment operator.
Top-level namespace.
Definition defines.h:12