Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
GridAxis.icpp
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
19/**
20 * @file GridContainer/_impl/GridAxis.icpp
21 * @date May 12, 2014
22 * @author Nikolaos Apostolakos
23 */
24
25#include <algorithm>
26
27namespace Euclid {
28namespace GridContainer {
29
30template <typename T>
31GridAxis<T>::GridAxis(std::string name_, std::vector<T> values) : m_name(std::move(name_)), m_values(std::move(values)) {}
32
33template <typename T>
34size_t GridAxis<T>::size() const {
35 return m_values.size();
36}
37
38template <typename T>
39const std::string& GridAxis<T>::name() const {
40 return m_name;
41}
42
43template <typename T>
44const T& GridAxis<T>::operator[](size_t index) const {
45 return m_values[index];
46}
47
48template <typename T>
49auto GridAxis<T>::begin() const -> const_iterator {
50 return m_values.cbegin();
51}
52
53template <typename T>
54auto GridAxis<T>::end() const -> const_iterator {
55 return m_values.end();
56}
57
58template <typename T>
59template <typename U>
60bool GridAxis<T>::operator==(const GridAxis<U>& other) const {
61 bool same = false;
62 if (this->size() == other.size()) {
63 same = std::equal(this->begin(), this->end(), other.begin());
64 }
65 return same;
66}
67
68template <typename T>
69template <typename U>
70bool GridAxis<T>::operator!=(const GridAxis<U>& other) const {
71 return !this->operator==(other);
72}
73
74template <typename T>
75auto GridAxis<T>::infimum(const T& value) const -> const_iterator {
76 auto upper_bound = std::upper_bound(m_values.begin(), m_values.end(), value);
77 if (upper_bound == m_values.begin() || (upper_bound != m_values.end() && *upper_bound == value)) {
78 return upper_bound;
79 }
80 return upper_bound - 1;
81}
82
83} // end of namespace GridContainer
84} // end of namespace Euclid