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 |
5307
|
17 along with this program; see the file COPYING. If not, write to the |
|
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
19 Boston, MA 02110-1301, USA. |
5164
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_MSparse_defs_h) |
|
24 #define octave_MSparse_defs_h 1 |
|
25 |
|
26 // Nothing like a little CPP abuse to brighten everyone's day. |
|
27 |
|
28 // A macro that can be used to declare and instantiate OP= operators. |
6708
|
29 #define SPARSE_OP_ASSIGN_DECL(A_T, E_T, OP, PFX, API, LTGT, RHS_T) \ |
|
30 PFX API A_T<E_T>& \ |
5164
|
31 operator OP LTGT (A_T<E_T>&, const RHS_T&) |
|
32 |
|
33 // All the OP= operators that we care about. |
6708
|
34 #define SPARSE_OP_ASSIGN_DECLS(A_T, E_T, PFX, API, LTGT, RHS_T) \ |
|
35 SPARSE_OP_ASSIGN_DECL (A_T, E_T, +=, PFX, API, LTGT, RHS_T); \ |
|
36 SPARSE_OP_ASSIGN_DECL (A_T, E_T, -=, PFX, API, LTGT, RHS_T); |
5164
|
37 |
|
38 // Generate forward declarations for OP= operators. |
6708
|
39 #define SPARSE_OP_ASSIGN_FWD_DECLS(A_T, RHS_T, API) \ |
|
40 SPARSE_OP_ASSIGN_DECLS (A_T, T, template <typename T>, API, , RHS_T) |
5164
|
41 |
|
42 // Generate friend declarations for the OP= operators. |
6708
|
43 #define SPARSE_OP_ASSIGN_FRIENDS(A_T, RHS_T, API) \ |
|
44 SPARSE_OP_ASSIGN_DECLS (A_T, T, friend, API, <>, RHS_T) |
5164
|
45 |
|
46 // Instantiate the OP= operators. |
6708
|
47 #define SPARSE_OP_ASSIGN_DEFS(A_T, E_T, RHS_T, API) \ |
|
48 SPARSE_OP_ASSIGN_DECLS (A_T, E_T, template, API, , RHS_T) |
5164
|
49 |
|
50 // A function that can be used to forward OP= operations from derived |
|
51 // classes back to us. |
|
52 #define SPARSE_OP_ASSIGN_FWD_FCN(R, F, T, C_X, X_T, C_Y, Y_T) \ |
|
53 inline R \ |
|
54 F (X_T& x, const Y_T& y) \ |
|
55 { \ |
|
56 return R (F (C_X (x), C_Y (y))); \ |
|
57 } |
|
58 |
|
59 // All the OP= operators that we care about forwarding. |
|
60 #define SPARSE_OP_ASSIGN_FWD_DEFS(R, 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 SPARSE_OP_ASSIGN_FWD_FCN (R, operator -=, T, C_X, X_T, C_Y, Y_T) |
|
63 |
|
64 // A macro that can be used to declare and instantiate unary operators. |
6708
|
65 #define SPARSE_UNOP(A_T, E_T, F, PFX, API, LTGT) \ |
|
66 PFX API A_T<E_T> \ |
5164
|
67 F LTGT (const A_T<E_T>&) |
|
68 |
|
69 // All the unary operators that we care about. |
6708
|
70 #define SPARSE_UNOP_DECLS(A_T, E_T, PFX, API, LTGT) \ |
|
71 SPARSE_UNOP (A_T, E_T, operator +, PFX, API, LTGT); \ |
|
72 SPARSE_UNOP (A_T, E_T, operator -, PFX, API, LTGT); |
5164
|
73 |
|
74 // Generate forward declarations for unary operators. |
6708
|
75 #define SPARSE_UNOP_FWD_DECLS(A_T, API) \ |
|
76 SPARSE_UNOP_DECLS (A_T, T, template <typename T>, API, ) |
5164
|
77 |
|
78 // Generate friend declarations for the unary operators. |
6708
|
79 #define SPARSE_UNOP_FRIENDS(A_T, API) \ |
|
80 SPARSE_UNOP_DECLS (A_T, T, friend, API, <>) |
5164
|
81 |
|
82 // Instantiate the unary operators. |
6708
|
83 #define SPARSE_UNOP_DEFS(A_T, E_T, API) \ |
|
84 SPARSE_UNOP_DECLS (A_T, E_T, template, API, ) |
5164
|
85 |
|
86 // A function that can be used to forward unary operations from derived |
|
87 // classes back to us. |
|
88 #define SPARSE_UNOP_FWD_FCN(R, F, T, C_X, X_T) \ |
|
89 inline R \ |
|
90 F (const X_T& x) \ |
|
91 { \ |
|
92 return R (F (C_X (x))); \ |
|
93 } |
|
94 |
|
95 // All the unary operators that we care about forwarding. |
|
96 #define SPARSE_UNOP_FWD_DEFS(R, T, C_X, X_T) \ |
|
97 SPARSE_UNOP_FWD_FCN (R, operator +, T, C_X, X_T) \ |
|
98 SPARSE_UNOP_FWD_FCN (R, operator -, T, C_X, X_T) |
|
99 |
|
100 // A macro that can be used to declare and instantiate binary operators. |
6708
|
101 #define SPARSE_BINOP_DECL(A_T, E_T, F, PFX, API, LTGT, X_T, Y_T) \ |
|
102 PFX API A_T<E_T> \ |
5164
|
103 F LTGT (const X_T&, const Y_T&) |
|
104 |
|
105 // All the binary operators that we care about. We have two |
|
106 // sets of macros since the MArray OP MArray operations use functions |
|
107 // (product and quotient) instead of operators (*, /). |
6708
|
108 #define SPARSE_BINOP_DECLS(A_T, F_T, E_T, PFX, API, LTGT, X_T, Y_T) \ |
|
109 SPARSE_BINOP_DECL (F_T, E_T, operator +, PFX, API, LTGT, X_T, Y_T); \ |
|
110 SPARSE_BINOP_DECL (F_T, E_T, operator -, PFX, API, LTGT, X_T, Y_T); \ |
|
111 SPARSE_BINOP_DECL (A_T, E_T, operator *, PFX, API, LTGT, X_T, Y_T); \ |
|
112 SPARSE_BINOP_DECL (A_T, E_T, operator /, PFX, API, LTGT, X_T, Y_T); |
5164
|
113 |
6708
|
114 #define SPARSE_AA_BINOP_DECLS(A_T, E_T, PFX, API, LTGT) \ |
|
115 SPARSE_BINOP_DECL (A_T, E_T, operator +, PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \ |
|
116 SPARSE_BINOP_DECL (A_T, E_T, operator -, PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \ |
|
117 SPARSE_BINOP_DECL (A_T, E_T, quotient, PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \ |
|
118 SPARSE_BINOP_DECL (A_T, E_T, product, PFX, API, LTGT, A_T<E_T>, A_T<E_T>); |
5164
|
119 |
|
120 // Generate forward declarations for binary operators. |
6708
|
121 #define SPARSE_BINOP_FWD_DECLS(A_T, F_T, API) \ |
|
122 SPARSE_BINOP_DECLS (A_T, F_T, T, template <typename T>, API, , A_T<T>, T) \ |
|
123 SPARSE_BINOP_DECLS (A_T, F_T, T, template <typename T>, API, , T, A_T<T>) \ |
|
124 SPARSE_AA_BINOP_DECLS (A_T, T, template <typename T>, API, ) |
5164
|
125 |
|
126 // Generate friend declarations for the binary operators. |
6708
|
127 #define SPARSE_BINOP_FRIENDS(A_T, F_T, API) \ |
|
128 SPARSE_BINOP_DECLS (A_T, F_T, T, friend, API, <>, A_T<T>, T) \ |
|
129 SPARSE_BINOP_DECLS (A_T, F_T, T, friend, API, <>, T, A_T<T>) \ |
|
130 SPARSE_AA_BINOP_DECLS (A_T, T, friend, API, <>) |
5164
|
131 |
|
132 // Instantiate the binary operators. |
6708
|
133 #define SPARSE_BINOP_DEFS(A_T, F_T, E_T, API) \ |
|
134 SPARSE_BINOP_DECLS (A_T, F_T, E_T, template, API, , A_T<E_T>, E_T) \ |
|
135 SPARSE_BINOP_DECLS (A_T, F_T, E_T, template, API, , E_T, A_T<E_T>) \ |
|
136 SPARSE_AA_BINOP_DECLS (A_T, E_T, template, API, ) |
5164
|
137 |
|
138 // A function that can be used to forward binary operations from derived |
|
139 // classes back to us. |
|
140 #define SPARSE_BINOP_FWD_FCN(R, F, T, C_X, X_T, C_Y, Y_T) \ |
|
141 inline R \ |
|
142 F (const X_T& x, const Y_T& y) \ |
|
143 { \ |
|
144 return R (F (C_X (x), C_Y (y))); \ |
|
145 } |
|
146 |
|
147 // The binary operators that we care about forwarding. We have two |
|
148 // sets of macros since the MSparse OP MSparse operations use functions |
|
149 // (product and quotient) instead of operators (*, /). |
|
150 #define SPARSE_BINOP_FWD_DEFS(R, F, 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 (F, 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 SPARSE_BINOP_FWD_FCN (R, operator /, T, C_X, X_T, C_Y, Y_T) |
|
155 |
|
156 #define SPARSE_AA_BINOP_FWD_DEFS(R, 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, operator -, T, C_X, X_T, C_Y, Y_T) \ |
|
159 SPARSE_BINOP_FWD_FCN (R, product, T, C_X, X_T, C_Y, Y_T) \ |
|
160 SPARSE_BINOP_FWD_FCN (R, quotient, T, C_X, X_T, C_Y, Y_T) |
|
161 |
|
162 // Forward declarations for the MSparse operators. |
6708
|
163 #define SPARSE_OPS_FORWARD_DECLS(A_T, F_T, API) \ |
5164
|
164 template <class T> \ |
|
165 class A_T; \ |
|
166 \ |
|
167 /* SPARSE_OP_ASSIGN_FWD_DECLS (A_T, T) */ \ |
6708
|
168 SPARSE_OP_ASSIGN_FWD_DECLS (A_T, A_T<T>, API) \ |
|
169 SPARSE_UNOP_FWD_DECLS (A_T, API) \ |
|
170 SPARSE_BINOP_FWD_DECLS (A_T, F_T, API) |
5164
|
171 |
|
172 // Friend declarations for the MSparse operators. |
6708
|
173 #define SPARSE_OPS_FRIEND_DECLS(A_T, F_T, API) \ |
5164
|
174 /* SPARSE_OP_ASSIGN_FRIENDS (A_T, T) */ \ |
6708
|
175 SPARSE_OP_ASSIGN_FRIENDS (A_T, A_T<T>, API) \ |
|
176 SPARSE_UNOP_FRIENDS (A_T, API) \ |
|
177 SPARSE_BINOP_FRIENDS (A_T, F_T, API) |
5164
|
178 |
|
179 // The following macros are for external use. |
|
180 |
|
181 // Instantiate all the MSparse friends for MSparse element type T. |
6708
|
182 #define INSTANTIATE_SPARSE_FRIENDS(T, API) \ |
5164
|
183 /* SPARSE_OP_ASSIGN_DEFS (MSparse, T, T) */ \ |
6708
|
184 SPARSE_OP_ASSIGN_DEFS (MSparse, T, MSparse<T>, API) \ |
|
185 SPARSE_UNOP_DEFS (MSparse, T, API) \ |
|
186 SPARSE_BINOP_DEFS (MSparse, MArray2, T, API) |
5164
|
187 |
|
188 // Define all the MSparse forwarding functions for return type R and |
|
189 // MSparse element type T |
|
190 #define SPARSE_FORWARD_DEFS(B, R, F, T) \ |
|
191 /* SPARSE_OP_ASSIGN_FWD_DEFS */ \ |
|
192 /* (R, T, dynamic_cast<B<T>&>, R, , T) */ \ |
|
193 \ |
|
194 SPARSE_OP_ASSIGN_FWD_DEFS \ |
|
195 (R, T, \ |
|
196 dynamic_cast<B<T>&>, R, dynamic_cast<const B<T>&>, R) \ |
|
197 \ |
|
198 SPARSE_UNOP_FWD_DEFS \ |
|
199 (R, T, dynamic_cast<const B<T>&>, R) \ |
|
200 \ |
|
201 SPARSE_BINOP_FWD_DEFS \ |
|
202 (R, F, T, dynamic_cast<const B<T>&>, R, , T) \ |
|
203 \ |
|
204 SPARSE_BINOP_FWD_DEFS \ |
|
205 (R, F, T, , T, dynamic_cast<const B<T>&>, R) \ |
|
206 \ |
|
207 SPARSE_AA_BINOP_FWD_DEFS \ |
|
208 (R, T, dynamic_cast<const B<T>&>, R, dynamic_cast<const B<T>&>, R) |
|
209 |
|
210 // Now we have all the definitions we need. |
|
211 |
|
212 #endif |
|
213 |
|
214 /* |
|
215 ;;; Local Variables: *** |
|
216 ;;; mode: C++ *** |
|
217 ;;; End: *** |
|
218 */ |