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 |
3503
|
31 #include <iostream> |
2901
|
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" |
3836
|
42 #include "pt-mat.h" |
2376
|
43 |
3219
|
44 DEFINE_OCTAVE_ALLOCATOR (octave_char_matrix_str); |
2376
|
45 |
3219
|
46 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_char_matrix_str, "string"); |
2376
|
47 |
|
48 static octave_value * |
|
49 default_numeric_conversion_function (const octave_value& a) |
|
50 { |
|
51 CAST_CONV_ARG (const octave_char_matrix_str&); |
|
52 |
3203
|
53 Matrix m = v.matrix_value (); |
|
54 |
|
55 return error_state ? 0 : new octave_matrix (m); |
2376
|
56 } |
|
57 |
2427
|
58 type_conv_fcn |
2376
|
59 octave_char_matrix_str::numeric_conversion_function (void) const |
|
60 { |
|
61 return default_numeric_conversion_function; |
|
62 } |
|
63 |
|
64 octave_value |
3933
|
65 octave_char_matrix_str::do_index_op (const octave_value_list& idx, |
|
66 int resize_ok) |
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 |
3933
|
79 retval = octave_value (charMatrix (matrix.index (i, j, resize_ok)), |
|
80 true); |
2407
|
81 } |
|
82 break; |
|
83 |
|
84 case 1: |
|
85 { |
|
86 idx_vector i = idx (0).index_vector (); |
|
87 |
3933
|
88 retval = octave_value (charMatrix (matrix.index (i, resize_ok)), true); |
2407
|
89 } |
|
90 break; |
|
91 |
|
92 default: |
|
93 error ("invalid number of indices (%d) for matrix value", len); |
|
94 break; |
|
95 } |
|
96 |
|
97 return retval; |
|
98 } |
|
99 |
|
100 void |
|
101 octave_char_matrix_str::assign (const octave_value_list& idx, |
|
102 const charMatrix& rhs) |
|
103 { |
|
104 int len = idx.length (); |
|
105 |
2571
|
106 // XXX FIXME XXX |
|
107 charMatrix tmp = rhs; |
|
108 if (tmp.rows () == 1 && tmp.columns () == 0) |
|
109 tmp.resize (0, 0); |
|
110 |
2407
|
111 switch (len) |
|
112 { |
|
113 case 2: |
|
114 { |
|
115 idx_vector i = idx (0).index_vector (); |
|
116 idx_vector j = idx (1).index_vector (); |
|
117 |
|
118 matrix.set_index (i); |
|
119 matrix.set_index (j); |
|
120 |
3836
|
121 ::assign (matrix, tmp, Vstring_fill_char); |
2407
|
122 } |
|
123 break; |
|
124 |
|
125 case 1: |
|
126 { |
|
127 idx_vector i = idx (0).index_vector (); |
|
128 |
|
129 matrix.set_index (i); |
|
130 |
3836
|
131 ::assign (matrix, tmp, Vstring_fill_char); |
2407
|
132 } |
|
133 break; |
|
134 |
|
135 default: |
|
136 error ("invalid number of indices (%d) for indexed matrix assignment", |
|
137 len); |
|
138 break; |
|
139 } |
|
140 } |
|
141 |
2376
|
142 bool |
|
143 octave_char_matrix_str::valid_as_scalar_index (void) const |
|
144 { |
|
145 bool retval = false; |
|
146 error ("octave_char_matrix_str::valid_as_scalar_index(): not implemented"); |
|
147 return retval; |
|
148 } |
|
149 |
|
150 Matrix |
|
151 octave_char_matrix_str::matrix_value (bool force_string_conv) const |
|
152 { |
|
153 Matrix retval; |
|
154 |
|
155 int flag = force_string_conv; |
|
156 |
|
157 if (! flag) |
|
158 flag = Vimplicit_str_to_num_ok; |
|
159 |
|
160 if (flag < 0) |
|
161 gripe_implicit_conversion ("string", "real matrix"); |
|
162 |
|
163 if (flag) |
|
164 retval = Matrix (matrix); |
|
165 else |
|
166 gripe_invalid_conversion ("string", "real matrix"); |
|
167 |
|
168 return retval; |
|
169 } |
|
170 |
2493
|
171 string_vector |
2376
|
172 octave_char_matrix_str::all_strings (void) const |
|
173 { |
2493
|
174 int n = matrix.rows (); |
|
175 |
|
176 string_vector retval (n); |
|
177 |
|
178 for (int i = 0; i < n; i++) |
|
179 retval[i] = matrix.row_as_string (i, true); |
|
180 |
|
181 return retval; |
2376
|
182 } |
|
183 |
3536
|
184 std::string |
2376
|
185 octave_char_matrix_str::string_value (void) const |
|
186 { |
|
187 return matrix.row_as_string (0); // XXX FIXME??? XXX |
|
188 } |
|
189 |
|
190 void |
3523
|
191 octave_char_matrix_str::print_raw (std::ostream& os, bool pr_as_read_syntax) const |
2376
|
192 { |
3219
|
193 octave_print_internal (os, matrix, pr_as_read_syntax, |
|
194 current_print_indent_level (), true); |
2376
|
195 } |
|
196 |
|
197 /* |
|
198 ;;; Local Variables: *** |
|
199 ;;; mode: C++ *** |
|
200 ;;; End: *** |
|
201 */ |