1 | /***************************************************************************
|
---|
2 | * blitz/numtrait.h Declaration of the NumericTypeTraits class
|
---|
3 | *
|
---|
4 | * $Id: numtrait.h,v 1.1.1.1 1999-04-09 17:58:59 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.5 1998/03/14 00:04:47 tveldhui
|
---|
27 | * 0.2-alpha-05
|
---|
28 | *
|
---|
29 | * Revision 1.4 1997/07/16 14:51:20 tveldhui
|
---|
30 | * Update: Alpha release 0.2 (Arrays)
|
---|
31 | *
|
---|
32 | * Revision 1.3 1997/01/24 14:42:00 tveldhui
|
---|
33 | * Periodic RCS update
|
---|
34 | *
|
---|
35 | * Revision 1.2 1997/01/23 03:28:28 tveldhui
|
---|
36 | * Periodic RCS update
|
---|
37 | *
|
---|
38 | * Revision 1.1 1997/01/13 22:19:58 tveldhui
|
---|
39 | * Periodic RCS update
|
---|
40 | *
|
---|
41 | *
|
---|
42 | */
|
---|
43 |
|
---|
44 | #ifndef BZ_NUMTRAIT_H
|
---|
45 | #define BZ_NUMTRAIT_H
|
---|
46 |
|
---|
47 | #ifndef BZ_BLITZ_H
|
---|
48 | #include <blitz/blitz.h>
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | BZ_NAMESPACE(blitz)
|
---|
52 |
|
---|
53 | #ifndef BZ_USE_NUMTRAIT
|
---|
54 | #define BZ_SUMTYPE(X) X
|
---|
55 | #define BZ_DIFFTYPE(X) X
|
---|
56 | #define BZ_FLOATTYPE(X) X
|
---|
57 | #define BZ_SIGNEDTYPE(X) X
|
---|
58 | #else
|
---|
59 |
|
---|
60 | #define BZ_SUMTYPE(X) _bz_typename NumericTypeTraits<X>::T_sumtype
|
---|
61 | #define BZ_DIFFTYPE(X) _bz_typename NumericTypeTraits<X>::T_difftype
|
---|
62 | #define BZ_FLOATTYPE(X) _bz_typename NumericTypeTraits<X>::T_floattype
|
---|
63 | #define BZ_SIGNEDTYPE(X) _bz_typename NumericTypeTraits<X>::T_signedtype
|
---|
64 |
|
---|
65 | template<class P_numtype>
|
---|
66 | class NumericTypeTraits {
|
---|
67 | public:
|
---|
68 | typedef P_numtype T_sumtype; // Type to be used for summing
|
---|
69 | typedef P_numtype T_difftype; // Type to be used for difference
|
---|
70 | typedef P_numtype T_floattype; // Type to be used for floating-point
|
---|
71 | // calculations
|
---|
72 | typedef P_numtype T_signedtype; // Type to be used for signed calculations
|
---|
73 | };
|
---|
74 |
|
---|
75 | #define BZDECLNUMTRAIT(X,Y,Z,W,U) \
|
---|
76 | template<> \
|
---|
77 | class NumericTypeTraits<X> { \
|
---|
78 | public: \
|
---|
79 | typedef Y T_sumtype; \
|
---|
80 | typedef Z T_difftype; \
|
---|
81 | typedef W T_floattype; \
|
---|
82 | typedef U T_signedtype; \
|
---|
83 | }
|
---|
84 |
|
---|
85 | #ifdef BZ_BOOL
|
---|
86 | BZDECLNUMTRAIT(bool,unsigned,int,float,int);
|
---|
87 | #endif
|
---|
88 |
|
---|
89 | BZDECLNUMTRAIT(char,int,int,float,char);
|
---|
90 | BZDECLNUMTRAIT(unsigned char, unsigned, int, float,int);
|
---|
91 | BZDECLNUMTRAIT(short int, int, int, float, short int);
|
---|
92 | BZDECLNUMTRAIT(short unsigned int, unsigned int, int, float, int);
|
---|
93 | BZDECLNUMTRAIT(int, long, int, float, int);
|
---|
94 | BZDECLNUMTRAIT(unsigned int, unsigned long, int, float, long);
|
---|
95 | BZDECLNUMTRAIT(long, long, long, double, long);
|
---|
96 | BZDECLNUMTRAIT(unsigned long, unsigned long, long, double, long);
|
---|
97 | BZDECLNUMTRAIT(float, double, float, float, float);
|
---|
98 | BZDECLNUMTRAIT(double, double, double, double, double);
|
---|
99 |
|
---|
100 | #ifdef BZ_HAVE_COMPLEX
|
---|
101 | // BZDECLNUMTRAIT(complex<float>, complex<double>, complex<float>, complex<float>);
|
---|
102 | // BZDECLNUMTRAIT(complex<double>, complex<long double>, complex<double>, complex<double>);
|
---|
103 | #endif // BZ_HAVE_COMPLEX
|
---|
104 |
|
---|
105 | #endif // BZ_USE_NUMTRAIT
|
---|
106 |
|
---|
107 | BZ_NAMESPACE_END
|
---|
108 |
|
---|
109 | #endif // BZ_NUMTRAIT_H
|
---|