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 |
5279
|
36 DEFUNOP (transpose, char_matrix_str) |
3203
|
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 |
5279
|
46 return octave_value (v.char_matrix_value().transpose (), true, |
|
47 a.is_sq_string () ? '\'' : '"'); |
3203
|
48 } |
|
49 |
2928
|
50 // string by string ops. |
|
51 |
|
52 DEFBINOP (eq, char_matrix_str, char_matrix_str) |
|
53 { |
|
54 CAST_BINOP_ARGS (const octave_char_matrix_str&, |
|
55 const octave_char_matrix_str&); |
|
56 |
|
57 charMatrix cm1 = v1.char_matrix_value (); |
|
58 charMatrix cm2 = v2.char_matrix_value (); |
|
59 |
|
60 if (cm1.rows () == 1 && cm1.columns () == 1) |
|
61 { |
|
62 if (cm2.rows () == 1 && cm2.columns () == 1) |
|
63 return octave_value (cm1 (0, 0) == cm2 (0, 0)); |
|
64 else |
|
65 SC_MX_BOOL_OP (char, c, cm1 (0, 0), charMatrix, m, cm2, |
|
66 c == m (i, j), 0.0); |
|
67 } |
|
68 else |
|
69 { |
|
70 int cm2_nr = cm2.rows (); |
|
71 int cm2_nc = cm2.cols (); |
|
72 |
|
73 if (cm2_nr == 1 && cm2_nc == 1) |
|
74 MX_SC_BOOL_OP (charMatrix, m, cm1, char, c, cm2 (0, 0), |
|
75 c == m (i, j), 0.0); |
|
76 else |
|
77 MX_MX_BOOL_OP (charMatrix, m1, cm1, charMatrix, m2, cm2, |
|
78 m1 (i, j) == m2 (i, j), "==", 0.0, 1.0); |
|
79 } |
|
80 } |
|
81 |
|
82 DEFBINOP (ne, char_matrix_str, char_matrix_str) |
|
83 { |
|
84 CAST_BINOP_ARGS (const octave_char_matrix_str&, |
|
85 const octave_char_matrix_str&); |
|
86 |
|
87 charMatrix cm1 = v1.char_matrix_value (); |
|
88 charMatrix cm2 = v2.char_matrix_value (); |
|
89 |
|
90 if (cm1.rows () == 1 && cm1.columns () == 1) |
|
91 { |
|
92 if (cm2.rows () == 1 && cm2.columns () == 1) |
|
93 return octave_value (cm1 (0, 0) != cm2 (0, 0)); |
|
94 else |
|
95 SC_MX_BOOL_OP (char, c, cm1 (0, 0), charMatrix, m, cm2, |
|
96 c != m (i, j), 1.0); |
|
97 } |
|
98 else |
|
99 { |
|
100 if (cm2.rows () == 1 && cm2.columns () == 1) |
|
101 MX_SC_BOOL_OP (charMatrix, m, cm1, char, c, cm2 (0, 0), |
|
102 c != m (i, j), 1.0); |
|
103 else |
|
104 MX_MX_BOOL_OP (charMatrix, m1, cm1, charMatrix, m2, cm2, |
|
105 m1 (i, j) != m2 (i, j), "!=", 1.0, 0.0); |
|
106 } |
|
107 } |
|
108 |
|
109 DEFASSIGNOP (assign, char_matrix_str, char_matrix_str) |
|
110 { |
|
111 CAST_BINOP_ARGS (octave_char_matrix_str&, const octave_char_matrix_str&); |
|
112 |
|
113 v1.assign (idx, v2.char_matrix_value ()); |
|
114 return octave_value (); |
|
115 } |
|
116 |
4915
|
117 DEFCATOP (str_str, char_matrix_str, char_matrix_str) |
|
118 { |
5073
|
119 CAST_BINOP_ARGS (octave_char_matrix_str&, const octave_char_matrix_str&); |
|
120 return octave_value (v1.char_array_value (). concat (v2.char_array_value (), |
5279
|
121 ra_idx), |
|
122 true, |
|
123 (a1.is_sq_string () && a2.is_sq_string () |
|
124 ? '\'' : '"')); |
4915
|
125 } |
|
126 |
2928
|
127 void |
|
128 install_str_str_ops (void) |
|
129 { |
3538
|
130 INSTALL_UNOP (op_transpose, octave_char_matrix_str, transpose); |
5279
|
131 INSTALL_UNOP (op_transpose, octave_char_matrix_sq_str, transpose); |
|
132 |
3538
|
133 INSTALL_UNOP (op_hermitian, octave_char_matrix_str, transpose); |
5279
|
134 INSTALL_UNOP (op_hermitian, octave_char_matrix_sq_str, transpose); |
3203
|
135 |
3538
|
136 INSTALL_BINOP (op_eq, octave_char_matrix_str, octave_char_matrix_str, eq); |
5279
|
137 INSTALL_BINOP (op_eq, octave_char_matrix_str, octave_char_matrix_sq_str, eq); |
|
138 INSTALL_BINOP (op_eq, octave_char_matrix_sq_str, octave_char_matrix_str, eq); |
|
139 INSTALL_BINOP (op_eq, octave_char_matrix_sq_str, octave_char_matrix_sq_str, eq); |
|
140 |
3538
|
141 INSTALL_BINOP (op_ne, octave_char_matrix_str, octave_char_matrix_str, ne); |
5279
|
142 INSTALL_BINOP (op_ne, octave_char_matrix_str, octave_char_matrix_sq_str, ne); |
|
143 INSTALL_BINOP (op_ne, octave_char_matrix_sq_str, octave_char_matrix_str, ne); |
|
144 INSTALL_BINOP (op_ne, octave_char_matrix_sq_str, octave_char_matrix_sq_str, ne); |
2928
|
145 |
4915
|
146 INSTALL_CATOP (octave_char_matrix_str, octave_char_matrix_str, str_str); |
5279
|
147 INSTALL_CATOP (octave_char_matrix_str, octave_char_matrix_sq_str, str_str); |
|
148 INSTALL_CATOP (octave_char_matrix_sq_str, octave_char_matrix_str, str_str); |
|
149 INSTALL_CATOP (octave_char_matrix_sq_str, octave_char_matrix_sq_str, str_str); |
4915
|
150 |
3538
|
151 INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_str, octave_char_matrix_str, assign); |
5279
|
152 INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_str, octave_char_matrix_sq_str, assign); |
|
153 INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_sq_str, octave_char_matrix_str, assign); |
|
154 INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_sq_str, octave_char_matrix_sq_str, assign); |
2928
|
155 } |
|
156 |
|
157 /* |
|
158 ;;; Local Variables: *** |
|
159 ;;; mode: C++ *** |
|
160 ;;; End: *** |
|
161 */ |