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