blitz Version 0.10
|
00001 // -*- C++ -*- 00002 /*************************************************************************** 00003 * blitz/numtrait.h Declaration of the NumericTypeTraits class 00004 * 00005 * $Id: numtrait.h,v 1.7 2011/03/25 22:41:16 julianc Exp $ 00006 * 00007 * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org> 00008 * 00009 * This file is a part of Blitz. 00010 * 00011 * Blitz is free software: you can redistribute it and/or modify 00012 * it under the terms of the GNU Lesser General Public License 00013 * as published by the Free Software Foundation, either version 3 00014 * of the License, or (at your option) any later version. 00015 * 00016 * Blitz is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with Blitz. If not, see <http://www.gnu.org/licenses/>. 00023 * 00024 * Suggestions: blitz-devel@lists.sourceforge.net 00025 * Bugs: blitz-support@lists.sourceforge.net 00026 * 00027 * For more information, please see the Blitz++ Home Page: 00028 * https://sourceforge.net/projects/blitz/ 00029 * 00030 ***************************************************************************/ 00031 00032 #ifndef BZ_NUMTRAIT_H 00033 #define BZ_NUMTRAIT_H 00034 00035 #ifndef BZ_BLITZ_H 00036 #include <blitz/blitz.h> 00037 #endif 00038 00039 BZ_NAMESPACE(blitz) 00040 00041 #ifndef BZ_USE_NUMTRAIT 00042 #define BZ_SUMTYPE(X) X 00043 #define BZ_DIFFTYPE(X) X 00044 #define BZ_FLOATTYPE(X) X 00045 #define BZ_SIGNEDTYPE(X) X 00046 #else 00047 00048 #define BZ_SUMTYPE(X) _bz_typename NumericTypeTraits<X>::T_sumtype 00049 #define BZ_DIFFTYPE(X) _bz_typename NumericTypeTraits<X>::T_difftype 00050 #define BZ_FLOATTYPE(X) _bz_typename NumericTypeTraits<X>::T_floattype 00051 #define BZ_SIGNEDTYPE(X) _bz_typename NumericTypeTraits<X>::T_signedtype 00052 00053 template<typename P_numtype> 00054 class NumericTypeTraits { 00055 public: 00056 typedef P_numtype T_sumtype; // Type to be used for summing 00057 typedef P_numtype T_difftype; // Type to be used for difference 00058 typedef P_numtype T_floattype; // Type to be used for floating-point 00059 // calculations 00060 typedef P_numtype T_signedtype; // Type to be used for signed calculations 00061 enum { hasTrivialCtor = 0 }; // Assume the worst 00062 }; 00063 00064 #define BZDECLNUMTRAIT(X,Y,Z,W,U) \ 00065 template<> \ 00066 class NumericTypeTraits<X> { \ 00067 public: \ 00068 typedef Y T_sumtype; \ 00069 typedef Z T_difftype; \ 00070 typedef W T_floattype; \ 00071 typedef U T_signedtype; \ 00072 enum { hasTrivialCtor = 1 }; \ 00073 } 00074 00075 #ifdef BZ_HAVE_BOOL 00076 BZDECLNUMTRAIT(bool,unsigned,int,float,int); 00077 #endif 00078 00079 BZDECLNUMTRAIT(char,int,int,float,char); 00080 BZDECLNUMTRAIT(unsigned char, unsigned, int, float,int); 00081 BZDECLNUMTRAIT(short int, int, int, float, short int); 00082 BZDECLNUMTRAIT(short unsigned int, unsigned int, int, float, int); 00083 BZDECLNUMTRAIT(int, long, int, float, int); 00084 BZDECLNUMTRAIT(unsigned int, unsigned long, int, float, long); 00085 BZDECLNUMTRAIT(long, long, long, double, long); 00086 BZDECLNUMTRAIT(unsigned long, unsigned long, long, double, long); 00087 BZDECLNUMTRAIT(float, double, float, float, float); 00088 BZDECLNUMTRAIT(double, double, double, double, double); 00089 00090 #ifdef BZ_HAVE_COMPLEX 00091 // BZDECLNUMTRAIT(complex<float>, complex<double>, complex<float>, complex<float>); 00092 // BZDECLNUMTRAIT(complex<double>, complex<long double>, complex<double>, complex<double>); 00093 #endif // BZ_HAVE_COMPLEX 00094 00095 #endif // BZ_USE_NUMTRAIT 00096 00097 BZ_NAMESPACE_END 00098 00099 #endif // BZ_NUMTRAIT_H