Alexandria  2.19
Please provide a description of the project.
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 
28 namespace Euclid {
29 namespace Table {
30 
31 Table::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 
48 std::shared_ptr<ColumnInfo> Table::getColumnInfo() const {
49  return m_column_info;
50 }
51 
52 std::size_t Table::size() const {
53  return m_row_list.size();
54 }
55 
56 const Row& Table::operator[](std::size_t index) const {
57  if (index >= m_row_list.size()) {
58  throw Elements::Exception("Index out of bounds");
59  }
60  return m_row_list[index];
61 }
62 
63 Table::const_iterator Table::begin() const {
64  return m_row_list.cbegin();
65 }
66 
67 Table::const_iterator Table::end() const {
68  return m_row_list.cend();
69 }
70 
71 } // namespace Table
72 } // end of namespace Euclid
std::shared_ptr
STL class.
std::move
T move(T... args)
std::vector
STL class.
Exception.h
Elements::Exception
Euclid::Table::Table
Represents a table.
Definition: Table.h:49
std::size_t
Euclid::Table::Row
Represents one row of a Table.
Definition: Row.h:64
Euclid::Table::Table::m_row_list
std::vector< Row > m_row_list
Definition: Table.h:115
Euclid
Definition: InstOrRefHolder.h:29
Euclid::Table::Table::m_column_info
std::shared_ptr< ColumnInfo > m_column_info
Definition: Table.h:116
Table.h
Euclid::Table::Table::const_iterator
std::vector< Row >::const_iterator const_iterator
Definition: Table.h:52