Ocean
Triple.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_BASE_TRIPLE_H
9 #define META_OCEAN_BASE_TRIPLE_H
10 
11 #include "ocean/base/Base.h"
12 
13 namespace Ocean
14 {
15 
16 // Forward declaration.
17 template <typename T1, typename T2, typename T3> class Triple;
18 
19 /**
20  * This class implements a triple object able to hold three individual elements.
21  * @tparam T1 Data type of the first element of the triple object
22  * @tparam T2 Data type of the second element of the triple object
23  * @tparam T3 Data type of the third element of the triple object
24  * @ingroup base
25  */
26 template <typename T1, typename T2, typename T3>
27 class Triple
28 {
29  public:
30 
31  /**
32  * Creates a new triple object with default values.
33  */
34  inline Triple();
35 
36  /**
37  * Creates a new triple object with three elements.
38  * @param first First element
39  * @param second Second element
40  * @param third Third element
41  */
42  inline explicit Triple(const T1& first, const T2& second = T1(), const T3& third = T3());
43 
44  /**
45  * Returns the first element of this triple object.
46  * @return First element
47  */
48  inline const T1& first() const;
49 
50  /**
51  * Returns the first element of this triple object.
52  * @return First element
53  */
54  inline T1& first();
55 
56  /**
57  * Returns the second element of this triple object.
58  * @return First element
59  */
60  inline const T2& second() const;
61 
62  /**
63  * Returns the second element of this triple object.
64  * @return Second element
65  */
66  inline T2& second();
67 
68  /**
69  * Returns the third element of this triple object.
70  * @return Third element
71  */
72  inline const T3& third() const;
73 
74  /**
75  * Returns the third element of this triple object.
76  * @return Third element
77  */
78  inline T3& third();
79 
80  /**
81  * Returns whether two triples are equal.
82  * @param triple Second triple object
83  * @return True, if so
84  */
85  inline bool operator==(const Triple<T1, T2, T3>& triple) const;
86 
87  /**
88  * Returns whether two triples are not equal.
89  * @param triple Second triple object
90  * @return True, if so
91  */
92  inline bool operator!=(const Triple<T1, T2, T3>& triple) const;
93 
94  /**
95  * Returns whether this triple object is 'lesser' than a second triple object.
96  * @param triple The second triple object to be used for comparison
97  * @return True, if so
98  */
99  inline bool operator<(const Triple<T1, T2, T3>& triple) const;
100 
101  private:
102 
103  /// First element of this triple.
105 
106  /// Second element of this triple.
108 
109  /// Third element of this triple.
111 };
112 
113 template <typename T1, typename T2, typename T3>
115  tripleFirst(T1()),
116  tripleSecond(T2()),
117  tripleThird(T3())
118 {
119  // nothing to do here
120 }
121 
122 template <typename T1, typename T2, typename T3>
123 inline Triple<T1, T2, T3>::Triple(const T1& first, const T2& second, const T3& third) :
124  tripleFirst(first),
125  tripleSecond(second),
126  tripleThird(third)
127 {
128  // nothing to do here
129 }
130 
131 template <typename T1, typename T2, typename T3>
132 inline const T1& Triple<T1, T2, T3>::first() const
133 {
134  return tripleFirst;
135 }
136 
137 template <typename T1, typename T2, typename T3>
139 {
140  return tripleFirst;
141 }
142 
143 template <typename T1, typename T2, typename T3>
144 inline const T2& Triple<T1, T2, T3>::second() const
145 {
146  return tripleSecond;
147 }
148 
149 template <typename T1, typename T2, typename T3>
151 {
152  return tripleSecond;
153 }
154 
155 template <typename T1, typename T2, typename T3>
156 inline const T3& Triple<T1, T2, T3>::third() const
157 {
158  return tripleThird;
159 }
160 
161 template <typename T1, typename T2, typename T3>
163 {
164  return tripleThird;
165 }
166 
167 template <typename T1, typename T2, typename T3>
168 inline bool Triple<T1, T2, T3>::operator==(const Triple<T1, T2, T3>& triple) const
169 {
170  return tripleFirst == triple.tripleFirst && tripleSecond == triple.tripleSecond && tripleThird == triple.tripleThird;
171 }
172 
173 template <typename T1, typename T2, typename T3>
174 inline bool Triple<T1, T2, T3>::operator!=(const Triple<T1, T2, T3>& triple) const
175 {
176  return !(*this == triple);
177 }
178 
179 template <typename T1, typename T2, typename T3>
180 inline bool Triple<T1, T2, T3>::operator<(const Triple<T1, T2, T3>& triple) const
181 {
182  return (tripleFirst < triple.tripleFirst)
183  || (tripleFirst == triple.tripleFirst && tripleSecond < triple.tripleSecond)
184  || (tripleFirst == triple.tripleFirst && tripleSecond == triple.tripleSecond && tripleThird < triple.tripleThird);
185 }
186 
187 }
188 
189 #endif // META_OCEAN_BASE_TRIPLE_H
This class implements a triple object able to hold three individual elements.
Definition: Triple.h:28
T3 tripleThird
Third element of this triple.
Definition: Triple.h:110
const T1 & first() const
Returns the first element of this triple object.
Definition: Triple.h:132
Triple()
Creates a new triple object with default values.
Definition: Triple.h:114
const T3 & third() const
Returns the third element of this triple object.
Definition: Triple.h:156
bool operator<(const Triple< T1, T2, T3 > &triple) const
Returns whether this triple object is 'lesser' than a second triple object.
Definition: Triple.h:180
const T2 & second() const
Returns the second element of this triple object.
Definition: Triple.h:144
T1 tripleFirst
First element of this triple.
Definition: Triple.h:104
T2 tripleSecond
Second element of this triple.
Definition: Triple.h:107
bool operator!=(const Triple< T1, T2, T3 > &triple) const
Returns whether two triples are not equal.
Definition: Triple.h:174
bool operator==(const Triple< T1, T2, T3 > &triple) const
Returns whether two triples are equal.
Definition: Triple.h:168
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15