Alexandria
2.19
Please provide a description of the project.
XYDataset
src
lib
XYDataset.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
26
#include <algorithm>
27
#include <iostream>
28
#include <utility>
29
30
#include "
ElementsKernel/Exception.h
"
31
#include "
XYDataset/XYDataset.h
"
32
33
namespace
Euclid
{
34
namespace
XYDataset {
35
36
XYDataset::const_iterator
XYDataset::begin()
const
{
37
return
m_values
.
cbegin
();
38
}
39
40
XYDataset::const_iterator
XYDataset::end()
const
{
41
return
m_values
.
cend
();
42
}
43
44
const
std::pair<double, double>
& XYDataset::front()
const
{
45
return
m_values
.
front
();
46
}
47
48
const
std::pair<double, double>
& XYDataset::back()
const
{
49
return
m_values
.
back
();
50
}
51
52
XYDataset
XYDataset::factory(
std::vector
<
std::pair<double, double>
> vector_pair) {
53
return
(
XYDataset
(
std::move
(vector_pair)));
54
}
55
56
XYDataset
XYDataset::factory(
const
std::vector<double>
& x_vector,
const
std::vector<double>
& y_vector) {
57
size_t
x_size = x_vector.
size
();
58
size_t
y_size = y_vector.
size
();
59
// Vector must have the same size
60
if
(x_size != y_size) {
61
throw
Elements::Exception
() <<
" Vectors must have "
62
<<
"the same size! x size: %d"
<< x_size <<
" y_size : %d"
<< y_size;
63
}
64
65
std::vector<std::pair<double, double>
> vector_pair;
66
vector_pair.
reserve
(x_size);
67
68
// Make the pair vector
69
transform(x_vector.
begin
(), x_vector.
end
(), y_vector.
begin
(), back_inserter(vector_pair),
70
[](
double
a,
double
b) {
return
std::make_pair
(a, b); });
71
72
return
(
XYDataset
(move(vector_pair)));
73
}
74
75
}
/* namespace XYDataset */
76
}
// end of namespace Euclid
std::move
T move(T... args)
Euclid::XYDataset::XYDataset::XYDataset
XYDataset(std::vector< std::pair< double, double >> values)
Constructor XYDataset interface represents an immutable data set.
Definition:
XYDataset.h:76
std::pair< double, double >
std::vector::reserve
T reserve(T... args)
Euclid::XYDataset::XYDataset
This module provides an interface for accessing two dimensional datasets (pairs of (X,...
Definition:
XYDataset.h:59
std::vector
STL class.
std::vector::size
T size(T... args)
std::vector::back
T back(T... args)
std::vector::front
T front(T... args)
Exception.h
Elements::Exception
Euclid::XYDataset::XYDataset::m_values
std::vector< std::pair< double, double > > m_values
Definition:
XYDataset.h:154
std::vector::cbegin
T cbegin(T... args)
std::make_pair
T make_pair(T... args)
std::vector::cend
T cend(T... args)
Euclid
Definition:
InstOrRefHolder.h:29
Euclid::XYDataset::XYDataset::const_iterator
std::vector< std::pair< double, double > >::const_iterator const_iterator
Definition:
XYDataset.h:62
XYDataset.h
Generated by
1.8.20