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 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2376
|
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 |
4513
|
79 retval = octave_value (charNDArray (matrix.index (i, j, resize_ok)), |
3933
|
80 true); |
2407
|
81 } |
|
82 break; |
|
83 |
|
84 case 1: |
|
85 { |
|
86 idx_vector i = idx (0).index_vector (); |
|
87 |
4513
|
88 retval = octave_value (charNDArray (matrix.index (i, resize_ok)), |
|
89 true); |
2407
|
90 } |
|
91 break; |
|
92 |
|
93 default: |
4513
|
94 { |
|
95 Array<idx_vector> idx_vec (len); |
|
96 |
|
97 for (int i = 0; i < len; i++) |
|
98 idx_vec(i) = idx(i).index_vector (); |
|
99 |
|
100 retval = octave_value (charNDArray (matrix.index (idx_vec, resize_ok)), |
|
101 true); |
|
102 } |
2407
|
103 break; |
|
104 } |
|
105 |
|
106 return retval; |
|
107 } |
|
108 |
|
109 void |
|
110 octave_char_matrix_str::assign (const octave_value_list& idx, |
|
111 const charMatrix& rhs) |
|
112 { |
|
113 int len = idx.length (); |
|
114 |
2571
|
115 // XXX FIXME XXX |
|
116 charMatrix tmp = rhs; |
|
117 if (tmp.rows () == 1 && tmp.columns () == 0) |
|
118 tmp.resize (0, 0); |
|
119 |
4513
|
120 for (int i = 0; i < len; i++) |
|
121 matrix.set_index (idx(i).index_vector ()); |
2407
|
122 |
4513
|
123 ::assign (matrix, tmp, Vstring_fill_char); |
2407
|
124 } |
|
125 |
2376
|
126 bool |
|
127 octave_char_matrix_str::valid_as_scalar_index (void) const |
|
128 { |
|
129 bool retval = false; |
|
130 error ("octave_char_matrix_str::valid_as_scalar_index(): not implemented"); |
|
131 return retval; |
|
132 } |
|
133 |
|
134 Matrix |
|
135 octave_char_matrix_str::matrix_value (bool force_string_conv) const |
|
136 { |
|
137 Matrix retval; |
|
138 |
4452
|
139 if (! force_string_conv && Vwarn_str_to_num) |
2376
|
140 gripe_implicit_conversion ("string", "real matrix"); |
|
141 |
4513
|
142 retval = Matrix (matrix.matrix_value ()); |
2376
|
143 |
|
144 return retval; |
|
145 } |
|
146 |
2493
|
147 string_vector |
4457
|
148 octave_char_matrix_str::all_strings (bool, bool) const |
2376
|
149 { |
4513
|
150 string_vector retval; |
|
151 |
|
152 if (matrix.ndims () == 2) |
|
153 { |
|
154 charMatrix chm = matrix.matrix_value (); |
|
155 |
|
156 int n = chm.rows (); |
2493
|
157 |
4513
|
158 retval.resize (n); |
2493
|
159 |
4513
|
160 for (int i = 0; i < n; i++) |
|
161 retval[i] = chm.row_as_string (i, true); |
|
162 } |
|
163 else |
|
164 error ("invalid conversion of charNDArray to string_vector"); |
2493
|
165 |
|
166 return retval; |
2376
|
167 } |
|
168 |
3536
|
169 std::string |
4457
|
170 octave_char_matrix_str::string_value (bool) const |
2376
|
171 { |
4513
|
172 std::string retval; |
|
173 |
|
174 if (matrix.ndims () == 2) |
|
175 { |
|
176 charMatrix chm = matrix.matrix_value (); |
|
177 |
|
178 retval = chm.row_as_string (0); // XXX FIXME??? XXX |
|
179 } |
|
180 else |
|
181 error ("invalid conversion of charNDArray to string"); |
|
182 |
|
183 return retval; |
2376
|
184 } |
|
185 |
|
186 void |
3523
|
187 octave_char_matrix_str::print_raw (std::ostream& os, bool pr_as_read_syntax) const |
2376
|
188 { |
3219
|
189 octave_print_internal (os, matrix, pr_as_read_syntax, |
|
190 current_print_indent_level (), true); |
2376
|
191 } |
|
192 |
|
193 /* |
|
194 ;;; Local Variables: *** |
|
195 ;;; mode: C++ *** |
|
196 ;;; End: *** |
|
197 */ |