Loading...
Searching...
No Matches
Table.h
// Copyright (C) 2008-2011 Anders Logg
//
// This file is part of DOLFIN.
//
// DOLFIN is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DOLFIN is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
//
// First added: 2008-07-19
// Last changed: 2011-10-07
#ifndef __TABLE_H
#define __TABLE_H
#include <map>
#include <set>
#include <vector>
#include <dolfin/common/Variable.h>
namespace dolfin
{
class MPI;
class XMLTable;
class TableEntry;
class Table : public Variable
{
public:
Table(std::string title="", bool right_justify=true);
~Table();
TableEntry operator() (std::string row, std::string col);
void set(std::string row, std::string col, int value);
void set(std::string row, std::string col, std::size_t value);
void set(std::string row, std::string col, double value);
void set(std::string row, std::string col, std::string value);
std::string get(std::string row, std::string col) const;
double get_value(std::string row, std::string col) const;
const Table& operator= (const Table& table);
std::string str(bool verbose) const;
std::string str_latex() const;
private:
// Rows
std::vector<std::string> rows;
std::set<std::string> row_set;
// Columns
std::vector<std::string> cols;
std::set<std::string> col_set;
// Table values as strings
std::map<std::pair<std::string, std::string>, std::string> values;
// Table values as doubles
std::map<std::pair<std::string, std::string>, double> dvalues;
// True if we should right-justify the table entries
bool _right_justify;
// Allow MPI::all_reduce accessing dvalues
friend class MPI;
// Allow XMLTable accessing data
friend class XMLTable;
};
class TableEntry
{
public:
TableEntry(std::string row, std::string col, Table& table);
~TableEntry();
const TableEntry& operator= (std::size_t value);
const TableEntry& operator= (int value);
const TableEntry& operator= (double value);
const TableEntry& operator= (std::string value);
operator std::string() const;
private:
// Row
std::string _row;
// Column
std::string _col;
// Table
Table& _table;
};
}
#endif
dolfin::MPI
Definition MPI.h:71
dolfin::TableEntry
This class represents an entry in a Table.
Definition Table.h:119
dolfin::TableEntry::TableEntry
TableEntry(std::string row, std::string col, Table &table)
Create table entry.
Definition Table.cpp:319
dolfin::TableEntry::~TableEntry
~TableEntry()
Destructor.
Definition Table.cpp:325
dolfin::TableEntry::operator=
const TableEntry & operator=(std::size_t value)
Assign value to table entry.
Definition Table.cpp:330
dolfin::Table
Definition Table.h:50
dolfin::Table::set
void set(std::string row, std::string col, int value)
Set value of table entry.
Definition Table.cpp:53
dolfin::Table::get_value
double get_value(std::string row, std::string col) const
Get value of table entry.
Definition Table.cpp:117
dolfin::Table::str
std::string str(bool verbose) const
Return informal string representation (pretty-print).
Definition Table.cpp:191
dolfin::Table::operator=
const Table & operator=(const Table &table)
Assignment operator.
Definition Table.cpp:174
dolfin::Table::~Table
~Table()
Destructor.
Definition Table.cpp:42
dolfin::Table::get
std::string get(std::string row, std::string col) const
Get value of table entry.
Definition Table.cpp:100
dolfin::Table::str_latex
std::string str_latex() const
Return informal string representation for LaTeX.
Definition Table.cpp:278
dolfin::Table::Table
Table(std::string title="", bool right_justify=true)
Create empty table.
Definition Table.cpp:35
dolfin::Table::operator()
TableEntry operator()(std::string row, std::string col)
Return table entry.
Definition Table.cpp:47
dolfin::Variable::Variable
Variable()
Create unnamed variable.
Definition Variable.cpp:31
dolfin::XMLTable
Output of XML representation of DOLFIN Table.
Definition XMLTable.h:37
dolfin
Definition adapt.h:30