2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_ops_h) |
|
24 #define octave_ops_h 1 |
|
25 |
|
26 extern void install_ops (void); |
|
27 |
3203
|
28 #define INSTALL_UNOP(op, t, f) \ |
|
29 octave_value_typeinfo::register_unary_op \ |
|
30 (octave_value::op, t::static_type_id (), oct_unop_ ## f); |
|
31 |
|
32 #define INSTALL_NCUNOP(op, t, f) \ |
|
33 octave_value_typeinfo::register_non_const_unary_op \ |
|
34 (octave_value::op, t::static_type_id (), oct_unop_ ## f); |
|
35 |
2376
|
36 #define INSTALL_BINOP(op, t1, t2, f) \ |
|
37 octave_value_typeinfo::register_binary_op \ |
3203
|
38 (octave_value::op, t1::static_type_id (), t2::static_type_id (), \ |
|
39 oct_binop_ ## f); |
2376
|
40 |
2879
|
41 #define INSTALL_ASSIGNOP(op, t1, t2, f) \ |
2376
|
42 octave_value_typeinfo::register_assign_op \ |
3203
|
43 (octave_value::op, t1::static_type_id (), t2::static_type_id (), \ |
|
44 oct_assignop_ ## f); |
2376
|
45 |
3195
|
46 #define INSTALL_ASSIGNANYOP(op, t1, f) \ |
|
47 octave_value_typeinfo::register_assignany_op \ |
3203
|
48 (octave_value::op, t1::static_type_id (), oct_assignop_ ## f); |
3195
|
49 |
2376
|
50 #define INSTALL_ASSIGNCONV(t1, t2, tr) \ |
|
51 octave_value_typeinfo::register_pref_assign_conv \ |
|
52 (t1::static_type_id (), t2::static_type_id (), tr::static_type_id ()); |
|
53 |
|
54 #define INSTALL_WIDENOP(t1, t2, f) \ |
|
55 octave_value_typeinfo::register_widening_op \ |
3203
|
56 (t1::static_type_id (), t2::static_type_id (), oct_conv_ ## f); |
2376
|
57 |
|
58 #define BOOL_OP1(xt, xn, get_x, yt, yn, get_y) \ |
|
59 xt xn = get_x; \ |
|
60 yt yn = get_y; |
|
61 |
|
62 #define BOOL_OP2(x) \ |
|
63 int nr = x.rows (); \ |
|
64 int nc = x.columns (); |
|
65 |
|
66 #define BOOL_OP3(test) \ |
2825
|
67 boolMatrix retval (nr, nc); \ |
2376
|
68 for (int j = 0; j < nc; j++) \ |
|
69 for (int i = 0; i < nr; i++) \ |
|
70 retval (i, j) = test; \ |
|
71 return retval; |
|
72 |
2601
|
73 #define SC_MX_BOOL_OP(st, sn, get_s, mt, mn, get_m, test, empty_result) \ |
2376
|
74 do \ |
|
75 { \ |
|
76 BOOL_OP1 (st, sn, get_s, mt, mn, get_m) \ |
|
77 BOOL_OP2 (mn) \ |
2612
|
78 if (nr == 0 || nc == 0) \ |
2601
|
79 return empty_result; \ |
2376
|
80 BOOL_OP3 (test) \ |
|
81 } \ |
|
82 while (0) |
|
83 |
2601
|
84 #define MX_SC_BOOL_OP(mt, mn, get_m, st, sn, get_s, test, empty_result) \ |
2376
|
85 do \ |
|
86 { \ |
|
87 BOOL_OP1 (mt, mn, get_m, st, sn, get_s) \ |
|
88 BOOL_OP2 (mn) \ |
2612
|
89 if (nr == 0 || nc == 0) \ |
2601
|
90 return empty_result; \ |
2376
|
91 BOOL_OP3 (test) \ |
|
92 } \ |
|
93 while (0) |
|
94 |
|
95 #define MX_MX_BOOL_OP(m1t, m1n, get_m1, m2t, m2n, get_m2, test, op, \ |
2613
|
96 one_empty_result, two_empty_result) \ |
2376
|
97 do \ |
|
98 { \ |
|
99 BOOL_OP1 (m1t, m1n, get_m1, m2t, m2n, get_m2) \ |
2601
|
100 int m1_nr = m1n.rows (); \ |
|
101 int m1_nc = m1n.cols (); \ |
|
102 int m2_nr = m2n.rows (); \ |
|
103 int m2_nc = m2n.cols (); \ |
2613
|
104 if (m1_nr == m2_nr && m1_nc == m2_nc) \ |
2376
|
105 { \ |
2613
|
106 if (m1_nr == 0 && m1_nc == 0) \ |
|
107 return two_empty_result; \ |
|
108 else \ |
|
109 { \ |
|
110 BOOL_OP2 (m1n) \ |
|
111 BOOL_OP3 (test) \ |
|
112 } \ |
2376
|
113 } \ |
2613
|
114 else \ |
|
115 { \ |
|
116 if ((m1_nr == 0 && m1_nc == 0) || (m2_nr == 0 && m2_nc == 0)) \ |
|
117 return one_empty_result; \ |
|
118 else \ |
|
119 { \ |
|
120 gripe_nonconformant ("operator " op, m1_nr, m1_nc, \ |
|
121 m2_nr, m2_nc); \ |
2825
|
122 return boolMatrix (); \ |
2613
|
123 } \ |
|
124 } \ |
2376
|
125 } \ |
|
126 while (0) |
|
127 |
3203
|
128 #define CAST_UNOP_ARG(t) \ |
|
129 t v = DYNAMIC_CAST (t, a); |
|
130 |
2376
|
131 #define CAST_BINOP_ARGS(t1, t2) \ |
|
132 t1 v1 = DYNAMIC_CAST (t1, a1); \ |
|
133 t2 v2 = DYNAMIC_CAST (t2, a2); |
|
134 |
|
135 #define CAST_CONV_ARG(t) \ |
|
136 t v = DYNAMIC_CAST (t, a); |
|
137 |
2914
|
138 #define ASSIGNOPDECL(name) \ |
|
139 static octave_value \ |
3203
|
140 oct_assignop_ ## name (octave_value& a1, \ |
|
141 const octave_value_list& idx, \ |
|
142 const octave_value& a2) |
2914
|
143 |
|
144 #define DEFASSIGNOP(name, t1, t2) \ |
|
145 ASSIGNOPDECL (name) |
|
146 |
|
147 #define DEFASSIGNOP_FN(name, t1, t2, f) \ |
|
148 ASSIGNOPDECL (name) \ |
|
149 { \ |
|
150 CAST_BINOP_ARGS (octave_ ## t1&, const octave_ ## t2&); \ |
|
151 \ |
|
152 v1.f (idx, v2.t1 ## _value ()); \ |
|
153 return octave_value (); \ |
|
154 } |
|
155 |
3195
|
156 #define DEFASSIGNANYOP_FN(name, t1, f) \ |
|
157 ASSIGNOPDECL (name) \ |
|
158 { \ |
|
159 octave_ ## t1& v1 = DYNAMIC_CAST (octave_ ## t1&, a1); \ |
|
160 \ |
|
161 v1.f (idx, a2); \ |
|
162 return octave_value (); \ |
|
163 } |
|
164 |
2914
|
165 #define CONVDECL(name) \ |
|
166 static octave_value * \ |
3203
|
167 oct_conv_ ## name (const octave_value& a) |
|
168 |
|
169 #define CONVDECLX(name) \ |
|
170 static octave_value * \ |
|
171 oct_conv_ ## name (const octave_value&) |
2914
|
172 |
|
173 #define DEFCONV(name, from, to) \ |
|
174 CONVDECL (name) |
|
175 |
3203
|
176 #define UNOPDECL(name, a) \ |
|
177 static octave_value \ |
|
178 oct_unop_ ## name (const octave_value& a) |
|
179 |
|
180 #define DEFUNOPX(name, t) \ |
|
181 UNOPDECL (name, , ) |
|
182 |
|
183 #define DEFUNOP(name, t) \ |
|
184 UNOPDECL (name, a) |
|
185 |
|
186 #define DEFUNOP_OP(name, t, op) \ |
|
187 UNOPDECL (name, a) \ |
|
188 { \ |
|
189 CAST_UNOP_ARG (const octave_ ## t&); \ |
|
190 return octave_value (op v.t ## _value ()); \ |
|
191 } |
|
192 |
4550
|
193 #define DEFNDUNOP_OP(name, t, e, op) \ |
4543
|
194 UNOPDECL (name, a) \ |
|
195 { \ |
|
196 CAST_UNOP_ARG (const octave_ ## t&); \ |
4550
|
197 return octave_value (op v.e ## _value ()); \ |
4543
|
198 } |
|
199 |
3203
|
200 // XXX FIXME XXX -- in some cases, the constructor isn't necessary. |
|
201 |
|
202 #define DEFUNOP_FN(name, t, f) \ |
|
203 UNOPDECL (name, a) \ |
|
204 { \ |
|
205 CAST_UNOP_ARG (const octave_ ## t&); \ |
|
206 return octave_value (f (v.t ## _value ())); \ |
|
207 } |
|
208 |
4550
|
209 #define DEFNDUNOP_FN(name, t, e, f) \ |
4543
|
210 UNOPDECL (name, a) \ |
|
211 { \ |
|
212 CAST_UNOP_ARG (const octave_ ## t&); \ |
4550
|
213 return octave_value (f (v.e ## _value ())); \ |
4543
|
214 } |
|
215 |
3203
|
216 #define DEFNCUNOP_METHOD(name, t, method) \ |
|
217 static void \ |
|
218 oct_unop_ ## name (octave_value& a) \ |
|
219 { \ |
|
220 CAST_UNOP_ARG (octave_ ## t&); \ |
|
221 v.method (); \ |
|
222 } |
|
223 |
2914
|
224 #define BINOPDECL(name, a1, a2) \ |
|
225 static octave_value \ |
3203
|
226 oct_binop_ ## name (const octave_value& a1, const octave_value& a2) |
2914
|
227 |
|
228 #define DEFBINOPX(name, t1, t2) \ |
|
229 BINOPDECL (name, , ) |
|
230 |
|
231 #define DEFBINOP(name, t1, t2) \ |
|
232 BINOPDECL (name, a1, a2) |
|
233 |
|
234 #define DEFBINOP_OP(name, t1, t2, op) \ |
|
235 BINOPDECL (name, a1, a2) \ |
|
236 { \ |
|
237 CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \ |
|
238 return octave_value \ |
|
239 (v1.t1 ## _value () op v2.t2 ## _value ()); \ |
|
240 } |
|
241 |
4543
|
242 #define DEFNDBINOP_OP(name, t1, t2, e1, e2, op) \ |
|
243 BINOPDECL (name, a1, a2) \ |
|
244 { \ |
|
245 CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \ |
|
246 return octave_value \ |
|
247 (v1.e1 ## _value () op v2.e2 ## _value ()); \ |
|
248 } |
|
249 |
2914
|
250 // XXX FIXME XXX -- in some cases, the constructor isn't necessary. |
|
251 |
|
252 #define DEFBINOP_FN(name, t1, t2, f) \ |
|
253 BINOPDECL (name, a1, a2) \ |
|
254 { \ |
|
255 CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \ |
|
256 return octave_value (f (v1.t1 ## _value (), v2.t2 ## _value ())); \ |
|
257 } |
|
258 |
4543
|
259 #define DEFNDBINOP_FN(name, t1, t2, e1, e2, f) \ |
|
260 BINOPDECL (name, a1, a2) \ |
|
261 { \ |
|
262 CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \ |
|
263 return octave_value (f (v1.e1 ## _value (), v2.e2 ## _value ())); \ |
|
264 } |
|
265 |
2914
|
266 #define BINOP_NONCONFORMANT(msg) \ |
|
267 gripe_nonconformant (msg, \ |
|
268 a1.rows (), a1.columns (), \ |
|
269 a2.rows (), a2.columns ()); \ |
|
270 return octave_value () |
|
271 |
2376
|
272 #endif |
|
273 |
|
274 /* |
|
275 ;;; Local Variables: *** |
|
276 ;;; mode: C++ *** |
|
277 ;;; End: *** |
|
278 */ |