Don't import ogdf namespace
[TortoiseGit.git] / ext / OGDF / ogdf / basic / tuples.h
blobac0203fcf53a10f84b0a7ae29a133b59401b31cf
1 /*
2 * $Revision: 2615 $
4 * last checkin:
5 * $Author: gutwenger $
6 * $Date: 2012-07-16 14:23:36 +0200 (Mo, 16. Jul 2012) $
7 ***************************************************************/
9 /** \file
10 * \brief Declaration and implementation of class Tuple2, Tuple3
11 * and Tuple4.
13 * \author Carsten Gutwenger
15 * \par License:
16 * This file is part of the Open Graph Drawing Framework (OGDF).
18 * \par
19 * Copyright (C)<br>
20 * See README.txt in the root directory of the OGDF installation for details.
22 * \par
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License
25 * Version 2 or 3 as published by the Free Software Foundation;
26 * see the file LICENSE.txt included in the packaging of this file
27 * for details.
29 * \par
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * \par
36 * You should have received a copy of the GNU General Public
37 * License along with this program; if not, write to the Free
38 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
39 * Boston, MA 02110-1301, USA.
41 * \see http://www.gnu.org/copyleft/gpl.html
42 ***************************************************************/
45 #ifdef _MSC_VER
46 #pragma once
47 #endif
49 #ifndef OGDF_TUPLE_H
50 #define OGDF_TUPLE_H
53 #include <ogdf/basic/basic.h>
54 #include <ogdf/basic/Hashing.h>
57 namespace ogdf {
59 //! Tuples of two elements (2-tuples).
60 /**
61 * @tparam E1 is the data type for the first element.
62 * @tparam E2 is the data type for the second element.
64 template<class E1, class E2> class Tuple2 {
65 public:
66 E1 m_x1; //!< The first element.
67 E2 m_x2; //!< The second element.
69 //! Constructs a 2-tuple using default constructors.
70 Tuple2() { }
71 //! Constructs a 2-tuple for given values.
72 Tuple2(const E1 &y1, const E2 &y2) : m_x1(y1), m_x2(y2) { }
73 //! Constructs a 2-tuple that is a copy of \a t2.
74 Tuple2(const Tuple2<E1,E2> &t2) : m_x1(t2.m_x1), m_x2(t2.m_x2) { }
76 //! Returns a reference the first element.
77 const E1 &x1() const { return m_x1; }
78 //! Returns a reference the second element.
79 const E2 &x2() const { return m_x2; }
81 //! Returns a reference the first element.
82 E1 &x1() { return m_x1; }
83 //! Returns a reference the second element.
84 E2 &x2() { return m_x2; }
86 // default assignment operator
88 OGDF_NEW_DELETE
91 //! Equality operator for 2-tuples
92 template<class E1, class E2>
93 bool operator==(const Tuple2<E1,E2> &t1, const Tuple2<E1,E2> &t2)
95 return t1.x1() == t2.x1() && t1.x2() == t2.x2();
98 //! Inequality operator for 2-tuples
99 template<class E1, class E2>
100 bool operator!=(const Tuple2<E1,E2> &t1, const Tuple2<E1,E2> &t2)
102 return t1.x1() != t2.x1() || t1.x2() != t2.x2();
105 //! Output operator for 2-tuples.
106 template<class E1, class E2>
107 ostream &operator<<(ostream &os, const Tuple2<E1,E2> &t2)
109 os << "(" << t2.x1() << " " << t2.x2() << ")";
110 return os;
114 //! Tuples of three elements (3-tuples).
116 * @tparam E1 is the data type for the first element.
117 * @tparam E2 is the data type for the second element.
118 * @tparam E3 is the data type for the third element.
120 template<class E1, class E2, class E3> class Tuple3 {
121 public:
122 E1 m_x1; //!< The first element.
123 E2 m_x2; //!< The second element.
124 E3 m_x3; //!< The third element.
126 //! Constructs a 3-tuple using default constructors.
127 Tuple3() { }
128 //! Constructs a 3-tuple for given values.
129 Tuple3(const E1 &y1, const E2 &y2, const E3 &y3) :
130 m_x1(y1), m_x2(y2), m_x3(y3) { }
131 //! Constructs a 3-tuple that is a copy of \a t3.
132 Tuple3(const Tuple3<E1,E2,E3> &t3) :
133 m_x1(t3.m_x1), m_x2(t3.m_x2), m_x3(t3.m_x3) { }
135 //! Returns a reference the first element.
136 const E1 &x1() const { return m_x1; }
137 //! Returns a reference the second element.
138 const E2 &x2() const { return m_x2; }
139 //! Returns a reference the third element.
140 const E3 &x3() const { return m_x3; }
142 //! Returns a reference the first element.
143 E1 &x1() { return m_x1; }
144 //! Returns a reference the second element.
145 E2 &x2() { return m_x2; }
146 //! Returns a reference the third element.
147 E3 &x3() { return m_x3; }
149 // default assignment operator
151 OGDF_NEW_DELETE
154 //! Equality operator for 3-tuples
155 template<class E1, class E2, class E3>
156 bool operator==(const Tuple3<E1,E2,E3> &t1, const Tuple3<E1,E2,E3> &t2)
158 return t1.x1() == t2.x1() && t1.x2() == t2.x2() && t1.x3() == t2.x3();
161 //! Inequality operator for 3-tuples
162 template<class E1, class E2, class E3>
163 bool operator!=(const Tuple3<E1,E2,E3> &t1, const Tuple3<E1,E2,E3> &t2)
165 return t1.x1() != t2.x1() || t1.x2() != t2.x2() || t1.x3() != t2.x3();
168 //! Output operator for 3-tuples
169 template<class E1, class E2, class E3>
170 ostream &operator<<(ostream &os, const Tuple3<E1,E2,E3> &t3)
172 os << "(" << t3.x1() << " " << t3.x2() << " " << t3.x3() << ")";
173 return os;
177 //! Tuples of four elements (4-tuples).
179 * @tparam E1 is the data type for the first element.
180 * @tparam E2 is the data type for the second element.
181 * @tparam E3 is the data type for the third element.
182 * @tparam E4 is the data type for the fourth element.
184 template<class E1, class E2, class E3, class E4> class Tuple4 {
185 public:
186 E1 m_x1; //!< The first element.
187 E2 m_x2; //!< The second element.
188 E3 m_x3; //!< The third element.
189 E4 m_x4; //!< The fourth element.
191 //! Constructs a 4-tuple using default constructors.
192 Tuple4() { }
193 //! Constructs a 4-tuple for given values.
194 Tuple4(const E1 &y1, const E2 &y2, const E3 &y3, const E4 &y4) :
195 m_x1(y1), m_x2(y2), m_x3(y3), m_x4(y4) { }
196 //! Constructs a 4-tuple that is a copy of \a t4.
197 Tuple4(const Tuple4<E1,E2,E3,E4> &t4) :
198 m_x1(t4.m_x1), m_x2(t4.m_x2), m_x3(t4.m_x3), m_x4(t4.m_x4) { }
200 //! Returns a reference the first element.
201 const E1 &x1() const { return m_x1; }
202 //! Returns a reference the second element.
203 const E2 &x2() const { return m_x2; }
204 //! Returns a reference the third element.
205 const E3 &x3() const { return m_x3; }
206 //! Returns a reference the fourth element.
207 const E4 &x4() const { return m_x4; }
209 //! Returns a reference the first element.
210 E1 &x1() { return m_x1; }
211 //! Returns a reference the second element.
212 E2 &x2() { return m_x2; }
213 //! Returns a reference the third element.
214 E3 &x3() { return m_x3; }
215 //! Returns a reference the fourth element.
216 E4 &x4() { return m_x4; }
218 // default assignment operator
220 OGDF_NEW_DELETE
223 //! Equality operator for 4-tuples
224 template<class E1, class E2, class E3, class E4>
225 bool operator==(const Tuple4<E1,E2,E3,E4> &t1, const Tuple4<E1,E2,E3,E4> &t2)
227 return t1.x1() == t2.x1() && t1.x2() == t2.x2() &&
228 t1.x3() == t2.x3() && t1.x4() == t2.x4();
231 //! Inequality operator for 4-tuples
232 template<class E1, class E2, class E3, class E4>
233 bool operator!=(const Tuple4<E1,E2,E3,E4> &t1, const Tuple4<E1,E2,E3,E4> &t2)
235 return t1.x1() != t2.x1() || t1.x2() != t2.x2() ||
236 t1.x3() != t2.x3() || t1.x4() != t2.x4();
239 //! Output operator for 4-tuples
240 template<class E1, class E2, class E3, class E4>
241 ostream &operator<<(ostream &os, const Tuple4<E1,E2,E3,E4> &t4)
243 os << "(" << t4.x1() << " " << t4.x2() << " " <<
244 t4.x3() << " " << t4.x4() << ")";
245 return os;
248 template<typename K1_, typename K2_,
249 typename Hash1_ = DefHashFunc<K1_>,
250 typename Hash2_ = DefHashFunc<K2_> >
251 class HashFuncTuple
253 public:
254 HashFuncTuple() { }
256 HashFuncTuple(const Hash1_ &hash1, const Hash2_ &hash2)
257 : m_hash1(hash1), m_hash2(hash2) { }
259 size_t hash(const Tuple2<K1_,K2_> &key) const {
260 return 23*m_hash1.hash(key.x1()) + 443*m_hash2.hash(key.x2());
263 private:
264 Hash1_ m_hash1;
265 Hash2_ m_hash2;
268 } // namespace ogdf
271 #endif