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 |
|
35 #include "gripes.h" |
|
36 #include "oct-map.h" |
2974
|
37 #include "oct-obj.h" |
2979
|
38 #include "oct-lvalue.h" |
3340
|
39 #include "oct-stream.h" |
2376
|
40 #include "ops.h" |
|
41 #include "ov-base.h" |
3928
|
42 #include "ov-cell.h" |
|
43 #include "ov-ch-mat.h" |
2376
|
44 #include "ov-complex.h" |
|
45 #include "ov-cx-mat.h" |
3928
|
46 #include "ov-list.h" |
|
47 #include "ov-range.h" |
|
48 #include "ov-re-mat.h" |
|
49 #include "ov-scalar.h" |
2376
|
50 #include "ov-str-mat.h" |
2948
|
51 #include "variables.h" |
2376
|
52 |
3219
|
53 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_base_value, "<unknown type>"); |
2376
|
54 |
|
55 octave_value |
3933
|
56 octave_base_value::subsref (const std::string, |
4219
|
57 const std::list<octave_value_list>&) |
3933
|
58 { |
|
59 std::string nm = type_name (); |
|
60 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
61 return octave_value (); |
|
62 } |
|
63 |
|
64 octave_value_list |
|
65 octave_base_value::subsref (const std::string, |
4219
|
66 const std::list<octave_value_list>&, int) |
3933
|
67 { |
|
68 std::string nm = type_name (); |
|
69 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
70 return octave_value (); |
|
71 } |
|
72 |
|
73 octave_value |
|
74 octave_base_value::do_index_op (const octave_value_list&, int) |
2974
|
75 { |
3523
|
76 std::string nm = type_name (); |
2974
|
77 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
78 return octave_value (); |
|
79 } |
|
80 |
|
81 octave_value_list |
3544
|
82 octave_base_value::do_multi_index_op (int, const octave_value_list&) |
2376
|
83 { |
3523
|
84 std::string nm = type_name (); |
2376
|
85 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
86 return octave_value (); |
|
87 } |
|
88 |
|
89 idx_vector |
|
90 octave_base_value::index_vector (void) const |
|
91 { |
3523
|
92 std::string nm = type_name (); |
2376
|
93 error ("%s type invalid as index value", nm.c_str ()); |
|
94 return idx_vector (); |
|
95 } |
|
96 |
|
97 octave_value |
3933
|
98 octave_base_value::subsasgn (const std::string type, |
4219
|
99 const std::list<octave_value_list>& idx, |
3933
|
100 const octave_value& rhs) |
2376
|
101 { |
3933
|
102 octave_value retval; |
2376
|
103 |
3933
|
104 if (is_defined ()) |
|
105 { |
4139
|
106 if (is_numeric_type ()) |
|
107 { |
|
108 switch (type[0]) |
|
109 { |
|
110 case '(': |
|
111 { |
|
112 if (type.length () == 1) |
|
113 retval = numeric_assign (type, idx, rhs); |
|
114 else |
|
115 { |
|
116 std::string nm = type_name (); |
|
117 error ("in indexed assignment of %s, last rhs index must be ()", |
|
118 nm.c_str ()); |
|
119 } |
|
120 } |
|
121 break; |
|
122 |
|
123 case '{': |
|
124 case '.': |
|
125 { |
|
126 std::string nm = type_name (); |
|
127 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
128 } |
|
129 break; |
|
130 |
|
131 default: |
|
132 panic_impossible (); |
|
133 } |
|
134 } |
|
135 else |
|
136 { |
|
137 std::string nm = type_name (); |
|
138 error ("can't perform indexed assignment for %s type", nm.c_str ()); |
|
139 } |
3933
|
140 } |
|
141 else |
|
142 { |
|
143 // Create new object of appropriate type for given index and rhs |
|
144 // types and then call subsasgn again for that object. |
|
145 |
|
146 octave_value tmp = octave_value::empty_conv (type, rhs); |
|
147 |
|
148 retval = tmp.subsasgn (type, idx, rhs); |
|
149 } |
|
150 |
|
151 return retval; |
2376
|
152 } |
|
153 |
|
154 octave_value |
|
155 octave_base_value::convert_to_str (void) const |
|
156 { |
|
157 gripe_wrong_type_arg ("octave_base_value::convert_to_str ()", |
|
158 type_name ()); |
|
159 return octave_value (); |
|
160 } |
|
161 |
|
162 void |
|
163 octave_base_value::convert_to_row_or_column_vector (void) |
|
164 { |
|
165 gripe_wrong_type_arg |
|
166 ("octave_base_value::convert_to_row_or_column_vector ()", |
|
167 type_name ()); |
|
168 } |
|
169 |
|
170 void |
3523
|
171 octave_base_value::print (std::ostream&, bool) const |
2376
|
172 { |
3195
|
173 gripe_wrong_type_arg ("octave_base_value::print ()", type_name ()); |
2376
|
174 } |
|
175 |
2901
|
176 void |
3523
|
177 octave_base_value::print_raw (std::ostream&, bool) const |
2901
|
178 { |
3195
|
179 gripe_wrong_type_arg ("octave_base_value::print_raw ()", type_name ()); |
2901
|
180 } |
|
181 |
|
182 bool |
3523
|
183 octave_base_value::print_name_tag (std::ostream& os, const std::string& name) const |
2901
|
184 { |
|
185 indent (os); |
|
186 os << name << " ="; |
|
187 newline (os); |
|
188 newline (os); |
|
189 return true; |
|
190 } |
|
191 |
3933
|
192 void |
|
193 octave_base_value::print_info (std::ostream& os, |
|
194 const std::string& prefix) const |
|
195 { |
|
196 os << "no info for type: " << type_name () << "\n"; |
|
197 } |
|
198 |
3195
|
199 int |
3202
|
200 octave_base_value::int_value (bool require_int, bool frc_str_conv) const |
|
201 { |
|
202 int retval = 0; |
|
203 |
|
204 double d = double_value (frc_str_conv); |
|
205 |
|
206 if (! error_state) |
|
207 { |
|
208 if (require_int && D_NINT (d) != d) |
|
209 { |
|
210 error ("conversion to integer value failed"); |
|
211 return retval; |
|
212 } |
|
213 |
|
214 retval = static_cast<int> (d); |
|
215 } |
|
216 else |
|
217 gripe_wrong_type_arg ("octave_base_value::int_value ()", type_name ()); |
|
218 |
|
219 return retval; |
|
220 } |
|
221 |
|
222 int |
|
223 octave_base_value::nint_value (bool frc_str_conv) const |
|
224 { |
|
225 int retval = 0; |
|
226 |
|
227 double d = double_value (frc_str_conv); |
|
228 |
|
229 if (! error_state) |
|
230 { |
|
231 if (xisnan (d)) |
|
232 { |
|
233 error ("conversion of NaN to integer value failed"); |
|
234 return retval; |
|
235 } |
|
236 |
|
237 retval = NINT (d); |
|
238 } |
|
239 else |
|
240 gripe_wrong_type_arg ("octave_base_value::nint_value ()", type_name ()); |
|
241 |
|
242 return retval; |
|
243 } |
|
244 |
2376
|
245 double |
|
246 octave_base_value::double_value (bool) const |
|
247 { |
4102
|
248 double retval = lo_ieee_nan_value (); |
2376
|
249 gripe_wrong_type_arg ("octave_base_value::double_value ()", type_name ()); |
|
250 return retval; |
|
251 } |
|
252 |
3351
|
253 Cell |
3539
|
254 octave_base_value::cell_value () const |
3351
|
255 { |
|
256 Cell retval; |
|
257 gripe_wrong_type_arg ("octave_base_value::cell_value()", type_name ()); |
|
258 return retval; |
|
259 } |
|
260 |
2376
|
261 Matrix |
|
262 octave_base_value::matrix_value (bool) const |
|
263 { |
|
264 Matrix retval; |
|
265 gripe_wrong_type_arg ("octave_base_value::matrix_value()", type_name ()); |
|
266 return retval; |
|
267 } |
|
268 |
|
269 Complex |
|
270 octave_base_value::complex_value (bool) const |
|
271 { |
4102
|
272 double tmp = lo_ieee_nan_value (); |
|
273 Complex retval (tmp, tmp); |
2376
|
274 gripe_wrong_type_arg ("octave_base_value::complex_value()", type_name ()); |
|
275 return retval; |
|
276 } |
|
277 |
|
278 ComplexMatrix |
|
279 octave_base_value::complex_matrix_value (bool) const |
|
280 { |
|
281 ComplexMatrix retval; |
|
282 gripe_wrong_type_arg ("octave_base_value::complex_matrix_value()", |
|
283 type_name ()); |
|
284 return retval; |
|
285 } |
|
286 |
|
287 charMatrix |
|
288 octave_base_value::char_matrix_value (bool) const |
|
289 { |
|
290 charMatrix retval; |
|
291 gripe_wrong_type_arg ("octave_base_value::char_matrix_value()", |
|
292 type_name ()); |
|
293 return retval; |
|
294 } |
|
295 |
2493
|
296 string_vector |
2376
|
297 octave_base_value::all_strings (void) const |
|
298 { |
2493
|
299 string_vector retval; |
2376
|
300 gripe_wrong_type_arg ("octave_base_value::all_strings()", type_name ()); |
|
301 return retval; |
|
302 } |
|
303 |
3536
|
304 std::string |
2376
|
305 octave_base_value::string_value (void) const |
|
306 { |
3523
|
307 std::string retval; |
2376
|
308 gripe_wrong_type_arg ("octave_base_value::string_value()", type_name ()); |
|
309 return retval; |
|
310 } |
|
311 |
|
312 Range |
|
313 octave_base_value::range_value (void) const |
|
314 { |
|
315 Range retval; |
|
316 gripe_wrong_type_arg ("octave_base_value::range_value()", type_name ()); |
|
317 return retval; |
|
318 } |
|
319 |
|
320 Octave_map |
|
321 octave_base_value::map_value (void) const |
|
322 { |
|
323 Octave_map retval; |
|
324 gripe_wrong_type_arg ("octave_base_value::map_value()", type_name ()); |
|
325 return retval; |
|
326 } |
|
327 |
3933
|
328 string_vector |
|
329 octave_base_value::map_keys (void) const |
|
330 { |
|
331 string_vector retval; |
|
332 gripe_wrong_type_arg ("octave_base_value::map_keys()", type_name ()); |
|
333 return retval; |
|
334 } |
|
335 |
3340
|
336 octave_stream |
2901
|
337 octave_base_value::stream_value (void) const |
|
338 { |
3340
|
339 octave_stream retval; |
2901
|
340 gripe_wrong_type_arg ("octave_base_value::stream_value()", type_name ()); |
|
341 return retval; |
|
342 } |
|
343 |
|
344 int |
|
345 octave_base_value::stream_number (void) const |
|
346 { |
|
347 int retval = -1; |
|
348 gripe_wrong_type_arg ("octave_base_value::stream_number()", type_name ()); |
|
349 return retval; |
|
350 } |
|
351 |
2974
|
352 octave_function * |
|
353 octave_base_value::function_value (bool silent) |
|
354 { |
|
355 octave_function *retval = 0; |
|
356 |
|
357 if (! silent) |
|
358 gripe_wrong_type_arg ("octave_base_value::function_value()", |
|
359 type_name ()); |
|
360 return retval; |
|
361 } |
|
362 |
2882
|
363 octave_value_list |
|
364 octave_base_value::list_value (void) const |
|
365 { |
|
366 octave_value_list retval; |
|
367 gripe_wrong_type_arg ("octave_base_value::list_value()", type_name ()); |
|
368 return retval; |
|
369 } |
|
370 |
2825
|
371 bool |
|
372 octave_base_value::bool_value (void) const |
|
373 { |
|
374 bool retval = false; |
|
375 gripe_wrong_type_arg ("octave_base_value::bool_value()", type_name ()); |
|
376 return retval; |
|
377 } |
|
378 |
|
379 boolMatrix |
|
380 octave_base_value::bool_matrix_value (void) const |
|
381 { |
|
382 boolMatrix retval; |
|
383 gripe_wrong_type_arg ("octave_base_value::bool_matrix_value()", |
|
384 type_name ()); |
|
385 return retval; |
|
386 } |
|
387 |
3203
|
388 CONVDECLX (matrix_conv) |
2376
|
389 { |
|
390 return new octave_matrix (); |
|
391 } |
|
392 |
3203
|
393 CONVDECLX (complex_matrix_conv) |
2376
|
394 { |
|
395 return new octave_complex_matrix (); |
|
396 } |
|
397 |
3203
|
398 CONVDECLX (string_conv) |
2376
|
399 { |
|
400 return new octave_char_matrix_str (); |
|
401 } |
|
402 |
3928
|
403 CONVDECLX (cell_conv) |
|
404 { |
|
405 return new octave_cell (); |
|
406 } |
|
407 |
2376
|
408 void |
|
409 install_base_type_conversions (void) |
|
410 { |
|
411 INSTALL_ASSIGNCONV (octave_base_value, octave_scalar, octave_matrix); |
|
412 INSTALL_ASSIGNCONV (octave_base_value, octave_matrix, octave_matrix); |
|
413 INSTALL_ASSIGNCONV (octave_base_value, octave_complex, octave_complex_matrix); |
|
414 INSTALL_ASSIGNCONV (octave_base_value, octave_complex_matrix, octave_complex_matrix); |
|
415 INSTALL_ASSIGNCONV (octave_base_value, octave_range, octave_matrix); |
|
416 INSTALL_ASSIGNCONV (octave_base_value, octave_char_matrix_str, octave_char_matrix_str); |
3928
|
417 INSTALL_ASSIGNCONV (octave_base_value, octave_cell, octave_cell); |
2376
|
418 |
|
419 INSTALL_WIDENOP (octave_base_value, octave_matrix, matrix_conv); |
|
420 INSTALL_WIDENOP (octave_base_value, octave_complex_matrix, complex_matrix_conv); |
|
421 INSTALL_WIDENOP (octave_base_value, octave_char_matrix_str, string_conv); |
3928
|
422 INSTALL_WIDENOP (octave_base_value, octave_cell, cell_conv); |
2376
|
423 } |
|
424 |
|
425 /* |
|
426 ;;; Local Variables: *** |
|
427 ;;; mode: C++ *** |
|
428 ;;; End: *** |
|
429 */ |