-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathQuad.h
121 lines (102 loc) · 3.08 KB
/
Quad.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* Quad.h
*
* Contact: Jeff Maddalon ([email protected])
* NASA LaRC
*
* a four element tuple
*
* Copyright (c) 2011-2021 United States Government as represented by
* the National Aeronautics and Space Administration. No copyright
* is claimed in the United States under Title 17, U.S.Code. All Other
* Rights Reserved.
*
*/
#ifndef QUAD_H_
#define QUAD_H_
namespace larcfm {
/** A 4-dimensional tuple
*
* @param <T1> generic type, first element
* @param <T2> generic type, second element
* @param <T3> generic type, third element
* @param <T4> generic type, fourth element
*/
template <typename T1, typename T2, typename T3, typename T4>
class Quad {
public:
T1 first;
T2 second;
T3 third;
T4 fourth;
/** Construct a new Quad object */
Quad(): first(T1()), second(T2()), third(T3()), fourth(T4()) {}
/** Construct a new Quad object */
Quad(const T1& first, const T2& second, const T3& third, const T4& fourth) : first(first), second(second), third(third), fourth(fourth) {
}
/** Return the first element of this Quad
* @return first element
* */
T1 getFirst() const {
return first;
}
/** Return the second element of this Quad
* @return second element
* */
T2 getSecond() const {
return second;
}
/** Return the third element of this Quad
* @return third element
* */
T3 getThird() const {
return third;
}
/** Return the fourth element of this Quad
* @return forth element
* */
T4 getFourth() const {
return fourth;
}
/** Copy a Quad object */
template<typename U1, typename U2, typename U3, typename U4>
explicit Quad(const Quad<U1,U2,U3,U4>& q): first(q.first), second(q.second), third(q.third), fourth(q.fourth) {}
/** Make a new Quad object */
static Quad<T1,T2,T3,T4> make(const T1& e1, const T2& e2, const T3& e3, const T4& e4) {
return Quad<T1,T2,T3,T4>(e1, e2, e3, e4);
}
};
/** Are these two Quad objects equal? */
template<typename T1, typename T2, typename T3, typename T4>
bool operator== (const Quad<T1,T2,T3,T4>& q1, const Quad<T1,T2,T3,T4>& q2) {
return q1.first == q2.first && q1.second == q2.second && q1.third == q2.third && q1.fourth == q2.fourth;
}
/** Are these two Quad objects unequal? */
template<typename T1, typename T2, typename T3, typename T4>
bool operator!= (const Quad<T1,T2,T3,T4>& q1, const Quad<T1,T2,T3,T4>& q2) {
return !(q1 == q2);
}
/** ordering */
template<typename T1, typename T2, typename T3, typename T4>
bool operator< (const Quad<T1,T2,T3,T4>& q1, const Quad<T1,T2,T3,T4>& q2) {
if (q1.first == q2.first) {
if (q1.second == q2.second) {
if (q1.third == q2.third) {
return q1.fourth < q2.fourth;
} else {
return q1.third < q2.third;
}
} else {
return q1.second < q2.second;
}
} else {
return q1.first < q2.first;
}
}
/** ordering */
template<typename T1, typename T2, typename T3, typename T4>
bool operator> (const Quad<T1,T2,T3,T4>& q1, const Quad<T1,T2,T3,T4>& q2) {
return q1 != q2 && !(q1 < q2);
}
}
#endif /* QUAD_H_ */