2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
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 |
2901
|
31 #include <iostream.h> |
|
32 |
2376
|
33 #include "lo-ieee.h" |
|
34 #include "mx-base.h" |
|
35 |
2407
|
36 #include "oct-obj.h" |
2376
|
37 #include "ops.h" |
|
38 #include "ov-re-mat.h" |
|
39 #include "ov-str-mat.h" |
|
40 #include "gripes.h" |
|
41 #include "pr-output.h" |
|
42 |
2668
|
43 int |
|
44 octave_char_matrix_str::t_id (-1); |
2376
|
45 |
2668
|
46 const string |
|
47 octave_char_matrix_str::t_name ("string"); |
2376
|
48 |
|
49 static octave_value * |
|
50 default_numeric_conversion_function (const octave_value& a) |
|
51 { |
|
52 CAST_CONV_ARG (const octave_char_matrix_str&); |
|
53 |
|
54 return new octave_matrix (v.matrix_value ()); |
|
55 } |
|
56 |
2427
|
57 type_conv_fcn |
2376
|
58 octave_char_matrix_str::numeric_conversion_function (void) const |
|
59 { |
|
60 return default_numeric_conversion_function; |
|
61 } |
|
62 |
|
63 octave_value |
2962
|
64 octave_char_matrix_str::do_index_op (const octave_value_list& idx) const |
2407
|
65 { |
|
66 octave_value retval; |
|
67 |
|
68 int len = idx.length (); |
|
69 |
|
70 switch (len) |
|
71 { |
|
72 case 2: |
|
73 { |
|
74 idx_vector i = idx (0).index_vector (); |
|
75 idx_vector j = idx (1).index_vector (); |
|
76 |
|
77 retval = octave_value (charMatrix (matrix.index (i, j)), true); |
|
78 } |
|
79 break; |
|
80 |
|
81 case 1: |
|
82 { |
|
83 idx_vector i = idx (0).index_vector (); |
|
84 |
|
85 retval = octave_value (charMatrix (matrix.index (i)), true); |
|
86 } |
|
87 break; |
|
88 |
|
89 default: |
|
90 error ("invalid number of indices (%d) for matrix value", len); |
|
91 break; |
|
92 } |
|
93 |
|
94 return retval; |
|
95 } |
|
96 |
|
97 extern void assign (Array2<char>&, const Array2<char>&); |
|
98 |
|
99 void |
|
100 octave_char_matrix_str::assign (const octave_value_list& idx, |
|
101 const charMatrix& rhs) |
|
102 { |
|
103 int len = idx.length (); |
|
104 |
2571
|
105 // XXX FIXME XXX |
|
106 charMatrix tmp = rhs; |
|
107 if (tmp.rows () == 1 && tmp.columns () == 0) |
|
108 tmp.resize (0, 0); |
|
109 |
2407
|
110 switch (len) |
|
111 { |
|
112 case 2: |
|
113 { |
|
114 idx_vector i = idx (0).index_vector (); |
|
115 idx_vector j = idx (1).index_vector (); |
|
116 |
|
117 matrix.set_index (i); |
|
118 matrix.set_index (j); |
|
119 |
2571
|
120 ::assign (matrix, tmp); |
2407
|
121 } |
|
122 break; |
|
123 |
|
124 case 1: |
|
125 { |
|
126 idx_vector i = idx (0).index_vector (); |
|
127 |
|
128 matrix.set_index (i); |
|
129 |
2571
|
130 ::assign (matrix, tmp); |
2407
|
131 } |
|
132 break; |
|
133 |
|
134 default: |
|
135 error ("invalid number of indices (%d) for indexed matrix assignment", |
|
136 len); |
|
137 break; |
|
138 } |
|
139 } |
|
140 |
|
141 octave_value |
2376
|
142 octave_char_matrix_str::all (void) const |
|
143 { |
|
144 octave_value retval; |
|
145 error ("octave_char_matrix_str::all(): not implemented"); |
|
146 return retval; |
|
147 } |
|
148 |
|
149 octave_value |
|
150 octave_char_matrix_str::any (void) const |
|
151 { |
|
152 octave_value retval; |
|
153 error ("octave_char_matrix_str::any(): not implemented"); |
|
154 return retval; |
|
155 } |
|
156 |
|
157 bool |
|
158 octave_char_matrix_str::valid_as_scalar_index (void) const |
|
159 { |
|
160 bool retval = false; |
|
161 error ("octave_char_matrix_str::valid_as_scalar_index(): not implemented"); |
|
162 return retval; |
|
163 } |
|
164 bool |
|
165 octave_char_matrix_str::valid_as_zero_index (void) const |
|
166 { |
|
167 bool retval = false; |
|
168 error ("octave_char_matrix_str::valid_as_zero_index(): not implemented"); |
|
169 return retval; |
|
170 } |
|
171 |
|
172 bool |
|
173 octave_char_matrix_str::is_true (void) const |
|
174 { |
|
175 bool retval = false; |
|
176 error ("octave_char_matrix_str::is_true(): not implemented"); |
|
177 return retval; |
|
178 } |
|
179 |
|
180 Matrix |
|
181 octave_char_matrix_str::matrix_value (bool force_string_conv) const |
|
182 { |
|
183 Matrix retval; |
|
184 |
|
185 int flag = force_string_conv; |
|
186 |
|
187 if (! flag) |
|
188 flag = Vimplicit_str_to_num_ok; |
|
189 |
|
190 if (flag < 0) |
|
191 gripe_implicit_conversion ("string", "real matrix"); |
|
192 |
|
193 if (flag) |
|
194 retval = Matrix (matrix); |
|
195 else |
|
196 gripe_invalid_conversion ("string", "real matrix"); |
|
197 |
|
198 return retval; |
|
199 } |
|
200 |
2493
|
201 string_vector |
2376
|
202 octave_char_matrix_str::all_strings (void) const |
|
203 { |
2493
|
204 int n = matrix.rows (); |
|
205 |
|
206 string_vector retval (n); |
|
207 |
|
208 for (int i = 0; i < n; i++) |
|
209 retval[i] = matrix.row_as_string (i, true); |
|
210 |
|
211 return retval; |
2376
|
212 } |
|
213 |
|
214 string |
|
215 octave_char_matrix_str::string_value (void) const |
|
216 { |
|
217 return matrix.row_as_string (0); // XXX FIXME??? XXX |
|
218 } |
|
219 |
|
220 void |
2901
|
221 octave_char_matrix_str::print (ostream& os, bool pr_as_read_syntax) const |
|
222 { |
2916
|
223 // indent (os); |
2901
|
224 print_raw (os, pr_as_read_syntax); |
|
225 newline (os); |
|
226 } |
|
227 |
|
228 void |
|
229 octave_char_matrix_str::print_raw (ostream& os, bool pr_as_read_syntax) const |
2376
|
230 { |
2466
|
231 octave_print_internal (os, matrix, pr_as_read_syntax, true, |
2901
|
232 current_print_indent_level ()); |
|
233 } |
|
234 |
|
235 bool |
|
236 octave_char_matrix_str::print_name_tag (ostream& os, const string& name) const |
|
237 { |
|
238 bool retval = false; |
|
239 |
|
240 indent (os); |
|
241 |
2933
|
242 if (rows () <= 1) |
2901
|
243 os << name << " = "; |
|
244 else |
|
245 { |
|
246 os << name << " ="; |
|
247 newline (os); |
|
248 newline (os); |
|
249 retval = true; |
|
250 } |
|
251 |
|
252 return retval; |
2376
|
253 } |
|
254 |
|
255 /* |
|
256 ;;; Local Variables: *** |
|
257 ;;; mode: C++ *** |
|
258 ;;; End: *** |
|
259 */ |