1 /*
2  * Copyright 2006-2008 The FLWOR Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 #ifndef ZORBA_TRIPLE_H
18 #define ZORBA_TRIPLE_H
19 
20 namespace zorba {
21 
22 template<class _T1, class _T2, class _T3>
23 class triple
24 {
25 public:
26 	_T1 first;
27 	_T2 second;
28 	_T3 third;
29 
30 public:
triple()31 	triple() : first(), second(), third() { }
32 
triple(const _T1 & _a,const _T2 & _b,const _T3 & _c)33 	triple(const _T1& _a, const _T2& _b, const _T3& _c)
34 	: first(_a), second(_b), third(_c) { }
35 
36 	template<class _U1, class _U2, class _U3>
triple(const triple<_U1,_U2,_U3> & _p)37 	triple(const triple<_U1, _U2, _U3>& _p)
38 	: first(_p.first), second(_p.second), third(_p.third) { }
39 };
40 
41 template<class _T1, class _T2, class _T3>
42 inline bool operator==(
43 	const triple<_T1, _T2, _T3>& _x,
44 	const triple<_T1, _T2, _T3>& _y)
45 {
46 	return _x.first  == _y.first
47 			&& _x.second == _y.second
48 			&& _x.third  == _y.third;
49 }
50 
51 template<class _T1, class _T2, class _T3>
52 inline bool operator<(
53 	const triple<_T1, _T2, _T3>& _x,
54 	const triple<_T1, _T2, _T3>& _y)
55 {
56 	return (_x.first < _y.first)
57 			|| ((_y.first == _x.first) && (_x.second < _y.second))
58 			|| ((_y.first == _x.first) && (_y.second == _x.second) && (_x.third < _y.third));
59 }
60 
61 template<class _T1, class _T2, class _T3>
62 inline bool operator!=(
63 	const triple<_T1, _T2, _T3>& _x,
64 	const triple<_T1, _T2, _T3>& _y)
65 {
66 	return !(_x == _y);
67 }
68 
69 template<class _T1, class _T2, class _T3>
70 inline bool operator>(
71 	const triple<_T1, _T2, _T3>& _x,
72 	const triple<_T1, _T2, _T3>& _y)
73 {
74 	return _y < _x;
75 }
76 
77 template<class _T1, class _T2, class _T3>
78 inline bool operator<=(
79 	const triple<_T1, _T2, _T3>& _x,
80 	const triple<_T1, _T2, _T3>& _y)
81 {
82 	return !(_y < _x);
83 }
84 
85 template<class _T1, class _T2, class _T3>
86 inline bool operator>=(
87 	const triple<_T1, _T2, _T3>& _x,
88 	const triple<_T1, _T2, _T3>& _y)
89 {
90 	return !(_x < _y);
91 }
92 
93 template<class _T1, class _T2, class _T3>
94 inline triple<_T1, _T2, _T3>
make_triple(_T1 _x,_T2 _y,_T3 _z)95 make_triple(_T1 _x, _T2 _y, _T3 _z)
96 {
97 	return triple<_T1, _T2, _T3>(_x, _y, _z);
98 }
99 
100 } /* namespace zorba */
101 #endif /* ZORBA_TRIPLE_H */
102 
103 /* vim:set et sw=2 ts=2: */
104