##// END OF EJS Templates
Fixes missing return
Alexandre Leroux -
r924:b6b0633c1ea5
parent child
Show More
@@ -1,99 +1,101
1 1 #include <Data/OptionalAxis.h>
2 2
3 3 #include "Data/ArrayData.h"
4 4
5 5 OptionalAxis::OptionalAxis() : m_Defined{false}, m_Data{nullptr}, m_Unit{}
6 6 {
7 7 }
8 8
9 9 OptionalAxis::OptionalAxis(std::shared_ptr<ArrayData<1> > data, Unit unit)
10 10 : m_Defined{true}, m_Data{data}, m_Unit{std::move(unit)}
11 11 {
12 12 if (m_Data == nullptr) {
13 13 throw std::invalid_argument{"Data can't be null for a defined axis"};
14 14 }
15 15 }
16 16
17 17 OptionalAxis::OptionalAxis(const OptionalAxis &other)
18 18 : m_Defined{other.m_Defined},
19 19 m_Data{other.m_Data ? std::make_shared<ArrayData<1> >(*other.m_Data) : nullptr},
20 20 m_Unit{other.m_Unit}
21 21 {
22 22 }
23 23
24 24 OptionalAxis &OptionalAxis::operator=(OptionalAxis other)
25 25 {
26 26 std::swap(m_Defined, other.m_Defined);
27 27 std::swap(m_Data, other.m_Data);
28 28 std::swap(m_Unit, other.m_Unit);
29
30 return *this;
29 31 }
30 32
31 33 bool OptionalAxis::isDefined() const
32 34 {
33 35 return m_Defined;
34 36 }
35 37
36 38 double OptionalAxis::at(int index) const
37 39 {
38 40 if (m_Defined) {
39 41 return (index >= 0 && index < m_Data->size()) ? m_Data->at(index)
40 42 : std::numeric_limits<double>::quiet_NaN();
41 43 }
42 44 else {
43 45 return std::numeric_limits<double>::quiet_NaN();
44 46 }
45 47 }
46 48
47 49 std::pair<double, double> OptionalAxis::bounds() const
48 50 {
49 51 if (!m_Defined || m_Data->size() == 0) {
50 52 return std::make_pair(std::numeric_limits<double>::quiet_NaN(),
51 53 std::numeric_limits<double>::quiet_NaN());
52 54 }
53 55 else {
54 56
55 57 auto minIt = std::min_element(
56 58 m_Data->cbegin(), m_Data->cend(), [](const auto &it1, const auto &it2) {
57 59 return SortUtils::minCompareWithNaN(it1.first(), it2.first());
58 60 });
59 61
60 62 // Gets the iterator on the max of all values data
61 63 auto maxIt = std::max_element(
62 64 m_Data->cbegin(), m_Data->cend(), [](const auto &it1, const auto &it2) {
63 65 return SortUtils::maxCompareWithNaN(it1.first(), it2.first());
64 66 });
65 67
66 68 auto pair = std::make_pair(minIt->first(), maxIt->first());
67 69
68 70 return std::make_pair(minIt->first(), maxIt->first());
69 71 }
70 72 }
71 73
72 74 int OptionalAxis::size() const
73 75 {
74 76 return m_Defined ? m_Data->size() : 0;
75 77 }
76 78
77 79 Unit OptionalAxis::unit() const
78 80 {
79 81 return m_Defined ? m_Unit : Unit{};
80 82 }
81 83
82 84 bool OptionalAxis::operator==(const OptionalAxis &other)
83 85 {
84 86 // Axis not defined
85 87 if (!m_Defined) {
86 88 return !other.m_Defined;
87 89 }
88 90
89 91 // Axis defined
90 92 return m_Unit == other.m_Unit
91 93 && std::equal(
92 94 m_Data->cbegin(), m_Data->cend(), other.m_Data->cbegin(), other.m_Data->cend(),
93 95 [](const auto &it1, const auto &it2) { return it1.values() == it2.values(); });
94 96 }
95 97
96 98 bool OptionalAxis::operator!=(const OptionalAxis &other)
97 99 {
98 100 return !(*this == other);
99 101 }
General Comments 0
You need to be logged in to leave comments. Login now