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 |
3203
|
54 Matrix m = v.matrix_value (); |
|
55 |
|
56 return error_state ? 0 : new octave_matrix (m); |
2376
|
57 } |
|
58 |
2427
|
59 type_conv_fcn |
2376
|
60 octave_char_matrix_str::numeric_conversion_function (void) const |
|
61 { |
|
62 return default_numeric_conversion_function; |
|
63 } |
|
64 |
|
65 octave_value |
2974
|
66 octave_char_matrix_str::do_index_op (const octave_value_list& idx) |
2407
|
67 { |
|
68 octave_value retval; |
|
69 |
|
70 int len = idx.length (); |
|
71 |
|
72 switch (len) |
|
73 { |
|
74 case 2: |
|
75 { |
|
76 idx_vector i = idx (0).index_vector (); |
|
77 idx_vector j = idx (1).index_vector (); |
|
78 |
|
79 retval = octave_value (charMatrix (matrix.index (i, j)), true); |
|
80 } |
|
81 break; |
|
82 |
|
83 case 1: |
|
84 { |
|
85 idx_vector i = idx (0).index_vector (); |
|
86 |
|
87 retval = octave_value (charMatrix (matrix.index (i)), true); |
|
88 } |
|
89 break; |
|
90 |
|
91 default: |
|
92 error ("invalid number of indices (%d) for matrix value", len); |
|
93 break; |
|
94 } |
|
95 |
|
96 return retval; |
|
97 } |
|
98 |
3109
|
99 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) |
2407
|
100 extern void assign (Array2<char>&, const Array2<char>&); |
3107
|
101 #endif |
2407
|
102 |
|
103 void |
|
104 octave_char_matrix_str::assign (const octave_value_list& idx, |
|
105 const charMatrix& rhs) |
|
106 { |
|
107 int len = idx.length (); |
|
108 |
2571
|
109 // XXX FIXME XXX |
|
110 charMatrix tmp = rhs; |
|
111 if (tmp.rows () == 1 && tmp.columns () == 0) |
|
112 tmp.resize (0, 0); |
|
113 |
2407
|
114 switch (len) |
|
115 { |
|
116 case 2: |
|
117 { |
|
118 idx_vector i = idx (0).index_vector (); |
|
119 idx_vector j = idx (1).index_vector (); |
|
120 |
|
121 matrix.set_index (i); |
|
122 matrix.set_index (j); |
|
123 |
2571
|
124 ::assign (matrix, tmp); |
2407
|
125 } |
|
126 break; |
|
127 |
|
128 case 1: |
|
129 { |
|
130 idx_vector i = idx (0).index_vector (); |
|
131 |
|
132 matrix.set_index (i); |
|
133 |
2571
|
134 ::assign (matrix, tmp); |
2407
|
135 } |
|
136 break; |
|
137 |
|
138 default: |
|
139 error ("invalid number of indices (%d) for indexed matrix assignment", |
|
140 len); |
|
141 break; |
|
142 } |
|
143 } |
|
144 |
2376
|
145 bool |
|
146 octave_char_matrix_str::valid_as_scalar_index (void) const |
|
147 { |
|
148 bool retval = false; |
|
149 error ("octave_char_matrix_str::valid_as_scalar_index(): not implemented"); |
|
150 return retval; |
|
151 } |
|
152 bool |
|
153 octave_char_matrix_str::valid_as_zero_index (void) const |
|
154 { |
|
155 bool retval = false; |
|
156 error ("octave_char_matrix_str::valid_as_zero_index(): not implemented"); |
|
157 return retval; |
|
158 } |
|
159 |
|
160 Matrix |
|
161 octave_char_matrix_str::matrix_value (bool force_string_conv) const |
|
162 { |
|
163 Matrix retval; |
|
164 |
|
165 int flag = force_string_conv; |
|
166 |
|
167 if (! flag) |
|
168 flag = Vimplicit_str_to_num_ok; |
|
169 |
|
170 if (flag < 0) |
|
171 gripe_implicit_conversion ("string", "real matrix"); |
|
172 |
|
173 if (flag) |
|
174 retval = Matrix (matrix); |
|
175 else |
|
176 gripe_invalid_conversion ("string", "real matrix"); |
|
177 |
|
178 return retval; |
|
179 } |
|
180 |
2493
|
181 string_vector |
2376
|
182 octave_char_matrix_str::all_strings (void) const |
|
183 { |
2493
|
184 int n = matrix.rows (); |
|
185 |
|
186 string_vector retval (n); |
|
187 |
|
188 for (int i = 0; i < n; i++) |
|
189 retval[i] = matrix.row_as_string (i, true); |
|
190 |
|
191 return retval; |
2376
|
192 } |
|
193 |
|
194 string |
|
195 octave_char_matrix_str::string_value (void) const |
|
196 { |
|
197 return matrix.row_as_string (0); // XXX FIXME??? XXX |
|
198 } |
|
199 |
|
200 void |
2901
|
201 octave_char_matrix_str::print (ostream& os, bool pr_as_read_syntax) const |
|
202 { |
2916
|
203 // indent (os); |
2901
|
204 print_raw (os, pr_as_read_syntax); |
|
205 newline (os); |
|
206 } |
|
207 |
|
208 void |
|
209 octave_char_matrix_str::print_raw (ostream& os, bool pr_as_read_syntax) const |
2376
|
210 { |
2466
|
211 octave_print_internal (os, matrix, pr_as_read_syntax, true, |
2901
|
212 current_print_indent_level ()); |
|
213 } |
|
214 |
|
215 bool |
|
216 octave_char_matrix_str::print_name_tag (ostream& os, const string& name) const |
|
217 { |
|
218 bool retval = false; |
|
219 |
|
220 indent (os); |
|
221 |
2933
|
222 if (rows () <= 1) |
2901
|
223 os << name << " = "; |
|
224 else |
|
225 { |
|
226 os << name << " ="; |
|
227 newline (os); |
|
228 newline (os); |
|
229 retval = true; |
|
230 } |
|
231 |
|
232 return retval; |
2376
|
233 } |
|
234 |
|
235 /* |
|
236 ;;; Local Variables: *** |
|
237 ;;; mode: C++ *** |
|
238 ;;; End: *** |
|
239 */ |