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