Alexandria
2.14.1
Please provide a description of the project.
Table
src
lib
Table.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2012-2020 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 "
ElementsKernel/Exception.h
"
26
#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)} ,
32
m_column_info {} {
33
// Check we have some rows
34
if
(m_row_list.empty()) {
35
throw
Elements::Exception
() <<
"Construction of empty tables is not allowed"
;
36
}
37
// We cannot initialize the m_column_info before this point because we must
38
// be sure the row list is not empty
39
m_column_info = m_row_list[0].getColumnInfo();
40
// Check that all the rows have the same column info
41
for
(
auto
row : m_row_list) {
42
if
(*row.getColumnInfo() != *m_column_info) {
43
throw
Elements::Exception
() <<
"Construction of table from rows with different "
44
<<
"columns is not allowed"
;
45
}
46
}
47
}
48
49
std::shared_ptr<ColumnInfo>
Table::getColumnInfo()
const
{
50
return
m_column_info
;
51
}
52
53
std::size_t
Table::size()
const
{
54
return
m_row_list
.size();
55
}
56
57
const
Row
& Table::operator [](
std::size_t
index)
const
{
58
if
(index >=
m_row_list
.size()) {
59
throw
Elements::Exception
(
"Index out of bounds"
);
60
}
61
return
m_row_list
[index];
62
}
63
64
Table::const_iterator
Table::begin()
const
{
65
return
m_row_list
.cbegin();
66
}
67
68
Table::const_iterator
Table::end()
const
{
69
return
m_row_list
.cend();
70
}
71
72
}
73
}
// 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:116
Euclid
Definition:
InstOrRefHolder.h:29
Euclid::Table::Table::m_column_info
std::shared_ptr< ColumnInfo > m_column_info
Definition:
Table.h:117
Table.h
Euclid::Table::Table::const_iterator
std::vector< Row >::const_iterator const_iterator
Definition:
Table.h:53
Generated by
1.8.17