| 1 | /***************************************************************************
 | 
|---|
| 2 |  * blitz/numtrait.h      Declaration of the NumericTypeTraits class
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  * $Id: numtrait.h,v 1.1.1.1 1999-11-26 16:37:04 ansari Exp $
 | 
|---|
| 5 |  *
 | 
|---|
| 6 |  * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca>
 | 
|---|
| 7 |  *
 | 
|---|
| 8 |  * This program is free software; you can redistribute it and/or
 | 
|---|
| 9 |  * modify it under the terms of the GNU General Public License
 | 
|---|
| 10 |  * as published by the Free Software Foundation; either version 2
 | 
|---|
| 11 |  * of the License, or (at your option) any later version.
 | 
|---|
| 12 |  *
 | 
|---|
| 13 |  * This program is distributed in the hope that it will be useful,
 | 
|---|
| 14 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 15 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
| 16 |  * GNU General Public License for more details.
 | 
|---|
| 17 |  *
 | 
|---|
| 18 |  * Suggestions:          blitz-suggest@cybervision.com
 | 
|---|
| 19 |  * Bugs:                 blitz-bugs@cybervision.com
 | 
|---|
| 20 |  *
 | 
|---|
| 21 |  * For more information, please see the Blitz++ Home Page:
 | 
|---|
| 22 |  *    http://seurat.uwaterloo.ca/blitz/
 | 
|---|
| 23 |  *
 | 
|---|
| 24 |  ***************************************************************************
 | 
|---|
| 25 |  * $Log: not supported by cvs2svn $
 | 
|---|
| 26 |  * Revision 1.1.1.1  1999/04/09  17:58:59  ansari
 | 
|---|
| 27 |  * Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99
 | 
|---|
| 28 |  *
 | 
|---|
| 29 |  * Revision 1.5  1998/03/14 00:04:47  tveldhui
 | 
|---|
| 30 |  * 0.2-alpha-05
 | 
|---|
| 31 |  *
 | 
|---|
| 32 |  * Revision 1.4  1997/07/16 14:51:20  tveldhui
 | 
|---|
| 33 |  * Update: Alpha release 0.2 (Arrays)
 | 
|---|
| 34 |  *
 | 
|---|
| 35 |  * Revision 1.3  1997/01/24 14:42:00  tveldhui
 | 
|---|
| 36 |  * Periodic RCS update
 | 
|---|
| 37 |  *
 | 
|---|
| 38 |  * Revision 1.2  1997/01/23 03:28:28  tveldhui
 | 
|---|
| 39 |  * Periodic RCS update
 | 
|---|
| 40 |  *
 | 
|---|
| 41 |  * Revision 1.1  1997/01/13 22:19:58  tveldhui
 | 
|---|
| 42 |  * Periodic RCS update
 | 
|---|
| 43 |  *
 | 
|---|
| 44 |  *
 | 
|---|
| 45 |  */
 | 
|---|
| 46 | 
 | 
|---|
| 47 | #ifndef BZ_NUMTRAIT_H
 | 
|---|
| 48 | #define BZ_NUMTRAIT_H
 | 
|---|
| 49 | 
 | 
|---|
| 50 | #ifndef BZ_BLITZ_H
 | 
|---|
| 51 |  #include <blitz/blitz.h>
 | 
|---|
| 52 | #endif
 | 
|---|
| 53 | 
 | 
|---|
| 54 | BZ_NAMESPACE(blitz)
 | 
|---|
| 55 | 
 | 
|---|
| 56 | #ifndef BZ_USE_NUMTRAIT
 | 
|---|
| 57 |   #define BZ_SUMTYPE(X)    X
 | 
|---|
| 58 |   #define BZ_DIFFTYPE(X)   X
 | 
|---|
| 59 |   #define BZ_FLOATTYPE(X)  X
 | 
|---|
| 60 |   #define BZ_SIGNEDTYPE(X) X
 | 
|---|
| 61 | #else
 | 
|---|
| 62 | 
 | 
|---|
| 63 | #define BZ_SUMTYPE(X)   _bz_typename NumericTypeTraits<X>::T_sumtype
 | 
