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