BWAPI
|
00001 // Copyright (c) 2001-2006 INRIA Sophia-Antipolis (France). 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/Number_types/include/CGAL/NT_converter.h $ 00016 // $Id: NT_converter.h 49905 2009-06-13 19:46:56Z spion $ 00017 // 00018 // 00019 // Author(s) : Sylvain Pion 00020 00021 #ifndef CGAL_NT_CONVERTER_H 00022 #define CGAL_NT_CONVERTER_H 00023 00024 #include <functional> 00025 00026 template <bool> class Interval_nt; 00027 00028 CGAL_BEGIN_NAMESPACE 00029 00030 // A number type converter usable as default, using the conversion operator. 00031 00032 template < class NT1, class NT2 > 00033 struct NT_converter 00034 : public std::unary_function< NT1, NT2 > 00035 { 00036 NT2 00037 operator()(const NT1 &a) const 00038 { 00039 return NT2(a); 00040 } 00041 }; 00042 00043 // Some specializations for : 00044 // - double to call to_double(). 00045 // - Interval_nt<> to call to_interval(). 00046 // - NT1 == NT2 to return a reference instead of copying. 00047 00048 template < class NT1 > 00049 struct NT_converter < NT1, NT1 > 00050 : public std::unary_function< NT1, NT1 > 00051 { 00052 const NT1 & 00053 operator()(const NT1 &a) const 00054 { 00055 return a; 00056 } 00057 }; 00058 00059 template < class NT1 > 00060 struct NT_converter < NT1, double > 00061 : public std::unary_function< NT1, double > 00062 { 00063 double 00064 operator()(const NT1 &a) const 00065 { 00066 return CGAL_NTS to_double(a); 00067 } 00068 }; 00069 00070 template <> 00071 struct NT_converter < double, double > 00072 : public std::unary_function< double, double > 00073 { 00074 const double & 00075 operator()(const double &a) const 00076 { 00077 return a; 00078 } 00079 }; 00080 00081 template < class NT1, bool b > 00082 struct NT_converter < NT1, Interval_nt<b> > 00083 : public std::unary_function< NT1, Interval_nt<b> > 00084 { 00085 Interval_nt<b> 00086 operator()(const NT1 &a) const 00087 { 00088 return CGAL_NTS to_interval(a); 00089 } 00090 }; 00091 00092 template < bool b > 00093 struct NT_converter < Interval_nt<b>, Interval_nt<b> > 00094 : public std::unary_function< Interval_nt<b>, Interval_nt<b> > 00095 { 00096 const Interval_nt<b> & 00097 operator()(const Interval_nt<b> &a) const 00098 { 00099 return a; 00100 } 00101 }; 00102 00103 CGAL_END_NAMESPACE 00104 00105 #endif // CGAL_NT_CONVERTER_H