Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
Table.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012-2021 Euclid Science Ground Segment
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 3.0 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
25#include "Table/Table.h"
27
28namespace Euclid {
29namespace Table {
30
31Table::Table(std::vector<Row> row_list) : m_row_list{std::move(row_list)}, m_column_info{} {
32 // Check we have some rows
33 if (m_row_list.empty()) {
34 throw Elements::Exception() << "Construction of empty tables is not allowed";
35 }
36 // We cannot initialize the m_column_info before this point because we must
37 // be sure the row list is not empty
38 m_column_info = m_row_list[0].getColumnInfo();
39 // Check that all the rows have the same column info
40 for (auto row : m_row_list) {
41 if (*row.getColumnInfo() != *m_column_info) {
42 throw Elements::Exception() << "Construction of table from rows with different "
43 << "columns is not allowed";
44 }
45 }
46}
47
48Table::Table(std::shared_ptr<ColumnInfo> column_info) : m_column_info(std::move(column_info)) {}
49
53
55 return m_row_list.size();
56}
57
58const Row& Table::operator[](std::size_t index) const {
59 if (index >= m_row_list.size()) {
60 throw Elements::Exception("Index out of bounds");
61 }
62 return m_row_list[index];
63}
64
66 return m_row_list.cbegin();
67}
68
70 return m_row_list.cend();
71}
72
73} // namespace Table
74} // end of namespace Euclid
Represents one row of a Table.
Definition Row.h:57
Represents a table.
Definition Table.h:49
std::size_t size() const
Returns the number of rows in the table.
Definition Table.cpp:54
std::vector< Row >::const_iterator const_iterator
Definition Table.h:52
const_iterator end() const
Returns a const iterator to the past-the-end row.
Definition Table.cpp:69
const Row & operator[](std::size_t index) const
Returns the row with the given index (zero based)
Definition Table.cpp:58
const_iterator begin() const
Returns a const iterator to the first row.
Definition Table.cpp:65
std::vector< Row > m_row_list
Definition Table.h:122
std::shared_ptr< ColumnInfo > m_column_info
Definition Table.h:123
std::shared_ptr< ColumnInfo > getColumnInfo() const
Returns a ColumnInfo object describing the columns of the table.
Definition Table.cpp:50
STL namespace.