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/Needs_parens_as_product.h $ 00016 // $Id: Needs_parens_as_product.h 48717 2009-04-08 11:54:51Z spion $ 00017 // 00018 // 00019 // Author(s) : Michael Hemmer <hemmer@mpi-inf.mpg.de> 00020 // 00021 // ============================================================================= 00022 00023 #ifndef CGAL_NEEDS_PARENTHESES_AS_PRODUCT_H 00024 #define CGAL_NEEDS_PARENTHESES_AS_PRODUCT_H 00025 00026 #include <CGAL/IO/io.h> 00027 00028 CGAL_BEGIN_NAMESPACE 00029 00033 class Parens_as_product_tag {}; 00034 00039 template <class NT> 00040 struct Needs_parens_as_product{ 00041 bool operator()(const NT&){ return true; } 00042 }; 00043 00048 template <class NT> 00049 inline bool needs_parens_as_product(const NT& x){ 00050 typedef Needs_parens_as_product<NT> NPAP; 00051 return NPAP()(x); 00052 } 00053 00058 template <class T> 00059 class Output_rep<T, Parens_as_product_tag> { 00060 const T& t; 00061 public: 00062 Output_rep(const T& tt) : t(tt) {} 00063 std::ostream& operator () (std::ostream& out) const { 00064 if ( needs_parens_as_product(t)) { 00065 return out << "(" << oformat(t) << ")"; 00066 } else { 00067 return out << oformat(t); 00068 } 00069 } 00070 }; 00071 00072 00073 // built-in number types: 00074 template <> struct Needs_parens_as_product<short>{ 00075 bool operator()(const short& x){return x < short(0);} 00076 }; 00077 template <> struct Needs_parens_as_product<int>{ 00078 bool operator()(const int& x){return x < int(0);} 00079 }; 00080 template <> struct Needs_parens_as_product<long>{ 00081 bool operator()(const long& x){return x < long(0);} 00082 }; 00083 00084 #ifdef CGAL_USE_LONG_LONG 00085 template <> struct Needs_parens_as_product<long long>{ 00086 bool operator()(const long long& x){return x < (long long)(0);} 00087 }; 00088 #endif 00089 00090 template <> struct Needs_parens_as_product<float>{ 00091 bool operator()(const float& x){return x < float(0);} 00092 }; 00093 template <> struct Needs_parens_as_product<double>{ 00094 bool operator()(const double& x){return x < double(0);} 00095 }; 00096 template <> struct Needs_parens_as_product<long double>{ 00097 bool operator()(const long double& x){return x < (long double)(0);} 00098 }; 00099 00100 CGAL_END_NAMESPACE 00101 00102 #endif //CGAL_NEEDS_PARENTHESES_AS_PRODUCT_H