BWAPI
|
00001 // Copyright (c) 2003,2004 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/function_objects.h $ 00019 // $Id: function_objects.h 46206 2008-10-11 20:21:08Z 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_FUNCTION_OBJECTS_H 00027 #define CGAL_FUNCTION_OBJECTS_H 1 00028 00029 #include <functional> 00030 00031 CGAL_BEGIN_NAMESPACE 00032 00033 template < class Value> 00034 struct Identity { 00035 typedef Value argument_type; 00036 typedef Value result_type; 00037 Value& operator()( Value& x) const { return x; } 00038 const Value& operator()( const Value& x) const { return x; } 00039 }; 00040 00041 template < class Value> 00042 struct Dereference { 00043 typedef Value* argument_type; 00044 typedef Value result_type; 00045 Value& operator()( Value* x) const { return *x;} 00046 const Value& operator()( const Value* x) const { return *x;} 00047 }; 00048 00049 template < class Value> 00050 struct Get_address { 00051 typedef Value argument_type; 00052 typedef Value* result_type; 00053 Value* operator()( Value& x) const { return &x;} 00054 const Value* operator()( const Value& x) const { return &x;} 00055 }; 00056 00057 template < class Arg, class Result> 00058 struct Cast_function_object { 00059 typedef Arg argument_type; 00060 typedef Result result_type; 00061 Result& operator()( Arg& x) const { return (Result&)(x); } 00062 const Result& operator()( const Arg& x) const { 00063 return (const Result&)(x); 00064 } 00065 }; 00066 00067 template < class Node> 00068 struct Project_vertex { 00069 typedef Node argument_type; 00070 typedef typename Node::Vertex Vertex; 00071 typedef Vertex result_type; 00072 Vertex& operator()( Node& x) const { return x.vertex(); } 00073 const Vertex& operator()( const Node& x) const { return x.vertex(); } 00074 }; 00075 00076 template < class Node> 00077 struct Project_facet { 00078 typedef Node argument_type; 00079 typedef typename Node::Facet Facet; 00080 typedef Facet result_type; 00081 Facet& operator()( Node& x) const { return x.facet(); } 00082 const Facet& operator()( const Node& x) const { return x.facet(); } 00083 }; 00084 00085 template < class Node> 00086 struct Project_point { 00087 typedef Node argument_type; 00088 typedef typename Node::Point Point; 00089 typedef Point result_type; 00090 Point& operator()( Node& x) const { return x.point(); } 00091 const Point& operator()( const Node& x) const { return x.point(); } 00092 }; 00093 00094 template < class Node> 00095 struct Project_normal { 00096 typedef Node argument_type; 00097 typedef typename Node::Normal Normal; 00098 typedef Normal result_type; 00099 Normal& operator()( Node& x) const { return x.normal(); } 00100 const Normal& operator()( const Node& x) const { return x.normal(); } 00101 }; 00102 00103 template < class Node> 00104 struct Project_plane { 00105 typedef Node argument_type; 00106 typedef typename Node::Plane Plane; 00107 typedef Plane result_type; 00108 Plane& operator()( Node& x) const { return x.plane(); } 00109 const Plane& operator()( const Node& x) const { return x.plane(); } 00110 }; 00111 00112 // The following four adaptors are used to create the circulators 00113 // for polyhedral surfaces. 00114 template < class Node> 00115 struct Project_next { 00116 typedef Node* argument_type; 00117 typedef Node* result_type; 00118 Node* operator()( Node* x) const { return x->next(); } 00119 const Node* operator()( const Node* x) const { return x->next(); } 00120 }; 00121 00122 template < class Node> 00123 struct Project_prev { 00124 typedef Node* argument_type; 00125 typedef Node* result_type; 00126 Node* operator()( Node* x) const { return x->prev(); } 00127 const Node* operator()( const Node* x) const { return x->prev(); } 00128 }; 00129 00130 template < class Node> 00131 struct Project_next_opposite { 00132 typedef Node* argument_type; 00133 typedef Node* result_type; 00134 Node* operator()( Node* x) const { 00135 return x->next()->opposite(); 00136 } 00137 const Node* operator()( const Node* x) const { 00138 return x->next()->opposite(); 00139 } 00140 }; 00141 00142 template < class Node> 00143 struct Project_opposite_prev { 00144 typedef Node* argument_type; 00145 typedef Node* result_type; 00146 Node* operator()( Node* x) const { 00147 return x->opposite()->prev(); 00148 } 00149 const Node* operator()( const Node* x) const { 00150 return x->opposite()->prev(); 00151 } 00152 }; 00153 template < class Arg, class Result > 00154 class Creator_1 { 00155 public: 00156 typedef Arg argument_type; 00157 typedef Arg argument1_type; 00158 typedef Result result_type; 00159 Result operator()(Arg a) const { return Result(a);} 00160 }; 00161 00162 template < class Arg1, class Arg2, class Result > 00163 class Creator_2 { 00164 public: 00165 typedef Arg1 argument1_type; 00166 typedef Arg2 argument2_type; 00167 typedef Result result_type; 00168 Result operator()(Arg1 a1, Arg2 a2) const { return Result(a1,a2);} 00169 }; 00170 00171 template < class Arg1, class Arg2, class Arg3, class Result > 00172 class Creator_3 { 00173 public: 00174 typedef Arg1 argument1_type; 00175 typedef Arg2 argument2_type; 00176 typedef Arg3 argument3_type; 00177 typedef Result result_type; 00178 Result operator()(Arg1 a1, Arg2 a2, Arg3 a3) const { 00179 return Result(a1,a2,a3); 00180 } 00181 }; 00182 00183 template < class Arg1, class Arg2, class Arg3, class Arg4, class Result > 00184 class Creator_4 { 00185 public: 00186 typedef Arg1 argument1_type; 00187 typedef Arg2 argument2_type; 00188 typedef Arg3 argument3_type; 00189 typedef Arg4 argument4_type; 00190 typedef Result result_type; 00191 Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4) const { 00192 return Result(a1,a2,a3,a4); 00193 } 00194 }; 00195 00196 template < class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, 00197 class Result > 00198 class Creator_5 { 00199 public: 00200 typedef Arg1 argument1_type; 00201 typedef Arg2 argument2_type; 00202 typedef Arg3 argument3_type; 00203 typedef Arg4 argument4_type; 00204 typedef Arg5 argument5_type; 00205 typedef Result result_type; 00206 Result operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5) const { 00207 return Result(a1,a2,a3,a4,a5); 00208 } 00209 }; 00210 00211 template < class Arg, class Result > 00212 class Creator_uniform_2 { 00213 public: 00214 typedef Arg argument_type; 00215 typedef Arg argument1_type; 00216 typedef Arg argument2_type; 00217 typedef Result result_type; 00218 Result operator()(Arg a1, Arg a2) const { return Result(a1,a2);} 00219 }; 00220 00221 template < class Arg, class Result > 00222 class Creator_uniform_3 { 00223 public: 00224 typedef Arg argument_type; 00225 typedef Arg argument1_type; 00226 typedef Arg argument2_type; 00227 typedef Arg argument3_type; 00228 typedef Result result_type; 00229 Result operator()(Arg a1, Arg a2, Arg a3) const { 00230 return Result(a1,a2,a3); 00231 } 00232 }; 00233 00234 template < class Arg, class Result > 00235 class Creator_uniform_4 { 00236 public: 00237 typedef Arg argument_type; 00238 typedef Arg argument1_type; 00239 typedef Arg argument2_type; 00240 typedef Arg argument3_type; 00241 typedef Arg argument4_type; 00242 typedef Result result_type; 00243 Result operator()(Arg a1, Arg a2, Arg a3, Arg a4) const { 00244 return Result(a1,a2,a3,a4); 00245 } 00246 }; 00247 00248 template < class Arg, class Result > 00249 class Creator_uniform_5 { 00250 public: 00251 typedef Arg argument_type; 00252 typedef Arg argument1_type; 00253 typedef Arg argument2_type; 00254 typedef Arg argument3_type; 00255 typedef Arg argument4_type; 00256 typedef Arg argument5_type; 00257 typedef Result result_type; 00258 Result operator()(Arg a1, Arg a2, Arg a3, Arg a4, Arg a5) const { 00259 return Result(a1,a2,a3,a4,a5); 00260 } 00261 }; 00262 00263 template < class Arg, class Result > 00264 class Creator_uniform_6 { 00265 public: 00266 typedef Arg argument_type; 00267 typedef Arg argument1_type; 00268 typedef Arg argument2_type; 00269 typedef Arg argument3_type; 00270 typedef Arg argument4_type; 00271 typedef Arg argument5_type; 00272 typedef Arg argument6_type; 00273 typedef Result result_type; 00274 Result operator()(Arg a1, Arg a2, Arg a3, Arg a4, Arg a5, Arg a6 00275 ) const { 00276 return Result(a1,a2,a3,a4,a5,a6); 00277 } 00278 }; 00279 00280 template < class Arg, class Result > 00281 class Creator_uniform_7 { 00282 public: 00283 typedef Arg argument_type; 00284 typedef Arg argument1_type; 00285 typedef Arg argument2_type; 00286 typedef Arg argument3_type; 00287 typedef Arg argument4_type; 00288 typedef Arg argument5_type; 00289 typedef Arg argument6_type; 00290 typedef Arg argument7_type; 00291 typedef Result result_type; 00292 Result operator()(Arg a1, Arg a2, Arg a3, Arg a4, Arg a5, Arg a6, 00293 Arg a7) const { 00294 return Result(a1,a2,a3,a4,a5,a6,a7); 00295 } 00296 }; 00297 00298 template < class Arg, class Result > 00299 class Creator_uniform_8 { 00300 public: 00301 typedef Arg argument_type; 00302 typedef Arg argument1_type; 00303 typedef Arg argument2_type; 00304 typedef Arg argument3_type; 00305 typedef Arg argument4_type; 00306 typedef Arg argument5_type; 00307 typedef Arg argument6_type; 00308 typedef Arg argument7_type; 00309 typedef Arg argument8_type; 00310 typedef Result result_type; 00311 Result operator()(Arg a1, Arg a2, Arg a3, Arg a4, Arg a5, Arg a6, 00312 Arg a7, Arg a8) const { 00313 return Result(a1,a2,a3,a4,a5,a6,a7,a8); 00314 } 00315 }; 00316 00317 template < class Arg, class Result > 00318 class Creator_uniform_9 { 00319 public: 00320 typedef Arg argument_type; 00321 typedef Arg argument1_type; 00322 typedef Arg argument2_type; 00323 typedef Arg argument3_type; 00324 typedef Arg argument4_type; 00325 typedef Arg argument5_type; 00326 typedef Arg argument6_type; 00327 typedef Arg argument7_type; 00328 typedef Arg argument8_type; 00329 typedef Arg argument9_type; 00330 typedef Result result_type; 00331 Result operator()(Arg a1, Arg a2, Arg a3, Arg a4, Arg a5, Arg a6, 00332 Arg a7, Arg a8, Arg a9) const { 00333 return Result(a1,a2,a3,a4,a5,a6,a7,a8,a9); 00334 } 00335 }; 00336 00337 template < class Arg, class Result > 00338 class Creator_uniform_d { 00339 int d; 00340 00341 private: 00342 Creator_uniform_d(){} 00343 00344 public: 00345 typedef Arg argument1_type; 00346 typedef Result result_type; 00347 00348 Creator_uniform_d(int dim) 00349 : d(dim) 00350 {} 00351 00352 Result operator()(Arg a1, Arg a2) const { return Result(d, a1,a2);} 00353 }; 00354 00355 template < class Op1, class Op2 > 00356 class Unary_compose_1 00357 : public std::unary_function< typename Op2::argument_type, 00358 typename Op1::result_type > 00359 { 00360 protected: 00361 Op1 op1; 00362 Op2 op2; 00363 public: 00364 typedef typename Op2::argument_type argument_type; 00365 typedef typename Op1::result_type result_type; 00366 00367 Unary_compose_1(const Op1& x, const Op2& y) : op1(x), op2(y) {} 00368 00369 result_type 00370 operator()(const argument_type& x) const 00371 { return op1(op2(x)); } 00372 }; 00373 00374 template < class Op1, class Op2 > 00375 inline Unary_compose_1< Op1, Op2 > 00376 compose1_1(const Op1& op1, const Op2& op2) 00377 { return Unary_compose_1< Op1, Op2 >(op1, op2); } 00378 00379 template < class Op1, class Op2, class Op3 > 00380 class Binary_compose_1 00381 : public std::unary_function< typename Op2::argument_type, 00382 typename Op1::result_type > 00383 { 00384 protected: 00385 Op1 op1; 00386 Op2 op2; 00387 Op3 op3; 00388 public: 00389 typedef typename Op2::argument_type argument_type; 00390 typedef typename Op1::result_type result_type; 00391 00392 Binary_compose_1(const Op1& x, const Op2& y, const Op3& z) 00393 : op1(x), op2(y), op3(z) {} 00394 00395 result_type 00396 operator()(const argument_type& x) const 00397 { return op1(op2(x), op3(x)); } 00398 }; 00399 00400 template < class Op1, class Op2, class Op3 > 00401 inline Binary_compose_1< Op1, Op2, Op3 > 00402 compose2_1(const Op1& op1, const Op2& op2, const Op3& op3) 00403 { return Binary_compose_1< Op1, Op2, Op3 >(op1, op2, op3); } 00404 00405 template < class Op1, class Op2 > 00406 class Unary_compose_2 00407 : public std::binary_function< typename Op2::first_argument_type, 00408 typename Op2::second_argument_type, 00409 typename Op1::result_type > 00410 { 00411 protected: 00412 Op1 op1; 00413 Op2 op2; 00414 public: 00415 typedef typename Op2::first_argument_type first_argument_type; 00416 typedef typename Op2::second_argument_type second_argument_type; 00417 typedef typename Op1::result_type result_type; 00418 00419 Unary_compose_2(const Op1& x, const Op2& y) : op1(x), op2(y) {} 00420 00421 result_type 00422 operator()(const first_argument_type& x, 00423 const second_argument_type& y) const 00424 { return op1(op2(x, y)); } 00425 }; 00426 00427 template < class Op1, class Op2 > 00428 inline Unary_compose_2< Op1, Op2 > 00429 compose1_2(const Op1& op1, const Op2& op2) 00430 { return Unary_compose_2< Op1, Op2 >(op1, op2); } 00431 00432 template < class Op1, class Op2, class Op3 > 00433 class Binary_compose_2 00434 : public std::binary_function< typename Op2::argument_type, 00435 typename Op3::argument_type, 00436 typename Op1::result_type > 00437 { 00438 protected: 00439 Op1 op1; 00440 Op2 op2; 00441 Op3 op3; 00442 public: 00443 typedef typename Op2::argument_type first_argument_type; 00444 typedef typename Op3::argument_type second_argument_type; 00445 typedef typename Op1::result_type result_type; 00446 00447 Binary_compose_2(const Op1& x, const Op2& y, const Op3& z) 00448 : op1(x), op2(y), op3(z) {} 00449 00450 result_type 00451 operator()(const first_argument_type& x, 00452 const second_argument_type& y) const 00453 { return op1(op2(x), op3(y)); } 00454 }; 00455 00456 template < class Op1, class Op2, class Op3 > 00457 inline Binary_compose_2< Op1, Op2, Op3 > 00458 compose2_2(const Op1& op1, const Op2& op2, const Op3& op3) 00459 { return Binary_compose_2< Op1, Op2, Op3 >(op1, op2, op3); } 00460 00461 00462 template < class Op > 00463 class Compare_to_less 00464 : public Op 00465 { 00466 public: 00467 typedef Op Type; 00468 typedef bool result_type; 00469 00470 Compare_to_less(const Op& op) : Op(op) {} 00471 00472 template < typename A1 > 00473 bool 00474 operator()(const A1 &a1) const 00475 { return Op::operator()(a1) == SMALLER; } 00476 00477 template < typename A1, typename A2 > 00478 bool 00479 operator()(const A1 &a1, const A2 &a2) const 00480 { return Op::operator()(a1, a2) == SMALLER; } 00481 00482 template < typename A1, typename A2, typename A3 > 00483 bool 00484 operator()(const A1 &a1, const A2 &a2, const A3 &a3) const 00485 { return Op::operator()(a1, a2, a3) == SMALLER; } 00486 00487 template < typename A1, typename A2, typename A3, typename A4 > 00488 bool 00489 operator()(const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4) const 00490 { return Op::operator()(a1, a2, a3, a4) == SMALLER; } 00491 00492 // More can be added. 00493 }; 00494 00495 template < class Op > 00496 inline Compare_to_less<Op> 00497 compare_to_less(const Op& op) 00498 { return Compare_to_less<Op>(op); } 00499 00500 00504 template < class T1, class T2, 00505 class Less1 = std::less<T1>, class Less2 = std::less<T2> > 00506 struct Pair_lexicographical_less_than { 00507 typedef bool result_type; 00508 typedef std::pair<T1,T2> first_argument_type; 00509 typedef std::pair<T1,T2> second_argument_type; 00514 bool operator () (const std::pair<T1,T2>& x, const std::pair<T1,T2>& y) { 00515 Less1 lt1; 00516 Less2 lt2; 00517 00518 if (lt1(x.first, y.first)) { 00519 return true; 00520 } else if (lt1(y.first, x.first)) { 00521 return false; 00522 } else /* neither is less than the other */ { 00523 return lt2(x.second, y.second); 00524 } 00525 } 00526 }; 00527 00528 00529 CGAL_END_NAMESPACE 00530 00531 #endif // CGAL_FUNCTION_OBJECTS_H