2928
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 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 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2928
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include "gripes.h" |
4055
|
32 #include "oct-obj.h" |
2928
|
33 #include "ov.h" |
|
34 #include "ov-str-mat.h" |
|
35 #include "ov-typeinfo.h" |
|
36 #include "ops.h" |
|
37 |
3203
|
38 // string unary ops. |
|
39 |
|
40 DEFUNOP (transpose, matrix) |
|
41 { |
|
42 CAST_UNOP_ARG (const octave_char_matrix_str&); |
|
43 |
|
44 return octave_value (v.char_matrix_value().transpose (), true); |
|
45 } |
|
46 |
2928
|
47 // string by string ops. |
|
48 |
|
49 DEFBINOP (eq, char_matrix_str, char_matrix_str) |
|
50 { |
|
51 CAST_BINOP_ARGS (const octave_char_matrix_str&, |
|
52 const octave_char_matrix_str&); |
|
53 |
|
54 charMatrix cm1 = v1.char_matrix_value (); |
|
55 charMatrix cm2 = v2.char_matrix_value (); |
|
56 |
|
57 if (cm1.rows () == 1 && cm1.columns () == 1) |
|
58 { |
|
59 if (cm2.rows () == 1 && cm2.columns () == 1) |
|
60 return octave_value (cm1 (0, 0) == cm2 (0, 0)); |
|
61 else |
|
62 SC_MX_BOOL_OP (char, c, cm1 (0, 0), charMatrix, m, cm2, |
|
63 c == m (i, j), 0.0); |
|
64 } |
|
65 else |
|
66 { |
|
67 int cm2_nr = cm2.rows (); |
|
68 int cm2_nc = cm2.cols (); |
|
69 |
|
70 if (cm2_nr == 1 && cm2_nc == 1) |
|
71 MX_SC_BOOL_OP (charMatrix, m, cm1, char, c, cm2 (0, 0), |
|
72 c == m (i, j), 0.0); |
|
73 else |
|
74 MX_MX_BOOL_OP (charMatrix, m1, cm1, charMatrix, m2, cm2, |
|
75 m1 (i, j) == m2 (i, j), "==", 0.0, 1.0); |
|
76 } |
|
77 } |
|
78 |
|
79 DEFBINOP (ne, char_matrix_str, char_matrix_str) |
|
80 { |
|
81 CAST_BINOP_ARGS (const octave_char_matrix_str&, |
|
82 const octave_char_matrix_str&); |
|
83 |
|
84 charMatrix cm1 = v1.char_matrix_value (); |
|
85 charMatrix cm2 = v2.char_matrix_value (); |
|
86 |
|
87 if (cm1.rows () == 1 && cm1.columns () == 1) |
|
88 { |
|
89 if (cm2.rows () == 1 && cm2.columns () == 1) |
|
90 return octave_value (cm1 (0, 0) != cm2 (0, 0)); |
|
91 else |
|
92 SC_MX_BOOL_OP (char, c, cm1 (0, 0), charMatrix, m, cm2, |
|
93 c != m (i, j), 1.0); |
|
94 } |
|
95 else |
|
96 { |
|
97 if (cm2.rows () == 1 && cm2.columns () == 1) |
|
98 MX_SC_BOOL_OP (charMatrix, m, cm1, char, c, cm2 (0, 0), |
|
99 c != m (i, j), 1.0); |
|
100 else |
|
101 MX_MX_BOOL_OP (charMatrix, m1, cm1, charMatrix, m2, cm2, |
|
102 m1 (i, j) != m2 (i, j), "!=", 1.0, 0.0); |
|
103 } |
|
104 } |
|
105 |
|
106 DEFASSIGNOP (assign, char_matrix_str, char_matrix_str) |
|
107 { |
|
108 CAST_BINOP_ARGS (octave_char_matrix_str&, const octave_char_matrix_str&); |
|
109 |
|
110 v1.assign (idx, v2.char_matrix_value ()); |
|
111 return octave_value (); |
|
112 } |
|
113 |
|
114 void |
|
115 install_str_str_ops (void) |
|
116 { |
3538
|
117 INSTALL_UNOP (op_transpose, octave_char_matrix_str, transpose); |
|
118 INSTALL_UNOP (op_hermitian, octave_char_matrix_str, transpose); |
3203
|
119 |
3538
|
120 INSTALL_BINOP (op_eq, octave_char_matrix_str, octave_char_matrix_str, eq); |
|
121 INSTALL_BINOP (op_ne, octave_char_matrix_str, octave_char_matrix_str, ne); |
2928
|
122 |
3538
|
123 INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_str, octave_char_matrix_str, assign); |
2928
|
124 } |
|
125 |
|
126 /* |
|
127 ;;; Local Variables: *** |
|
128 ;;; mode: C++ *** |
|
129 ;;; End: *** |
|
130 */ |