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{
28class Table
29{
30public:
33 enum class Reduction : std::uint8_t
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#ifdef _MSC_VER
50 Table(Table&& table) noexcept = default;
51#else
52 Table(Table&& table) = default;
53#endif
54
56 ~Table() = default;
57
59 Table& operator=(const Table& table) = default;
60
62 Table& operator=(Table&& table) = default;
63
68 void set(std::string_view row, std::string_view col,
69 std::variant<std::string, int, double> value);
70
75 std::variant<std::string, int, double> get(std::string_view row,
76 std::string_view col) const;
77
82 Table reduce(MPI_Comm comm, Reduction reduction) const;
83
85 std::string name;
86
88 std::string str() const;
89
90private:
91 // Row and column names
92 std::vector<std::string> _rows, _cols;
93
94 // Table entry values
95 std::map<std::pair<std::string, std::string>,
96 std::variant<std::string, int, double>>
97 _values;
98
99 // True if we should right-justify the table entries
100 bool _right_justify;
101};
102
103} // namespace dolfinx
void set(std::string_view row, std::string_view col, std::variant< std::string, int, double > value)
Definition Table.cpp:42
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:58
~Table()=default
Destructor.
Reduction
Definition Table.h:34
std::string name
Table name.
Definition Table.h:85
Table(Table &&table)=default
Move constructor.
Table(std::string title="", bool right_justify=true)
Create empty table.
Definition Table.cpp:36
std::string str() const
Return string representation of the table.
Definition Table.cpp:203
Table reduce(MPI_Comm comm, Reduction reduction) const
Definition Table.cpp:72
Table & operator=(const Table &table)=default
Assignment operator.
Top-level namespace.
Definition defines.h:12