|---|
| 64 | #define BZ_DIFFTYPE(X)  _bz_typename NumericTypeTraits<X>::T_difftype
 | 
|---|
| 65 | #define BZ_FLOATTYPE(X) _bz_typename NumericTypeTraits<X>::T_floattype
 | 
|---|
| 66 | #define BZ_SIGNEDTYPE(X) _bz_typename NumericTypeTraits<X>::T_signedtype
 | 
|---|
| 67 | 
 | 
|---|
| 68 | template<class P_numtype>
 | 
|---|
| 69 | class NumericTypeTraits {
 | 
|---|
| 70 | public:
 | 
|---|
| 71 |     typedef P_numtype T_sumtype;    // Type to be used for summing
 | 
|---|
| 72 |     typedef P_numtype T_difftype;   // Type to be used for difference
 | 
|---|
| 73 |     typedef P_numtype T_floattype;  // Type to be used for floating-point
 | 
|---|
| 74 |                                     // calculations
 | 
|---|
| 75 |     typedef P_numtype T_signedtype; // Type to be used for signed calculations
 | 
|---|
| 76 | };
 | 
|---|
| 77 | 
 | 
|---|
| 78 | #define BZDECLNUMTRAIT(X,Y,Z,W,U)                                   \
 | 
|---|
| 79 |     template<>                                                      \
 | 
|---|
| 80 |     class NumericTypeTraits<X> {                                    \
 | 
|---|
| 81 |     public:                                                         \
 | 
|---|
| 82 |         typedef Y T_sumtype;                                        \
 | 
|---|
| 83 |         typedef Z T_difftype;                                       \
 | 
|---|
| 84 |         typedef W T_floattype;                                      \
 | 
|---|
| 85 |         typedef U T_signedtype;                                     \
 | 
|---|
| 86 |     }                                                               
 | 
|---|
| 87 | 
 | 
|---|
| 88 | #ifdef BZ_BOOL
 | 
|---|
| 89 |     BZDECLNUMTRAIT(bool,unsigned,int,float,int);
 | 
|---|
| 90 | #endif
 | 
|---|
| 91 | 
 | 
|---|
| 92 | BZDECLNUMTRAIT(char,int,int,float,char);
 | 
|---|
| 93 | BZDECLNUMTRAIT(unsigned char, unsigned, int, float,int);
 | 
|---|
| 94 | BZDECLNUMTRAIT(short int, int, int, float, short int);
 | 
|---|
| 95 | BZDECLNUMTRAIT(short unsigned int, unsigned int, int, float, int);
 | 
|---|
| 96 | BZDECLNUMTRAIT(int, long, int, float, int);
 | 
|---|
| 97 | BZDECLNUMTRAIT(unsigned int, unsigned long, int, float, long);
 | 
|---|
| 98 | BZDECLNUMTRAIT(long, long, long, double, long);
 | 
|---|
| 99 | BZDECLNUMTRAIT(unsigned long, unsigned long, long, double, long);
 | 
|---|
| 100 | BZDECLNUMTRAIT(float, double, float, float, float);
 | 
|---|
| 101 | BZDECLNUMTRAIT(double, double, double, double, double);
 | 
|---|
| 102 | 
 | 
|---|
| 103 | #ifdef BZ_HAVE_COMPLEX
 | 
|---|
| 104 | // BZDECLNUMTRAIT(complex<float>, complex<double>, complex<float>, complex<float>);
 | 
|---|
| 105 | // BZDECLNUMTRAIT(complex<double>, complex<long double>, complex<double>, complex<double>);
 | 
|---|
| 106 | #endif // BZ_HAVE_COMPLEX
 | 
|---|
| 107 | 
 | 
|---|
| 108 | #endif // BZ_USE_NUMTRAIT
 | 
|---|
| 109 | 
 | 
|---|
| 110 | BZ_NAMESPACE_END
 | 
|---|
| 111 | 
 | 
|---|
| 112 | #endif // BZ_NUMTRAIT_H
 | 
|---|