DOLFIN
DOLFIN C++ interface
Table.h
1 // Copyright (C) 2008-2011 Anders Logg
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // First added: 2008-07-19
19 // Last changed: 2011-10-07
20 
21 #ifndef __TABLE_H
22 #define __TABLE_H
23 
24 #include <map>
25 #include <set>
26 #include <vector>
27 #include <dolfin/common/Variable.h>
28 
29 namespace dolfin
30 {
31  class MPI;
32  class XMLTable;
33  class TableEntry;
34 
48 
49  class Table : public Variable
50  {
51  public:
52 
54  Table(std::string title="", bool right_justify=true);
55 
57  ~Table();
58 
60  TableEntry operator() (std::string row, std::string col);
61 
63  void set(std::string row, std::string col, int value);
64 
66  void set(std::string row, std::string col, std::size_t value);
67 
69  void set(std::string row, std::string col, double value);
70 
72  void set(std::string row, std::string col, std::string value);
73 
75  std::string get(std::string row, std::string col) const;
76 
78  double get_value(std::string row, std::string col) const;
79 
81  const Table& operator= (const Table& table);
82 
84  std::string str(bool verbose) const;
85 
87  std::string str_latex() const;
88 
89  private:
90 
91  // Rows
92  std::vector<std::string> rows;
93  std::set<std::string> row_set;
94 
95  // Columns
96  std::vector<std::string> cols;
97  std::set<std::string> col_set;
98 
99  // Table values as strings
100  std::map<std::pair<std::string, std::string>, std::string> values;
101 
102  // Table values as doubles
103  std::map<std::pair<std::string, std::string>, double> dvalues;
104 
105  // True if we should right-justify the table entries
106  bool _right_justify;
107 
108  // Allow MPI::all_reduce accessing dvalues
109  friend class MPI;
110 
111  // Allow XMLTable accessing data
112  friend class XMLTable;
113 
114  };
115 
117 
119  {
120  public:
121 
123  TableEntry(std::string row, std::string col, Table& table);
124 
126  ~TableEntry();
127 
129  const TableEntry& operator= (std::size_t value);
130 
132  const TableEntry& operator= (int value);
133 
135  const TableEntry& operator= (double value);
136 
138  const TableEntry& operator= (std::string value);
139 
141  operator std::string() const;
142 
143  private:
144 
145  // Row
146  std::string _row;
147 
148  // Column
149  std::string _col;
150 
151  // Table
152  Table& _table;
153 
154  };
155 
156 }
157 
158 #endif
TableEntry operator()(std::string row, std::string col)
Return table entry.
Definition: Table.cpp:47
const Table & operator=(const Table &table)
Assignment operator.
Definition: Table.cpp:174
double get_value(std::string row, std::string col) const
Get value of table entry.
Definition: Table.cpp:117
Definition: Table.h:49
Common base class for DOLFIN variables.
Definition: Variable.h:35
Output of XML representation of DOLFIN Table.
Definition: XMLTable.h:36
~Table()
Destructor.
Definition: Table.cpp:42
Definition: adapt.h:29
Definition: MPI.h:70
Table(std::string title="", bool right_justify=true)
Create empty table.
Definition: Table.cpp:35
std::string str_latex() const
Return informal string representation for LaTeX.
Definition: Table.cpp:278
std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: Table.cpp:191
This class represents an entry in a Table.
Definition: Table.h:118