Alexandria 2.25.0
SDC-CH common library for the Euclid project
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
31#include "XYDataset/XYDataset.h"
32
33namespace Euclid {
34namespace XYDataset {
35
36XYDataset::const_iterator XYDataset::begin() const {
37 return m_values.cbegin();
38}
39
40XYDataset::const_iterator XYDataset::end() const {
41 return m_values.cend();
42}
43
44const std::pair<double, double>& XYDataset::front() const {
45 return m_values.front();
46}
47
48const std::pair<double, double>& XYDataset::back() const {
49 return m_values.back();
50}
51
52XYDataset XYDataset::factory(std::vector<std::pair<double, double>> vector_pair) {
53 return (XYDataset(std::move(vector_pair)));
54}
55
56XYDataset 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
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
T back(T... args)
T cbegin(T... args)
This module provides an interface for accessing two dimensional datasets (pairs of (X,...
Definition: XYDataset.h:59
std::vector< std::pair< double, double > >::const_iterator const_iterator
Definition: XYDataset.h:62
std::vector< std::pair< double, double > > m_values
Definition: XYDataset.h:155
XYDataset(std::vector< std::pair< double, double > > values)
Constructor XYDataset interface represents an immutable data set.
Definition: XYDataset.h:76
T cend(T... args)
T front(T... args)
T make_pair(T... args)
T move(T... args)
T reserve(T... args)
T size(T... args)