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