BWAPI
|
00001 /**************************************************************************** 00002 * Core Library Version 1.7, August 2004 00003 * Copyright (c) 1995-2004 Exact Computation Project 00004 * All rights reserved. 00005 * 00006 * This file is part of CORE (http://cs.nyu.edu/exact/core/); you may 00007 * redistribute it under the terms of the Q Public License version 1.0. 00008 * See the file LICENSE.QPL distributed with CORE. 00009 * 00010 * Licensees holding a valid commercial license may use this file in 00011 * accordance with the commercial license agreement provided with the 00012 * software. 00013 * 00014 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00015 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00016 * 00017 * 00018 * File: Expr.h 00019 * Synopsis: a class of Expression in Level 3 00020 * 00021 * Written by 00022 * Koji Ouchi <ouchi@simulation.nyu.edu> 00023 * Chee Yap <yap@cs.nyu.edu> 00024 * Igor Pechtchanski <pechtcha@cs.nyu.edu> 00025 * Vijay Karamcheti <vijayk@cs.nyu.edu> 00026 * Chen Li <chenli@cs.nyu.edu> 00027 * Zilin Du <zilin@cs.nyu.edu> 00028 * Sylvain Pion <pion@cs.nyu.edu> 00029 * Vikram Sharma<sharma@cs.nyu.edu> 00030 * 00031 * WWW URL: http://cs.nyu.edu/exact/ 00032 * Email: exact@cs.nyu.edu 00033 * 00034 * $Source: /home/exact/cvsroot/exact/corelib/inc/CORE/Promote.h,v $ 00035 * $Revision: 37060 $ $Date: 2007-03-13 19:10:39 +0100 (Tue, 13 Mar 2007) $ 00036 ***************************************************************************/ 00037 00038 #ifndef __PROMOTE_H__ 00039 #define __PROMOTE_H__ 00040 00041 #include <CGAL/CORE/Impl.h> 00042 00043 CORE_BEGIN_NAMESPACE 00044 00052 template < class NT > 00053 struct hasExactDivision { 00054 static bool check() { // This default function is supposed to work for NT other than BigRat or Expr 00055 return false; 00056 } 00057 }; 00058 00059 template<> struct hasExactDivision<Expr> { 00060 static bool check() { 00061 return true; 00062 } 00063 }; 00064 template<> struct hasExactDivision<BigRat> { 00065 static bool check() { 00066 return true; 00067 } 00068 }; 00069 00070 template<typename T1, typename T2> 00071 class Promotion; 00072 00073 template<typename T> 00074 class Promotion<T, T> { 00075 public: 00076 typedef T ResultT; 00077 }; 00078 00079 #define MAX_TYPE(T1, T2) \ 00080 typename Promotion<T1, T2>::ResultT 00081 00082 #define DEFINE_MAX_TYPE(T1, T2, Tr) \ 00083 template<> class Promotion<T1, T2> { \ 00084 public: \ 00085 typedef Tr ResultT; \ 00086 }; \ 00087 template<> class Promotion<T2, T1> { \ 00088 public: \ 00089 typedef Tr ResultT; \ 00090 }; 00091 00092 /* 00093 * For example: 00094 * 00095 * DEFINE_MAX_TYPE(BigInt, BigRat, BigRat) // define the promotion 00096 * 00097 * template<typename T1, typename T2> // define function f with type templates 00098 * MAX_TYPE(T1, T2) f(T1& , T2& ); 00099 * 00100 * or 00101 * 00102 * template<typename T1, typename T2> // define function f with type templates 00103 * const MAX_TYPE(T1, T2)& f(T1& , T2& ); 00104 * 00105 * BigInt a = 1; 00106 * BigRat b = "1/3"; 00107 * BigRat c = f(a, b); // or, typename Promotion<BigInt, BigRat>::ResultT c = f(a,b); 00108 * 00109 * REMARK: this mechanism is used by the eval function for polynomial evaluation (see Poly.tcc) 00110 * where the two types are NT (type of coefficients) and N (type of evaluation point). 00111 */ 00112 00113 /* 00114 * primary types: (11) 00115 * 00116 * bool, 00117 * char, unsigned char, 00118 * short, unsigned short, 00119 * int, unsigned int, 00120 * long, unsigned long, 00121 * float, double 00122 * 00123 * CORE types: (5) 00124 * 00125 * BigInt < BigFloat < BigRat < Real < Expr 00126 * 00127 * (NOTE: BigFloat here must be error-free) 00128 * 00129 */ 00130 00131 class BigInt; 00132 class BigFloat; 00133 class BigRat; 00134 class Expr; 00135 00136 DEFINE_MAX_TYPE(long, BigInt, BigInt) 00137 DEFINE_MAX_TYPE(long, BigFloat, BigFloat) 00138 DEFINE_MAX_TYPE(long, BigRat, BigRat) 00139 DEFINE_MAX_TYPE(long, Expr, Expr) 00140 00141 DEFINE_MAX_TYPE(int, BigInt, BigInt) 00142 DEFINE_MAX_TYPE(int, BigFloat, BigFloat) 00143 DEFINE_MAX_TYPE(int, BigRat, BigRat) 00144 DEFINE_MAX_TYPE(int, Expr, Expr) 00145 00146 DEFINE_MAX_TYPE(BigInt, BigFloat, BigFloat) 00147 DEFINE_MAX_TYPE(BigInt, BigRat, BigRat) 00148 DEFINE_MAX_TYPE(BigInt, Expr, Expr) 00149 00150 DEFINE_MAX_TYPE(BigFloat, BigRat, BigRat) 00151 DEFINE_MAX_TYPE(BigFloat, Expr, Expr) 00152 00153 DEFINE_MAX_TYPE(BigRat, Expr, Expr) 00154 00155 CORE_END_NAMESPACE 00156 00157 #endif //__PROMOTE_H__ 00158