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