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