File: triple.h

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 239,924 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; javascript: 164; makefile: 88
file content (266 lines) | stat: -rw-r--r-- 6,215 bytes parent folder | download | duplicates (13)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: triple.h,v 1.9 2003/08/26 08:04:12 oliver Exp $
//

#ifndef BALL_DATATYPE_TRIPLE_H
#define BALL_DATATYPE_TRIPLE_H

#ifndef BALL_COMMON_H
#	include <BALL/common.h>
#endif

namespace BALL 
{
	/**	Triple Class.
			This template class is used to represent triples of arbitrary types
			(like the STL type <tt>pair</tt>).
			@see Quadruple
    	
			\ingroup  DatatypeMiscellaneous
	*/
	template <typename T1, typename T2, typename T3>
	class Triple
	{
		public:

		/**	@name	Constructors and Destructors 
		*/
		//@{

		BALL_CREATE(Triple)

		/**	Default constructor.
				Creates a new Triple object.
		*/
		Triple();

		/**	Copy constructor.
				Creates a new Triple object from another.
				@param	triple the Triple object to be copied
				@param	deep not used (needed for a consistent interface only)
		*/
		Triple(const Triple& triple, bool deep = true);

		/**	Detailed constructor.
				Creates a new Triple object from the triple's three
				members.
				@param	new_first	the first triple member
				@param	new_second	the second triple member
				@param	new_third	the third triple member
		*/
		Triple(const T1& new_first, const T2& new_second, const T3& new_third);

		/**	Destructor.
				Destructs the Triple object.
		*/
		virtual ~Triple();
		//@}

		/** Clear method.
		*/
		virtual void clear();

		/**	@name	Assignment
		*/
		//@{

		/**	Assignment operator.
				Assigns the contents of a triple to another.
				@param	triple the triple to be copied
		*/
		const Triple& operator = (const Triple& triple);

		/**
		*/
		void set(const T1& t1, const T2& t2, const T3& t3);

		/**
		*/
		void get(T1& first, T2& second, T3& third) const;

		//@}
		/**	@name	Predicates
		*/
		//@{

		/**	Equality operator 
				Two instances are equal if they have the same members.
		*/
		bool operator == (const Triple& triple) const;

		/**	Inequality operator 
		*/
		bool operator != (const Triple& triple) const;

		/**	Lesser than operator.	
				One instance is lesser than an other if all members from first to
				third are equal or less than the members of the other instance and at least
				threeth is less.
		*/
		bool operator < (const Triple& triple) const;

		/**	Lesser or equal than operator.	
		*/
		bool operator <= (const Triple& triple) const;

		/**	Greater or equal than operator.	
		*/
		bool operator >= (const Triple& triple) const;

		/**	Greater than operator.	
		*/
		bool operator > (const Triple& triple) const;

		//@}
		
		/**	@name	Attributes
		*/
		//@{

		/**	The first triple member
		*/
		T1 first;

		/**	The second triple member
		*/
		T2 second;

		/**	The third triple member
		*/
		T3 third;
		//@}
	};

	template <typename T1, typename T2, typename T3>
	Triple<T1, T2, T3>::Triple()
	{
	}

	template <typename T1, typename T2, typename T3>
	Triple<T1, T2, T3>::Triple
		(const Triple<T1, T2, T3>& triple, bool /* deep */)
		:	first(triple.first),
			second(triple.second),
			third(triple.third)	{
	}

	template <typename T1, typename T2, typename T3>
	Triple<T1, T2, T3>::Triple
		(const T1& new_first, const T2& new_second, const T3& new_third)
		:	first(new_first),
			second(new_second),
			third(new_third)
	{
	}

	template <typename T1, typename T2, typename T3>
	Triple<T1, T2, T3>::~Triple()
	{
	}

	template <typename T1, typename T2, typename T3>
	BALL_INLINE 
	void Triple<T1, T2, T3>::set(const T1& new_first, const T2& new_second, const T3& new_third)
	{
		first		= new_first;
		second	= new_second;
		third		= new_third;
	}

	template <typename T1, typename T2, typename T3>
	BALL_INLINE 
	const Triple<T1, T2, T3>& Triple<T1, T2, T3>::operator = 
		(const Triple<T1, T2, T3>& triple)
	{
		first = triple.first;
		second = triple.second;
		third = triple.third;

		return *this;
	}

	template <typename T1, typename T2, typename T3>
	BALL_INLINE 
	void Triple<T1, T2, T3>::get(T1& t1, T2& t2, T3& t3) 
		const
	{
		t1 = first;
		t2 = second;
		t3 = third;
	}

	template <typename T1, typename T2, typename T3>
	BALL_INLINE 
	bool Triple<T1, T2, T3>::operator ==	(const Triple& triple) 
		const
	{
		return (first  == triple.first
									&& second == triple.second
									&& third  == triple.third);
	}

	template <typename T1, typename T2, typename T3>
	BALL_INLINE 
	bool Triple<T1, T2, T3>::operator != (const Triple& triple)
		const
	{
		return (first != triple.first
									|| second != triple.second
									|| third  != triple.third);
	}

	template <typename T1, typename T2, typename T3>
	BALL_INLINE 
	void Triple<T1, T2, T3>::clear()
	{
		first = T1();
		second = T2();
		third = T3();
	}

	template <typename T1, typename T2, typename T3>
	BALL_INLINE 
	bool Triple<T1, T2, T3>::operator <
		(const Triple<T1, T2, T3>& triple) const
	{
		return ((first < triple.first)
						|| ((first == triple.first) && (second < triple.second))
						|| ((first  == triple.first) && (second == triple.second) && (third < triple.third)));
	}

	template <typename T1, typename T2, typename T3>
	BALL_INLINE 
	bool Triple<T1, T2, T3>::operator <=
		(const Triple<T1, T2, T3>& triple) const
	{
		return ((first < triple.first) 
						|| ((first == triple.first)	&& (second < triple.second))
						|| ((first == triple.first)	&& (second == triple.second) && (third < triple.third))
						|| ((first == triple.first) && (second == triple.second) && (third == triple.third)));
	}

	template <typename T1, typename T2, typename T3>
	BALL_INLINE 
	bool Triple<T1, T2, T3>::operator >=
		(const Triple<T1, T2, T3>& triple) const
	{
		return ((first > triple.first)
						|| ((first == triple.first)	&& (second > triple.second)) 
						|| ((first == triple.first)	&& (second == triple.second) && (third > triple.third))
						|| ((first == triple.first) && (second == triple.second) && (third == triple.third)));
	}

	template <typename T1, typename T2, typename T3>
	BALL_INLINE 
	bool Triple<T1, T2, T3>::operator >
		(const Triple<T1, T2, T3>& triple) const
	{
		return ((first > triple.first)
						|| ((first == triple.first)	&& (second > triple.second))	
						|| ((first == triple.first)	&& (second == triple.second) && (third > triple.third)));
	}
} // namespace BALL

#endif // BALL_DATATYPE_TRIPLE_H