2376
|
1 /* |
|
2 |
|
3 Copyright (C) 1996 John W. Eaton |
|
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 |
|
28 #define INSTALL_UNOP(op, t, f) \ |
|
29 octave_value_typeinfo::register_unary_op \ |
|
30 (octave_value::op, t::static_type_id (), f); |
|
31 |
|
32 #define INSTALL_BINOP(op, t1, t2, f) \ |
|
33 octave_value_typeinfo::register_binary_op \ |
|
34 (octave_value::op, t1::static_type_id (), t2::static_type_id (), f); |
|
35 |
|
36 #define INSTALL_ASSIGNOP(t1, t2, f) \ |
|
37 octave_value_typeinfo::register_assign_op \ |
|
38 (t1::static_type_id (), t2::static_type_id (), f); |
|
39 |
|
40 #define INSTALL_ASSIGNCONV(t1, t2, tr) \ |
|
41 octave_value_typeinfo::register_pref_assign_conv \ |
|
42 (t1::static_type_id (), t2::static_type_id (), tr::static_type_id ()); |
|
43 |
|
44 #define INSTALL_WIDENOP(t1, t2, f) \ |
|
45 octave_value_typeinfo::register_widening_op \ |
|
46 (t1::static_type_id (), t2::static_type_id (), f); |
|
47 |
|
48 #define BOOL_OP1(xt, xn, get_x, yt, yn, get_y) \ |
|
49 xt xn = get_x; \ |
|
50 yt yn = get_y; |
|
51 |
|
52 #define BOOL_OP2(x) \ |
|
53 int nr = x.rows (); \ |
|
54 int nc = x.columns (); |
|
55 |
|
56 #define BOOL_OP3(test) \ |
|
57 Matrix retval (nr, nc); \ |
|
58 for (int j = 0; j < nc; j++) \ |
|
59 for (int i = 0; i < nr; i++) \ |
|
60 retval (i, j) = test; \ |
|
61 return retval; |
|
62 |
2601
|
63 #define SC_MX_BOOL_OP(st, sn, get_s, mt, mn, get_m, test, empty_result) \ |
2376
|
64 do \ |
|
65 { \ |
|
66 BOOL_OP1 (st, sn, get_s, mt, mn, get_m) \ |
|
67 BOOL_OP2 (mn) \ |
2601
|
68 if (nr == 0|| nc == 0) \ |
|
69 return empty_result; \ |
2376
|
70 BOOL_OP3 (test) \ |
|
71 } \ |
|
72 while (0) |
|
73 |
2601
|
74 #define MX_SC_BOOL_OP(mt, mn, get_m, st, sn, get_s, test, empty_result) \ |
2376
|
75 do \ |
|
76 { \ |
|
77 BOOL_OP1 (mt, mn, get_m, st, sn, get_s) \ |
|
78 BOOL_OP2 (mn) \ |
2601
|
79 if (nr == 0|| nc == 0) \ |
|
80 return empty_result; \ |
2376
|
81 BOOL_OP3 (test) \ |
|
82 } \ |
|
83 while (0) |
|
84 |
|
85 #define MX_MX_BOOL_OP(m1t, m1n, get_m1, m2t, m2n, get_m2, test, op, \ |
|
86 empty_result) \ |
|
87 do \ |
|
88 { \ |
|
89 BOOL_OP1 (m1t, m1n, get_m1, m2t, m2n, get_m2) \ |
2601
|
90 int m1_nr = m1n.rows (); \ |
|
91 int m1_nc = m1n.cols (); \ |
|
92 int m2_nr = m2n.rows (); \ |
|
93 int m2_nc = m2n.cols (); \ |
2376
|
94 if (m1_nr != m2_nr || m1_nc != m2_nc) \ |
|
95 { \ |
|
96 gripe_nonconformant ("operator " op, m1_nr, m1_nc, m2_nr, m2_nc); \ |
|
97 return Matrix (); \ |
|
98 } \ |
|
99 if (m1_nr == 0 || m1_nc == 0) \ |
|
100 return empty_result; \ |
|
101 BOOL_OP2 (m1n) \ |
|
102 BOOL_OP3 (test) \ |
|
103 } \ |
|
104 while (0) |
|
105 |
|
106 #define CAST_BINOP_ARGS(t1, t2) \ |
|
107 t1 v1 = DYNAMIC_CAST (t1, a1); \ |
|
108 t2 v2 = DYNAMIC_CAST (t2, a2); |
|
109 |
|
110 #define CAST_CONV_ARG(t) \ |
|
111 t v = DYNAMIC_CAST (t, a); |
|
112 |
|
113 #endif |
|
114 |
|
115 /* |
|
116 ;;; Local Variables: *** |
|
117 ;;; mode: C++ *** |
|
118 ;;; End: *** |
|
119 */ |