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