BWAPI
|
00001 // Copyright (c) 2003 Utrecht University (The Netherlands), 00002 // ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany), 00003 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg 00004 // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria), 00005 // and Tel-Aviv University (Israel). All rights reserved. 00006 // 00007 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00008 // modify it under the terms of the GNU Lesser General Public License as 00009 // published by the Free Software Foundation; version 2.1 of the License. 00010 // See the file LICENSE.LGPL distributed with CGAL. 00011 // 00012 // Licensees holding a valid commercial license may use this file in 00013 // accordance with the commercial license agreement provided with the software. 00014 // 00015 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 // 00018 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/STL_Extension/include/CGAL/utility.h $ 00019 // $Id: utility.h 49057 2009-04-30 14:03:52Z spion $ 00020 // 00021 // 00022 // Author(s) : Michael Hoffmann <hoffmann@inf.ethz.ch> 00023 // Lutz Kettner <kettner@mpi-sb.mpg.de> 00024 // Sylvain Pion 00025 00026 #ifndef CGAL_UTILITY_H 00027 #define CGAL_UTILITY_H 1 00028 00029 #include <CGAL/basic.h> 00030 00031 // The Triple and Quadruple classes are NOT RECOMMENDED anymore. 00032 // We recommend that you use cpp0x::tuple or cpp0x::array instead 00033 // for new uses. 00034 00035 CGAL_BEGIN_NAMESPACE 00036 00037 namespace CGALi { 00038 00039 template <int i, typename T> 00040 struct Tuple_get; 00041 00042 template <typename T> 00043 struct Tuple_get<0, T> 00044 { 00045 typedef typename T::first_type result_type; 00046 static result_type & get(T & t) { return t.first; } 00047 static result_type const & get(T const & t) { return t.first; } 00048 }; 00049 00050 template <typename T> 00051 struct Tuple_get<1, T> 00052 { 00053 typedef typename T::second_type result_type; 00054 static result_type & get(T & t) { return t.second; } 00055 static result_type const & get(T const & t) { return t.second; } 00056 }; 00057 00058 template <typename T> 00059 struct Tuple_get<2, T> 00060 { 00061 typedef typename T::third_type result_type; 00062 static result_type & get(T & t) { return t.third; } 00063 static result_type const & get(T const & t) { return t.third; } 00064 }; 00065 00066 template <typename T> 00067 struct Tuple_get<3, T> 00068 { 00069 typedef typename T::fourth_type result_type; 00070 static result_type & get(T & t) { return t.fourth; } 00071 static result_type const & get(T const & t) { return t.fourth; } 00072 }; 00073 00074 } 00075 00076 //+---------------------------------------------------------------------+ 00077 //| Triple class | 00078 //+---------------------------------------------------------------------+ 00079 00080 template <class T1, class T2, class T3> 00081 class Triple 00082 { 00083 typedef Triple<T1, T2, T3> Self; 00084 00085 public: 00086 00087 typedef T1 first_type; 00088 typedef T2 second_type; 00089 typedef T3 third_type; 00090 00091 T1 first; 00092 T2 second; 00093 T3 third; 00094 00095 Triple() {} 00096 00097 Triple(const T1& a, const T2& b, const T3& c) 00098 : first(a), second(b), third(c) 00099 {} 00100 00101 template <class U, class V, class W> 00102 Triple(const U& a, const V& b, const W& c) 00103 : first(a), second(b), third(c) 00104 {} 00105 00106 template <class U, class V, class W> 00107 Triple& operator=(const Triple<U, V, W> &t) { 00108 first = t.first; 00109 second = t.second; 00110 third = t.third; 00111 return *this; 00112 } 00113 00114 template < int i > 00115 typename CGALi::Tuple_get<i, Self>::result_type const & 00116 get() const 00117 { 00118 return CGALi::Tuple_get<i, Self>::get(*this); 00119 } 00120 00121 template < int i > 00122 typename CGALi::Tuple_get<i, Self>::result_type & 00123 get() 00124 { 00125 return CGALi::Tuple_get<i, Self>::get(*this); 00126 } 00127 00128 }; 00129 00130 template <class T1, class T2, class T3> 00131 inline 00132 Triple<T1, T2, T3> make_triple(const T1& x, const T2& y, const T3& z) 00133 { 00134 return Triple<T1, T2, T3>(x, y, z); 00135 } 00136 00137 template <class T1, class T2, class T3> 00138 inline 00139 Triple<T1, T2, T3> make_tuple(const T1& x, const T2& y, const T3& z) 00140 { 00141 return Triple<T1, T2, T3>(x, y, z); 00142 } 00143 00144 template <class T1, class T2, class T3> 00145 inline bool operator==(const Triple<T1, T2, T3>& x, 00146 const Triple<T1, T2, T3>& y) 00147 { 00148 return ( (x.first == y.first) && 00149 (x.second == y.second) && 00150 (x.third == y.third) ); 00151 } 00152 00153 template <class T1, class T2, class T3> 00154 inline bool operator!=(const Triple<T1, T2, T3>& x, 00155 const Triple<T1, T2, T3>& y) 00156 { 00157 return !(x == y); 00158 } 00159 00160 template <class T1, class T2, class T3> 00161 inline 00162 bool operator<(const Triple<T1, T2, T3>& x, 00163 const Triple<T1, T2, T3>& y) 00164 { 00165 return ( x.first < y.first || 00166 ( !(y.first < x.first) && 00167 ( x.second < y.second || 00168 ( !(y.second < x.second) && x.third < y.third ) ) ) ); 00169 } 00170 //+---------------------------------------------------------------------+ 00171 //| Quadruple class | 00172 //+---------------------------------------------------------------------+ 00173 00174 template <class T1, class T2, class T3, class T4> 00175 class Quadruple 00176 { 00177 typedef Quadruple<T1, T2, T3, T4> Self; 00178 00179 public: 00180 00181 typedef T1 first_type; 00182 typedef T2 second_type; 00183 typedef T3 third_type; 00184 typedef T4 fourth_type; 00185 00186 T1 first; 00187 T2 second; 00188 T3 third; 00189 T4 fourth; 00190 00191 Quadruple() {} 00192 00193 Quadruple(const T1& a, const T2& b, const T3& c, const T4& d) 00194 : first(a), second(b), third(c), fourth(d) 00195 {} 00196 00197 template <class U, class V, class W, class X> 00198 Quadruple(const U& a, const V& b, const W& c, const X& d) 00199 : first(a), second(b), third(c), fourth(d) 00200 {} 00201 00202 template <class U, class V, class W, class X> 00203 Quadruple& operator=(const Quadruple<U, V, W, X> &q) { 00204 first = q.first; 00205 second = q.second; 00206 third = q.third; 00207 fourth = q.fourth; 00208 return *this; 00209 } 00210 00211 template < int i > 00212 typename CGALi::Tuple_get<i, Self>::result_type const & 00213 get() const 00214 { 00215 return CGALi::Tuple_get<i, Self>::get(*this); 00216 } 00217 00218 template < int i > 00219 typename CGALi::Tuple_get<i, Self>::result_type & 00220 get() 00221 { 00222 return CGALi::Tuple_get<i, Self>::get(*this); 00223 } 00224 }; 00225 00226 template <class T1, class T2, class T3, class T4> 00227 inline 00228 Quadruple<T1, T2, T3, T4> 00229 make_quadruple(const T1& x, const T2& y, const T3& z, const T4& zz) 00230 { 00231 return Quadruple<T1, T2, T3, T4>(x, y, z, zz); 00232 } 00233 00234 template <class T1, class T2, class T3, class T4> 00235 inline 00236 Quadruple<T1, T2, T3, T4> 00237 make_tuple(const T1& x, const T2& y, const T3& z, const T4& zz) 00238 { 00239 return Quadruple<T1, T2, T3, T4>(x, y, z, zz); 00240 } 00241 00242 template <class T1, class T2, class T3, class T4> 00243 inline 00244 bool 00245 operator==(const Quadruple<T1, T2, T3, T4>& x, 00246 const Quadruple<T1, T2, T3, T4>& y) 00247 { 00248 return ( (x.first == y.first) && 00249 (x.second == y.second) && 00250 (x.third == y.third) && 00251 (x.fourth == y.fourth) ); 00252 } 00253 00254 template <class T1, class T2, class T3, class T4> 00255 inline 00256 bool 00257 operator!=(const Quadruple<T1, T2, T3, T4>& x, 00258 const Quadruple<T1, T2, T3, T4>& y) 00259 { 00260 return ! (x == y); 00261 } 00262 00263 template <class T1, class T2, class T3, class T4> 00264 inline 00265 bool 00266 operator<(const Quadruple<T1, T2, T3, T4>& x, 00267 const Quadruple<T1, T2, T3, T4>& y) 00268 { 00269 return ( x.first < y.first || 00270 ( !(y.first < x.first) && 00271 ( x.second < y.second || 00272 ( !(y.second < x.second) && 00273 ( x.third < y.third || 00274 (!(y.third < x.third) && x.fourth < y.fourth)) ) ) ) ); 00275 } 00276 00277 00278 CGAL_END_NAMESPACE 00279 00280 #endif // CGAL_UTILITY_H