Mantid
Loading...
Searching...
No Matches
TableRow.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9
10namespace Mantid::API {
11
15TableRow::TableRow(const TableRowHelper &trh) : m_row(trh.m_row), m_col(0), m_sep(",") {
16 for (size_t i = 0; i < trh.m_workspace->columnCount(); i++)
17 m_columns.emplace_back(trh.m_workspace->getColumn(i));
18 if (!m_columns.empty())
19 m_nrows = int(m_columns[0]->size());
20 else
21 m_nrows = 0;
22}
23
27void TableRow::row(size_t i) {
28 if (i < m_nrows) {
29 m_row = i;
30 m_col = 0;
31 } else {
32 throw std::range_error("Row index out of range.");
33 }
34}
35
41 if (m_row < m_nrows - 1) {
42 ++m_row;
43 m_col = 0;
44 return true;
45 }
46 return false;
47}
48
54 if (m_row > 0) {
55 --m_row;
56 m_col = 0;
57 return true;
58 }
59 return false;
60}
61
63const TableRow &TableRow::operator>>(bool &t) const {
64 Boolean b;
65 operator>>(b);
66 t = b;
67 return *this;
68}
69
75std::ostream &operator<<(std::ostream &s, const TableRow &row) {
76 if (row.m_columns.empty())
77 return s;
78 if (row.m_columns.size() == 1) {
79 row.m_columns[0]->print(row.row(), s);
80 return s;
81 }
82 auto ci = row.m_columns.cbegin();
83 for (; ci != row.m_columns.cend() - 1; ++ci) {
84 (*ci)->print(row.row(), s);
85 s << row.m_sep;
86 }
87 (*ci)->print(row.row(), s);
88 return s;
89}
90
91} // namespace Mantid::API
virtual Column_sptr getColumn(const std::string &name)=0
Gets the shared pointer to a column by name.
virtual size_t columnCount() const =0
Number of columns in the workspace.
Helper class used to create TableRow.
ITableWorkspace * m_workspace
Pointer to the TableWorkspace.
TableRow represents a row in a TableWorkspace.
Definition: TableRow.h:39
bool next()
Steps to the next row in the TableWorkspace if there is one.
Definition: TableRow.cpp:40
std::vector< Column_sptr > m_columns
Pointers to the columns in the ITableWorkspace.
Definition: TableRow.h:154
size_t m_col
Current column number (for streaming operations)
Definition: TableRow.h:156
size_t m_row
Row number in the TableWorkspace.
Definition: TableRow.h:155
bool prev()
Steps to the previous row in the TableWorkspace if there is one.
Definition: TableRow.cpp:53
const TableRow & operator>>(T &t) const
Output streaming operator.
Definition: TableRow.h:92
size_t row() const
Returns the row number of the TableRow.
Definition: TableRow.h:43
size_t m_nrows
Number of rows in the TableWorkspace.
Definition: TableRow.h:157
TableRow(const TableRowHelper &trh)
Constructor.
Definition: TableRow.cpp:15
std::string m_sep
Separator character(s) between elements in a text output.
Definition: TableRow.h:158
size_t size() const
Returns the number of rows in the TableWorkspace.
Definition: TableRow.h:45
MANTID_API_DLL std::ostream & operator<<(std::ostream &, const AlgorithmHistory &)
Prints a text representation.
As TableColumn stores its data in a std::vector bool type cannot be used in the same way as the other...
Definition: Column.h:209