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/Rational_traits.h $ 00016 // $Id: Rational_traits.h 39778 2007-08-08 15:59:25Z spion $ 00017 // 00018 // 00019 // Author(s) : Michael Hemmer <hemmer@mpi-inf.mpg.de> 00020 // 00021 // ============================================================================= 00022 00023 // This file is for backward compatibility 00024 // Rational_traits will be replaced by Fraction_traits 00025 00026 #ifndef CGAL_RATIONAL_TRAITS_H 00027 #define CGAL_RATIONAL_TRAITS_H 00028 00029 #include <CGAL/number_type_basic.h> 00030 #include <CGAL/Fraction_traits.h> 00031 00032 CGAL_BEGIN_NAMESPACE 00033 00034 namespace CGALi{ 00035 00036 template <class Rational, bool > 00037 struct Rational_traits_base 00038 { 00039 typedef Rational RT; 00040 00041 const RT& numerator (const Rational& r) const { return r; } 00042 RT denominator (const Rational&) const { return RT(1); } 00043 00044 Rational make_rational(const RT & n, const RT & d) const 00045 { return n / d; } 00046 }; 00047 00048 template <class Rational> 00049 struct Rational_traits_base<Rational, true> 00050 { 00051 private: 00052 typedef Fraction_traits<Rational> FT; 00053 typedef typename FT::Decompose Decomose; 00054 typedef typename FT::Compose Compose; 00055 00056 public: 00057 typedef typename FT::Numerator_type RT; 00058 00059 RT numerator (const Rational& r) const { 00060 RT num,den; 00061 Decomose()(r,num,den); 00062 return num; 00063 } 00064 00065 RT denominator (const Rational& r) const { 00066 RT num,den; 00067 Decomose()(r,num,den); 00068 return den; 00069 } 00070 00071 Rational make_rational(const RT & n, const RT & d) const 00072 { return Compose()(n,d); } 00073 Rational make_rational(const Rational & n, const Rational & d) const 00074 { return n/d; } 00075 }; 00076 }// namespace CGALi 00077 00078 // use Fraction_traits if Is_fraction && Num and Den are the same 00079 template <class T> 00080 class Rational_traits 00081 : public CGALi::Rational_traits_base<T, 00082 ::boost::is_same<typename Fraction_traits<T>::Is_fraction,Tag_true>::value 00083 && 00084 ::boost::is_same< 00085 typename Fraction_traits<T>::Numerator_type, 00086 typename Fraction_traits<T>::Denominator_type 00087 >::value > 00088 {}; 00089 00090 CGAL_END_NAMESPACE 00091 00092 #endif // CGAL_RATIONAL_TRAITS_H 00093 // EOF 00094