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