BWAPI
|
00001 // Copyright (c) 1997 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/Algebraic_foundations/include/CGAL/number_utils_classes.h $ 00019 // $Id: number_utils_classes.h 45636 2008-09-18 15:35:55Z hemmer $ 00020 // 00021 // 00022 // Author(s) : Michael Hoffmann <hoffmann@inf.ethz.ch> 00023 // : Michael Hemmer <hemmer@mpi-inf.mpg.de> 00024 00025 // to be included by number_utils.h 00026 00027 #ifndef CGAL_NUMBER_UTILS_CLASSES_H 00028 #define CGAL_NUMBER_UTILS_CLASSES_H 1 00029 00030 #include <CGAL/number_type_basic.h> 00031 #include <algorithm> 00032 #include <utility> 00033 00034 CGAL_BEGIN_NAMESPACE 00035 00036 /* Defines functors: 00037 - Is_zero 00038 - Is_one 00039 - Is_negative 00040 - Is_positive 00041 - Sgn 00042 - Abs 00043 - Compare 00044 - Square 00045 - Sqrt 00046 - Div 00047 - Gcd 00048 - To_double 00049 - To_interval 00050 */ 00051 00052 template < class NT > 00053 struct Is_negative : Real_embeddable_traits<NT>::Is_negative {}; 00054 template < class NT > 00055 struct Is_positive : Real_embeddable_traits<NT>::Is_positive {}; 00056 template < class NT > 00057 struct Abs : Real_embeddable_traits<NT>::Abs{}; 00058 template < class NT > 00059 struct To_double : Real_embeddable_traits<NT>::To_double{}; 00060 template < class NT > 00061 struct To_interval : Real_embeddable_traits<NT>::To_interval{}; 00062 00063 // Sign would result in a name clash with enum.h 00064 template < class NT > 00065 struct Sgn : Real_embeddable_traits<NT>::Sgn {}; 00066 00067 00068 template < class NT > 00069 struct Square : Algebraic_structure_traits<NT>::Square{}; 00070 template < class NT > 00071 struct Sqrt : Algebraic_structure_traits<NT>::Sqrt {}; 00072 template < class NT > 00073 struct Div : Algebraic_structure_traits<NT>::Div{}; 00074 template < class NT > 00075 struct Gcd : Algebraic_structure_traits<NT>::Gcd{}; 00076 template < class NT > 00077 struct Is_one : Algebraic_structure_traits<NT>::Is_one {}; 00078 00079 // This is due to the fact that Is_zero may be provided by 00080 // Algebraic_structure_traits as well as Real_embeddable_traits 00081 // Of course it is not possible to derive from both since this 00082 // would cause an ambiguity. 00083 namespace CGALi{ 00084 template <class AST_Is_zero, class RET_Is_zero> 00085 struct Is_zero_base : AST_Is_zero {} ; 00086 template <class RET_Is_zero> 00087 struct Is_zero_base <CGAL::Null_functor, RET_Is_zero >: RET_Is_zero {} ; 00088 } // namespace CGALi 00089 template < class NT > 00090 struct Is_zero : 00091 CGALi::Is_zero_base 00092 <typename Algebraic_structure_traits<NT>::Is_zero, 00093 typename Real_embeddable_traits<NT>::Is_zero>{}; 00094 00095 00096 // This is due to the fact that CGAL::Compare is used for other 00097 // non-realembeddable types as well. 00098 // In this case we try to provide a default implementation 00099 namespace CGALi { 00100 template <class NT, class Compare> struct Compare_base: public Compare {}; 00101 template <class NT> struct Compare_base<NT,Null_functor> 00102 :public std::binary_function< NT, NT, Comparison_result > { 00103 Comparison_result operator()( const NT& x, const NT& y) const 00104 { 00105 if (x < y) return SMALLER; 00106 if (x > y) return LARGER; 00107 CGAL_postcondition(x == y); 00108 return EQUAL; 00109 } 00110 }; 00111 } // namespace CGALi 00112 00113 template < class NT > 00114 struct Compare 00115 :public CGALi::Compare_base 00116 <NT,typename Real_embeddable_traits<NT>::Compare>{}; 00117 00118 00119 00120 CGAL_END_NAMESPACE 00121 00122 #endif // CGAL_NUMBER_UTILS_CLASSES_H