BWAPI
|
00001 // Copyright (c) 2006-2007 Max-Planck-Institute Saarbruecken (Germany). 00002 // All rights reserved. 00003 // 00004 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public License as 00006 // published by the Free Software Foundation; version 2.1 of the License. 00007 // See the file LICENSE.LGPL distributed with CGAL. 00008 // 00009 // Licensees holding a valid commercial license may use this file in 00010 // accordance with the commercial license agreement provided with the software. 00011 // 00012 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00013 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00014 // 00015 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Algebraic_foundations/include/CGAL/Real_embeddable_traits.h $ 00016 // $Id: Real_embeddable_traits.h 45636 2008-09-18 15:35:55Z hemmer $ 00017 // 00018 // 00019 // Author(s) : Michael Hemmer <hemmer@mpi-inf.mpg.de> 00020 // 00021 // ============================================================================= 00022 00023 00024 #ifndef CGAL_REAL_EMBEDDABLE_TRAITS_H 00025 #define CGAL_REAL_EMBEDDABLE_TRAITS_H 00026 00027 #include <CGAL/number_type_basic.h> 00028 00029 CGAL_BEGIN_NAMESPACE 00030 00031 namespace INTERN_RET { 00032 00033 template< class T, class AST_is_zero > 00034 struct Is_zero_selector{ typedef AST_is_zero Type; }; 00035 00036 template< class T > 00037 struct Is_zero_selector< T, Null_functor > 00038 { 00039 struct Type : public std::unary_function< T, bool >{ 00040 bool operator()( const T& x ) const { 00041 return x == T(0); 00042 } 00043 }; 00044 }; 00045 00046 template < class Type_ , class Is_real_embeddable_ > 00047 class Real_embeddable_traits_base{ 00048 public: 00049 typedef Type_ Type; 00050 typedef Is_real_embeddable_ Is_real_embeddable; 00051 typedef Null_tag Boolean; 00052 typedef Null_tag Sign; 00053 typedef Null_tag Comparison_result; 00054 00055 typedef Null_functor Abs; 00056 typedef Null_functor Sgn; 00057 typedef Null_functor Is_finite; 00058 typedef Null_functor Is_positive; 00059 typedef Null_functor Is_negative; 00060 typedef Null_functor Is_zero; 00061 typedef Null_functor Compare; 00062 typedef Null_functor To_double; 00063 typedef Null_functor To_interval; 00064 }; 00065 00066 template< class Type_ > 00067 class Real_embeddable_traits_base<Type_, CGAL::Tag_true> { 00068 public: 00069 typedef Type_ Type; 00070 typedef Tag_true Is_real_embeddable; 00071 typedef bool Boolean; 00072 typedef CGAL::Sign Sign; 00073 typedef CGAL::Comparison_result Comparison_result; 00074 00075 private: 00076 typedef typename Algebraic_structure_traits< Type >::Is_zero AST_Is_zero; 00077 public: 00079 typedef typename INTERN_RET::Is_zero_selector< Type, AST_Is_zero >::Type 00080 Is_zero; 00081 00083 class Is_finite : public std::unary_function< Type, Boolean > { 00084 public: 00085 Boolean operator()( const Type& ) const { 00086 return true; 00087 } 00088 }; 00089 00092 class Abs 00093 : public std::unary_function< Type, Type > { 00094 public: 00096 Type operator()( const Type& x ) const { 00097 return( x < Type(0) ) ? -x : x; 00098 } 00099 }; 00100 00102 class Sgn 00103 : public std::unary_function< Type, ::CGAL::Sign > { 00104 public: 00106 ::CGAL::Sign operator()( const Type& x ) const { 00107 if ( x < Type(0)) 00108 return NEGATIVE; 00109 if ( x > Type(0)) 00110 return POSITIVE; 00111 return ZERO; 00112 } 00113 }; 00114 00116 class Is_positive 00117 : public std::unary_function< Type, Boolean > { 00118 public: 00120 Boolean operator()( const Type& x ) const { 00121 return x > Type(0); 00122 } 00123 }; 00124 00126 class Is_negative 00127 : public std::unary_function< Type, Boolean > { 00128 public: 00130 Boolean operator()( const Type& x ) const { 00131 return x < Type(0); 00132 } 00133 }; 00134 00136 class Compare 00137 : public std::binary_function< Type, Type, 00138 Comparison_result > { 00139 public: 00141 Comparison_result operator()( const Type& x, 00142 const Type& y) const { 00143 if( x < y ) 00144 return SMALLER; 00145 if( x > y ) 00146 return LARGER; 00147 return EQUAL; 00148 } 00149 00150 CGAL_IMPLICIT_INTEROPERABLE_BINARY_OPERATOR_WITH_RT( Type, 00151 Comparison_result ) 00152 }; 00153 00154 class To_double : public std::unary_function< Type, double > { 00155 public: 00156 double operator()( const Type& x ) const { 00157 return static_cast<double>(x); 00158 } 00159 }; 00160 00161 class To_interval 00162 : public std::unary_function< Type, std::pair<double,double> > { 00163 public: 00164 std::pair<double,double> operator()( const Type& x ) const { 00165 double dx(static_cast<double>(x)); 00166 return std::make_pair(dx,dx); 00167 } 00168 }; 00169 }; 00170 00171 } // INTERN_RET 00172 00173 00174 template< class Type_ > 00175 class Real_embeddable_traits 00176 : public INTERN_RET::Real_embeddable_traits_base<Type_,CGAL::Tag_false> {}; 00177 00178 CGAL_END_NAMESPACE 00179 00180 #endif // CGAL_REAL_EMBEDDABLE_TRAITS_H