5164
|
1 /* |
|
2 |
|
3 Copyright (C) 2004 David Bateman |
|
4 Copyright (C) 1998-2004 Andy Adler |
|
5 |
|
6 Octave is free software; you can redistribute it and/or modify it |
|
7 under the terms of the GNU General Public License as published by the |
|
8 Free Software Foundation; either version 2, or (at your option) any |
|
9 later version. |
|
10 |
|
11 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 for more details. |
|
15 |
|
16 You should have received a copy of the GNU General Public License |
|
17 along with this program; see the file COPYING. If not, write to the Free |
|
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
19 |
|
20 */ |
|
21 |
|
22 #if !defined (octave_MSparse_defs_h) |
|
23 #define octave_MSparse_defs_h 1 |
|
24 |
|
25 // Nothing like a little CPP abuse to brighten everyone's day. |
|
26 |
|
27 // A macro that can be used to declare and instantiate OP= operators. |
|
28 #define SPARSE_OP_ASSIGN_DECL(A_T, E_T, OP, PFX, LTGT, RHS_T) \ |
|
29 PFX A_T<E_T>& \ |
|
30 operator OP LTGT (A_T<E_T>&, const RHS_T&) |
|
31 |
|
32 // All the OP= operators that we care about. |
|
33 #define SPARSE_OP_ASSIGN_DECLS(A_T, E_T, PFX, LTGT, RHS_T) \ |
|
34 SPARSE_OP_ASSIGN_DECL (A_T, E_T, +=, PFX, LTGT, RHS_T); \ |
|
35 SPARSE_OP_ASSIGN_DECL (A_T, E_T, -=, PFX, LTGT, RHS_T); |
|
36 |
|
37 // Generate forward declarations for OP= operators. |
|
38 #define SPARSE_OP_ASSIGN_FWD_DECLS(A_T, RHS_T) \ |
|
39 SPARSE_OP_ASSIGN_DECLS (A_T, T, template <typename T>, , RHS_T) |
|
40 |
|
41 // Generate friend declarations for the OP= operators. |
|
42 #define SPARSE_OP_ASSIGN_FRIENDS(A_T, RHS_T) \ |
|
43 SPARSE_OP_ASSIGN_DECLS (A_T, T, friend, <>, RHS_T) |
|
44 |
|
45 // Instantiate the OP= operators. |
|
46 #define SPARSE_OP_ASSIGN_DEFS(A_T, E_T, RHS_T) \ |
|
47 SPARSE_OP_ASSIGN_DECLS (A_T, E_T, template, , RHS_T) |
|
48 |
|
49 // A function that can be used to forward OP= operations from derived |
|
50 // classes back to us. |
|
51 #define SPARSE_OP_ASSIGN_FWD_FCN(R, F, T, C_X, X_T, C_Y, Y_T) \ |
|
52 inline R \ |
|
53 F (X_T& x, const Y_T& y) \ |
|
54 { \ |
|
55 return R (F (C_X (x), C_Y (y))); \ |
|
56 } |
|
57 |
|
58 // All the OP= operators that we care about forwarding. |
|
59 #define SPARSE_OP_ASSIGN_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \ |
|
60 SPARSE_OP_ASSIGN_FWD_FCN (R, operator +=, T, C_X, X_T, C_Y, Y_T) \ |
|
61 SPARSE_OP_ASSIGN_FWD_FCN (R, operator -=, T, C_X, X_T, C_Y, Y_T) |
|
62 |
|
63 // A macro that can be used to declare and instantiate unary operators. |
|
64 #define SPARSE_UNOP(A_T, E_T, F, PFX, LTGT) \ |
|
65 PFX A_T<E_T> \ |
|
66 F LTGT (const A_T<E_T>&) |
|
67 |
|
68 // All the unary operators that we care about. |
|
69 #define SPARSE_UNOP_DECLS(A_T, E_T, PFX, LTGT) \ |
|
70 SPARSE_UNOP (A_T, E_T, operator +, PFX, LTGT); \ |
|
71 SPARSE_UNOP (A_T, E_T, operator -, PFX, LTGT); |
|
72 |
|
73 // Generate forward declarations for unary operators. |
|
74 #define SPARSE_UNOP_FWD_DECLS(A_T) \ |
|
75 SPARSE_UNOP_DECLS (A_T, T, template <typename T>, ) |
|
76 |
|
77 // Generate friend declarations for the unary operators. |
|
78 #define SPARSE_UNOP_FRIENDS(A_T) \ |
|
79 SPARSE_UNOP_DECLS (A_T, T, friend, <>) |
|
80 |
|
81 // Instantiate the unary operators. |
|
82 #define SPARSE_UNOP_DEFS(A_T, E_T) \ |
|
83 SPARSE_UNOP_DECLS (A_T, E_T, template, ) |
|
84 |
|
85 // A function that can be used to forward unary operations from derived |
|
86 // classes back to us. |
|
87 #define SPARSE_UNOP_FWD_FCN(R, F, T, C_X, X_T) \ |
|
88 inline R \ |
|
89 F (const X_T& x) \ |
|
90 { \ |
|
91 return R (F (C_X (x))); \ |
|
92 } |
|
93 |
|
94 // All the unary operators that we care about forwarding. |
|
95 #define SPARSE_UNOP_FWD_DEFS(R, T, C_X, X_T) \ |
|
96 SPARSE_UNOP_FWD_FCN (R, operator +, T, C_X, X_T) \ |
|
97 SPARSE_UNOP_FWD_FCN (R, operator -, T, C_X, X_T) |
|
98 |
|
99 // A macro that can be used to declare and instantiate binary operators. |
|
100 #define SPARSE_BINOP_DECL(A_T, E_T, F, PFX, LTGT, X_T, Y_T) \ |
|
101 PFX A_T<E_T> \ |
|
102 F LTGT (const X_T&, const Y_T&) |
|
103 |
|
104 // All the binary operators that we care about. We have two |
|
105 // sets of macros since the MArray OP MArray operations use functions |
|
106 // (product and quotient) instead of operators (*, /). |
|
107 #define SPARSE_BINOP_DECLS(A_T, F_T, E_T, PFX, LTGT, X_T, Y_T) \ |
|
108 SPARSE_BINOP_DECL (F_T, E_T, operator +, PFX, LTGT, X_T, Y_T); \ |
|
109 SPARSE_BINOP_DECL (F_T, E_T, operator -, PFX, LTGT, X_T, Y_T); \ |
|
110 SPARSE_BINOP_DECL (A_T, E_T, operator *, PFX, LTGT, X_T, Y_T); \ |
|
111 SPARSE_BINOP_DECL (A_T, E_T, operator /, PFX, LTGT, X_T, Y_T); |
|
112 |
|
113 #define SPARSE_AA_BINOP_DECLS(A_T, E_T, PFX, LTGT) \ |
|
114 SPARSE_BINOP_DECL (A_T, E_T, operator +, PFX, LTGT, A_T<E_T>, A_T<E_T>); \ |
|
115 SPARSE_BINOP_DECL (A_T, E_T, operator -, PFX, LTGT, A_T<E_T>, A_T<E_T>); \ |
|
116 SPARSE_BINOP_DECL (A_T, E_T, quotient, PFX, LTGT, A_T<E_T>, A_T<E_T>); \ |
|
117 SPARSE_BINOP_DECL (A_T, E_T, product, PFX, LTGT, A_T<E_T>, A_T<E_T>); |
|
118 |
|
119 // Generate forward declarations for binary operators. |
|
120 #define SPARSE_BINOP_FWD_DECLS(A_T, F_T) \ |
|
121 SPARSE_BINOP_DECLS (A_T, F_T, T, template <typename T>, , A_T<T>, T) \ |
|
122 SPARSE_BINOP_DECLS (A_T, F_T, T, template <typename T>, , T, A_T<T>) \ |
|
123 SPARSE_AA_BINOP_DECLS (A_T, T, template <typename T>, ) |
|
124 |
|
125 // Generate friend declarations for the binary operators. |
|
126 #define SPARSE_BINOP_FRIENDS(A_T, F_T) \ |
|
127 SPARSE_BINOP_DECLS (A_T, F_T, T, friend, <>, A_T<T>, T) \ |
|
128 SPARSE_BINOP_DECLS (A_T, F_T, T, friend, <>, T, A_T<T>) \ |
|
129 SPARSE_AA_BINOP_DECLS (A_T, T, friend, <>) |
|
130 |
|
131 // Instantiate the binary operators. |
|
132 #define SPARSE_BINOP_DEFS(A_T, F_T, E_T) \ |
|
133 SPARSE_BINOP_DECLS (A_T, F_T, E_T, template, , A_T<E_T>, E_T) \ |
|
134 SPARSE_BINOP_DECLS (A_T, F_T, E_T, template, , E_T, A_T<E_T>) \ |
|
135 SPARSE_AA_BINOP_DECLS (A_T, E_T, template, ) |
|
136 |
|
137 // A function that can be used to forward binary operations from derived |
|
138 // classes back to us. |
|
139 #define SPARSE_BINOP_FWD_FCN(R, F, T, C_X, X_T, C_Y, Y_T) \ |
|
140 inline R \ |
|
141 F (const X_T& x, const Y_T& y) \ |
|
142 { \ |
|
143 return R (F (C_X (x), C_Y (y))); \ |
|
144 } |
|
145 |
|
146 // The binary operators that we care about forwarding. We have two |
|
147 // sets of macros since the MSparse OP MSparse operations use functions |
|
148 // (product and quotient) instead of operators (*, /). |
|
149 #define SPARSE_BINOP_FWD_DEFS(R, F, T, C_X, X_T, C_Y, Y_T) \ |
|
150 SPARSE_BINOP_FWD_FCN (F, operator +, T, C_X, X_T, C_Y, Y_T) \ |
|
151 SPARSE_BINOP_FWD_FCN (F, operator -, T, C_X, X_T, C_Y, Y_T) \ |
|
152 SPARSE_BINOP_FWD_FCN (R, operator *, T, C_X, X_T, C_Y, Y_T) \ |
|
153 SPARSE_BINOP_FWD_FCN (R, operator /, T, C_X, X_T, C_Y, Y_T) |
|
154 |
|
155 #define SPARSE_AA_BINOP_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \ |
|
156 SPARSE_BINOP_FWD_FCN (R, operator +, T, C_X, X_T, C_Y, Y_T) \ |
|
157 SPARSE_BINOP_FWD_FCN (R, operator -, T, C_X, X_T, C_Y, Y_T) \ |
|
158 SPARSE_BINOP_FWD_FCN (R, product, T, C_X, X_T, C_Y, Y_T) \ |
|
159 SPARSE_BINOP_FWD_FCN (R, quotient, T, C_X, X_T, C_Y, Y_T) |
|
160 |
|
161 // Forward declarations for the MSparse operators. |
|
162 #define SPARSE_OPS_FORWARD_DECLS(A_T, F_T) \ |
|
163 template <class T> \ |
|
164 class A_T; \ |
|
165 \ |
|
166 /* SPARSE_OP_ASSIGN_FWD_DECLS (A_T, T) */ \ |
|
167 SPARSE_OP_ASSIGN_FWD_DECLS (A_T, A_T<T>) \ |
|
168 SPARSE_UNOP_FWD_DECLS (A_T) \ |
|
169 SPARSE_BINOP_FWD_DECLS (A_T, F_T) |
|
170 |
|
171 // Friend declarations for the MSparse operators. |
|
172 #define SPARSE_OPS_FRIEND_DECLS(A_T, F_T) \ |
|
173 /* SPARSE_OP_ASSIGN_FRIENDS (A_T, T) */ \ |
|
174 SPARSE_OP_ASSIGN_FRIENDS (A_T, A_T<T>) \ |
|
175 SPARSE_UNOP_FRIENDS (A_T) \ |
|
176 SPARSE_BINOP_FRIENDS (A_T, F_T) |
|
177 |
|
178 // The following macros are for external use. |
|
179 |
|
180 // Instantiate all the MSparse friends for MSparse element type T. |
|
181 #define INSTANTIATE_SPARSE_FRIENDS(T) \ |
|
182 /* SPARSE_OP_ASSIGN_DEFS (MSparse, T, T) */ \ |
|
183 SPARSE_OP_ASSIGN_DEFS (MSparse, T, MSparse<T>) \ |
|
184 SPARSE_UNOP_DEFS (MSparse, T) \ |
|
185 SPARSE_BINOP_DEFS (MSparse, MArray2, T) |
|
186 |
|
187 // Define all the MSparse forwarding functions for return type R and |
|
188 // MSparse element type T |
|
189 #define SPARSE_FORWARD_DEFS(B, R, F, T) \ |
|
190 /* SPARSE_OP_ASSIGN_FWD_DEFS */ \ |
|
191 /* (R, T, dynamic_cast<B<T>&>, R, , T) */ \ |
|
192 \ |
|
193 SPARSE_OP_ASSIGN_FWD_DEFS \ |
|
194 (R, T, \ |
|
195 dynamic_cast<B<T>&>, R, dynamic_cast<const B<T>&>, R) \ |
|
196 \ |
|
197 SPARSE_UNOP_FWD_DEFS \ |
|
198 (R, T, dynamic_cast<const B<T>&>, R) \ |
|
199 \ |
|
200 SPARSE_BINOP_FWD_DEFS \ |
|
201 (R, F, T, dynamic_cast<const B<T>&>, R, , T) \ |
|
202 \ |
|
203 SPARSE_BINOP_FWD_DEFS \ |
|
204 (R, F, T, , T, dynamic_cast<const B<T>&>, R) \ |
|
205 \ |
|
206 SPARSE_AA_BINOP_FWD_DEFS \ |
|
207 (R, T, dynamic_cast<const B<T>&>, R, dynamic_cast<const B<T>&>, R) |
|
208 |
|
209 // Now we have all the definitions we need. |
|
210 |
|
211 #endif |
|
212 |
|
213 /* |
|
214 ;;; Local Variables: *** |
|
215 ;;; mode: C++ *** |
|
216 ;;; End: *** |
|
217 */ |