Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
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
39
43
45 return m_values.front();
46}
47
49 return m_values.back();
50}
51
55
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
const std::pair< double, double > & back() const
Returns a reference to the last pair of the dataset.
Definition XYDataset.cpp:48
std::vector< std::pair< double, double > >::const_iterator const_iterator
Definition XYDataset.h:62
static XYDataset factory(std::vector< std::pair< double, double > > vector_pair)
Make a XYDataset object from a vector of pair of doubles.
Definition XYDataset.cpp:52
const std::pair< double, double > & front() const
Returns a reference to the first pair of the dataset.
Definition XYDataset.cpp:44
const_iterator begin() const
Returns a const iterator to the first pair of the dataset.
Definition XYDataset.cpp:36
std::vector< std::pair< double, double > > m_values
Definition XYDataset.h:155
const_iterator end() const
Returns a const iterator to the one after last pair dataset.
Definition XYDataset.cpp:40
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)