BWAPI
|
00001 // Copyright (c) 2008 Max-Planck-Institute Saarbruecken (Germany) 00002 // 00003 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00004 // modify it under the terms of the GNU Lesser General Public License as 00005 // published by the Free Software Foundation; version 2.1 of the License. 00006 // See the file LICENSE.LGPL distributed with CGAL. 00007 // 00008 // Licensees holding a valid commercial license may use this file in 00009 // accordance with the commercial license agreement provided with the software. 00010 // 00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00013 // 00014 // $URL: svn+ssh://afabri@scm.gforge.inria.fr/svn/cgal/trunk/Polynomial/include/CGAL/Polynomial/Fraction_traits.h $ 00015 // $Id: Fraction_traits.h 44820 2008-08-07 09:49:32Z hemmer $ 00016 // 00017 // 00018 // Author(s) : Michael Hemmer <hemmer@mpi-inf.mpg.de> 00019 // 00020 // ============================================================================ 00021 00022 #ifndef CGAL_POLYNOMIAL_COERCION_TRAITS_H 00023 #define CGAL_POLYNOMIAL_COERCION_TRAITS_H 00024 00025 // The coercion type of two polynomials is a polynomial in d=max(d1,d2) 00026 // variables, where d1 and d2 are the number of variables the two 00027 // polynomials. (This also includes the case of d1 = 0 or d2 = 0.) 00028 // Moreover, the new Innermost_coefficient_type is the coercion type of the 00029 // two Innermost_coefficient_types of the two involved polynomials. 00030 // (Again, this is generalized if one of the involved types is just a scalar 00031 // type) 00032 // Though the coercion type is clear, the problem is how to match the 00033 // variables. The recursive definition of Polynomial<Coeff> suggest that 00034 // the coercion type of two polynomial types Polynomial<A> and Polynomial<B> 00035 // is defined as Polynomial<C>, where C is the coercion type. 00036 // However, this is not in line with the fact that a Polynomial<A> 00037 // is interoperable with its coefficient type A, that is, if A is a polynomial 00038 // the variables of A should not be moved outward while casting A to 00039 // Polynomial<A>. 00040 00041 #include <CGAL/Polynomial/misc.h> 00042 00043 CGAL_BEGIN_NAMESPACE 00044 00045 namespace CGALi{ 00046 00047 // A has less variables than B 00048 template <typename A, typename B, bool less > 00049 class Coercion_traits_for_polynomial_comp_d 00050 :public Coercion_traits_for_polynomial_comp_d< B, A , false >{}; 00051 00052 // Polynomial<A> has more variables than B 00053 template <typename A, typename B > 00054 class Coercion_traits_for_polynomial_comp_d< Polynomial<A>, B , false>{ 00055 typedef Coercion_traits<A,B> CT; 00056 public: 00057 typedef CGAL::Tag_true Are_explicit_interoperable; 00058 typedef CGAL::Tag_false Are_implicit_interoperable; 00059 00060 typedef Polynomial<typename CT::Type> Type; 00061 struct Cast{ 00062 typedef Type result_type; 00063 Type operator()(const Polynomial<A>& poly) const { 00064 typename CT::Cast cast; 00065 return Type(::boost::make_transform_iterator(poly.begin(),cast), 00066 ::boost::make_transform_iterator(poly.end() ,cast)); 00067 } 00068 Type operator()(const B& x) const { 00069 typename CT::Cast cast; 00070 return Type(cast(x)); 00071 } 00072 }; 00073 }; 00074 00075 // number of variables is different 00076 template <typename A, typename B, int a, int b> 00077 class Coercion_traits_for_polynomial_equal_d 00078 :public Coercion_traits_for_polynomial_comp_d <A,B, a < b >{}; 00079 00080 // number of variables is equal and at least one. 00081 template <class A,class B, int d> 00082 class Coercion_traits_for_polynomial_equal_d<Polynomial<A>, Polynomial<B>, d, d >{ 00083 typedef Coercion_traits<A,B> CT; 00084 public: 00085 typedef CGAL::Tag_true Are_explicit_interoperable; 00086 typedef CGAL::Tag_false Are_implicit_interoperable; 00087 typedef Polynomial<typename CT::Type> Type; 00088 struct Cast{ 00089 typedef Type result_type; 00090 Type operator()(const Polynomial<A>& poly) const { 00091 typename CT::Cast cast; 00092 return Type(::boost::make_transform_iterator(poly.begin(),cast), 00093 ::boost::make_transform_iterator(poly.end() ,cast)); 00094 } 00095 Type operator()(const Polynomial<B>& poly) const { 00096 typename CT::Cast cast; 00097 return Type(::boost::make_transform_iterator(poly.begin(),cast), 00098 ::boost::make_transform_iterator(poly.end() ,cast)); 00099 } 00100 }; 00101 }; 00102 00103 // determine number of variables in each polynomial 00104 template <typename A, typename B> 00105 class Coercion_traits_for_polynomial 00106 : public Coercion_traits_for_polynomial_equal_d 00107 < A , B , Dimension<A>::value, Dimension<B>::value >{}; 00108 00109 }// namespace CGALi 00110 00111 template <class A,class B> 00112 class Coercion_traits_for_level< Polynomial<A> , Polynomial<B>, CTL_POLYNOMIAL > 00113 :public CGALi::Coercion_traits_for_polynomial< Polynomial<A>, Polynomial<B> > 00114 {}; 00115 template <class A,class B> 00116 class Coercion_traits_for_level< Polynomial<A> , B , CTL_POLYNOMIAL > 00117 :public CGALi::Coercion_traits_for_polynomial< Polynomial<A>, B > 00118 {}; 00119 template <class A,class B> 00120 class Coercion_traits_for_level< A , Polynomial<B> , CTL_POLYNOMIAL > 00121 :public CGALi::Coercion_traits_for_polynomial< A , Polynomial<B> > 00122 {}; 00123 00124 00125 00126 00127 #if 0 00128 // COERCION_TRAITS BEGIN 00129 00130 //Coercion_traits_polynomial----------------------------------- 00131 // If there is a Polynomial_traits, valid for more than one Polynomial 00132 // class this part should be adapted, using a Polynomial_traits 00133 // and the nesting_depth 00134 template <class A,class B> 00135 class Coercion_traits_for_level<Polynomial<A>, Polynomial<B>, CTL_POLYNOMIAL >{ 00136 typedef Coercion_traits<A,B> CT; 00137 public: 00138 typedef CGAL::Tag_true Are_explicit_interoperable; 00139 typedef CGAL::Tag_false Are_implicit_interoperable; 00140 typedef Polynomial<typename CT::Type> Type; 00141 struct Cast{ 00142 typedef Type result_type; 00143 Type operator()(const Polynomial<A>& poly) const { 00144 typename CT::Cast cast; 00145 return Type(::boost::make_transform_iterator(poly.begin(),cast), 00146 ::boost::make_transform_iterator(poly.end() ,cast)); 00147 } 00148 Type operator()(const Polynomial<B>& poly) const { 00149 typename CT::Cast cast; 00150 return Type(::boost::make_transform_iterator(poly.begin(),cast), 00151 ::boost::make_transform_iterator(poly.end() ,cast)); 00152 } 00153 }; 00154 }; 00155 00156 template <class A,class B> 00157 class Coercion_traits_for_level<Polynomial<A>,B ,CTL_POLYNOMIAL >{ 00158 typedef Coercion_traits<A,B> CT; 00159 public: 00160 typedef CGAL::Tag_true Are_explicit_interoperable; 00161 typedef CGAL::Tag_false Are_implicit_interoperable; 00162 00163 typedef Polynomial<typename CT::Type> Type; 00164 struct Cast{ 00165 typedef Type result_type; 00166 Type operator()(const Polynomial<A>& poly) const { 00167 typename CT::Cast cast; 00168 return Type(::boost::make_transform_iterator(poly.begin(),cast), 00169 ::boost::make_transform_iterator(poly.end() ,cast)); 00170 } 00171 Type operator()(const B& x) const { 00172 typename CT::Cast cast; 00173 return Type(cast(x)); 00174 } 00175 }; 00176 }; 00177 template <class A,class B> 00178 class Coercion_traits_for_level<B,Polynomial<A>,CTL_POLYNOMIAL > 00179 :public Coercion_traits_for_level<Polynomial<A>,B,CTL_POLYNOMIAL > 00180 {}; 00181 00182 #endif // 0 00183 00184 // COERCION_TRAITS END 00185 00186 CGAL_END_NAMESPACE 00187 00188 #endif // CGAL_POLYNOMIAL_COERCION_TRAITS_H