4645
|
1 /* |
|
2 |
|
3 Copyright (C) 2003 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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
4645
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "gripes.h" |
|
29 #include "ov.h" |
|
30 #include "ov-re-mat.h" |
|
31 #include "ov-scalar.h" |
|
32 #include "ov-streamoff.h" |
|
33 #include "ov-typeinfo.h" |
|
34 #include "ops.h" |
|
35 |
|
36 // streamoff unary ops. |
|
37 |
|
38 DEFUNOP (transpose, streamoff) |
|
39 { |
|
40 CAST_UNOP_ARG (const octave_streamoff&); |
|
41 |
4673
|
42 if (v.ndims () > 2) |
|
43 { |
|
44 error ("transpose not defined for N-d objects"); |
|
45 return octave_value (); |
|
46 } |
|
47 else |
|
48 return octave_value (streamoff_array (v.streamoff_array_value().transpose ())); |
4645
|
49 } |
|
50 |
4646
|
51 DEFNCUNOP_METHOD (incr, streamoff, increment) |
|
52 DEFNCUNOP_METHOD (decr, streamoff, decrement) |
4645
|
53 |
|
54 // streamoff by streamoff ops. |
|
55 |
|
56 DEFNDBINOP_OP (add, streamoff, streamoff, streamoff_array, streamoff_array, +) |
|
57 DEFNDBINOP_OP (sub, streamoff, streamoff, streamoff_array, streamoff_array, -) |
|
58 |
|
59 DEFNDBINOP_OP (add_so_m, streamoff, matrix, streamoff_array, streamoff_array, +) |
|
60 DEFNDBINOP_OP (sub_so_m, streamoff, matrix, streamoff_array, streamoff_array, -) |
|
61 |
|
62 DEFNDBINOP_OP (add_m_so, matrix, streamoff, streamoff_array, streamoff_array, +) |
|
63 DEFNDBINOP_OP (sub_m_so, matrix, streamoff, streamoff_array, streamoff_array, +) |
|
64 DEFNDBINOP_OP (add_so_s, streamoff, scalar, streamoff_array, streamoff, +) |
|
65 DEFNDBINOP_OP (sub_so_s, streamoff, scalar, streamoff_array, streamoff, -) |
|
66 |
|
67 DEFNDBINOP_OP (add_s_so, scalar, streamoff, streamoff, streamoff_array, +) |
|
68 DEFNDBINOP_OP (sub_s_so, scalar, streamoff, streamoff, streamoff_array, +) |
|
69 |
4701
|
70 #define STREAMOFF_COMP_OP(FN, OP, T1, T2) \ |
|
71 DEFBINOP (FN, T1, T2) \ |
|
72 { \ |
5760
|
73 CAST_BINOP_ARGS (const octave_ ## T1&, const octave_ ## T2&); \ |
4701
|
74 \ |
|
75 streamoff_array cm1 = v1.streamoff_array_value (); \ |
|
76 streamoff_array cm2 = v2.streamoff_array_value (); \ |
|
77 \ |
|
78 if (! error_state) \ |
|
79 { \ |
|
80 if (cm1.rows () == 1 && cm1.columns () == 1) \ |
|
81 { \ |
|
82 if (cm2.rows () == 1 && cm2.columns () == 1) \ |
|
83 return octave_value (cm1(0,0) OP cm2(0,0)); \ |
|
84 else \ |
|
85 SC_MX_BOOL_OP (std::streamoff, c, cm1 (0, 0), streamoff_array, \ |
|
86 m, cm2, c OP m(i,j), 0.0); \ |
|
87 } \ |
|
88 else \ |
|
89 { \ |
|
90 if (cm2.rows () == 1 && cm2.columns () == 1) \ |
|
91 MX_SC_BOOL_OP (streamoff_array, m, cm1, std::streamoff, \ |
|
92 c, cm2(0,0), c OP m(i,j), 0.0); \ |
|
93 else \ |
|
94 MX_MX_BOOL_OP (streamoff_array, m1, cm1, streamoff_array, \ |
|
95 m2, cm2, m1(i,j) OP m2(i,j), #OP, 0.0, 1.0); \ |
|
96 } \ |
|
97 } \ |
|
98 else \ |
|
99 return octave_value (); \ |
|
100 } |
4645
|
101 |
4701
|
102 STREAMOFF_COMP_OP (eq, ==, streamoff, streamoff); |
|
103 STREAMOFF_COMP_OP (ne, !=, streamoff, streamoff); |
4645
|
104 |
4701
|
105 STREAMOFF_COMP_OP (eq_so_m, ==, streamoff, matrix); |
|
106 STREAMOFF_COMP_OP (ne_so_m, !=, streamoff, matrix); |
4645
|
107 |
4701
|
108 STREAMOFF_COMP_OP (eq_m_so, ==, matrix, streamoff); |
|
109 STREAMOFF_COMP_OP (ne_m_so, !=, matrix, streamoff); |
|
110 |
|
111 STREAMOFF_COMP_OP (eq_so_s, ==, streamoff, scalar); |
|
112 STREAMOFF_COMP_OP (ne_so_s, !=, streamoff, scalar); |
|
113 |
|
114 STREAMOFF_COMP_OP (eq_s_so, ==, scalar, streamoff); |
|
115 STREAMOFF_COMP_OP (ne_s_so, !=, scalar, streamoff); |
4645
|
116 |
|
117 DEFASSIGNOP (assign, streamoff, streamoff) |
|
118 { |
|
119 CAST_BINOP_ARGS (octave_streamoff&, const octave_streamoff&); |
|
120 |
|
121 v1.assign (idx, v2.streamoff_array_value ()); |
|
122 return octave_value (); |
|
123 } |
|
124 |
|
125 void |
|
126 install_streamoff_ops (void) |
|
127 { |
|
128 INSTALL_UNOP (op_transpose, octave_streamoff, transpose); |
|
129 INSTALL_UNOP (op_hermitian, octave_streamoff, transpose); |
|
130 |
4646
|
131 INSTALL_NCUNOP (op_incr, octave_streamoff, incr); |
|
132 INSTALL_NCUNOP (op_decr, octave_streamoff, decr); |
|
133 |
4645
|
134 INSTALL_BINOP (op_eq, octave_streamoff, octave_streamoff, eq); |
|
135 INSTALL_BINOP (op_ne, octave_streamoff, octave_streamoff, ne); |
|
136 |
4701
|
137 INSTALL_BINOP (op_eq, octave_streamoff, octave_matrix, eq_so_m); |
|
138 INSTALL_BINOP (op_ne, octave_streamoff, octave_matrix, ne_so_m); |
|
139 |
|
140 INSTALL_BINOP (op_eq, octave_matrix, octave_streamoff, eq_m_so); |
|
141 INSTALL_BINOP (op_ne, octave_matrix, octave_streamoff, ne_m_so); |
|
142 |
|
143 INSTALL_BINOP (op_eq, octave_streamoff, octave_scalar, eq_so_s); |
|
144 INSTALL_BINOP (op_ne, octave_streamoff, octave_scalar, ne_so_s); |
|
145 |
|
146 INSTALL_BINOP (op_eq, octave_scalar, octave_streamoff, eq_s_so); |
|
147 INSTALL_BINOP (op_ne, octave_scalar, octave_streamoff, ne_s_so); |
|
148 |
4645
|
149 INSTALL_BINOP (op_add, octave_streamoff, octave_streamoff, add); |
|
150 INSTALL_BINOP (op_sub, octave_streamoff, octave_streamoff, sub); |
|
151 |
|
152 INSTALL_BINOP (op_add, octave_streamoff, octave_matrix, add_so_m); |
|
153 INSTALL_BINOP (op_sub, octave_streamoff, octave_matrix, sub_so_m); |
|
154 |
|
155 INSTALL_BINOP (op_add, octave_matrix, octave_streamoff, add_m_so); |
|
156 INSTALL_BINOP (op_sub, octave_matrix, octave_streamoff, sub_m_so); |
|
157 |
|
158 INSTALL_BINOP (op_add, octave_streamoff, octave_scalar, add_so_s); |
|
159 INSTALL_BINOP (op_sub, octave_streamoff, octave_scalar, sub_so_s); |
|
160 |
|
161 INSTALL_BINOP (op_add, octave_scalar, octave_streamoff, add_s_so); |
|
162 INSTALL_BINOP (op_sub, octave_scalar, octave_streamoff, sub_s_so); |
|
163 |
|
164 INSTALL_ASSIGNOP (op_asn_eq, octave_streamoff, octave_streamoff, assign); |
|
165 } |
|
166 |
|
167 /* |
|
168 ;;; Local Variables: *** |
|
169 ;;; mode: C++ *** |
|
170 ;;; End: *** |
|
171 */ |