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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2376
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
4254
|
28 #include <climits> |
|
29 |
3503
|
30 #include <iostream> |
2901
|
31 |
5759
|
32 #include "Array-flags.h" |
2376
|
33 #include "lo-ieee.h" |
4732
|
34 #include "lo-mappers.h" |
4649
|
35 #include "so-array.h" |
2376
|
36 |
5759
|
37 #include "defun.h" |
2376
|
38 #include "gripes.h" |
|
39 #include "oct-map.h" |
2974
|
40 #include "oct-obj.h" |
2979
|
41 #include "oct-lvalue.h" |
3340
|
42 #include "oct-stream.h" |
2376
|
43 #include "ops.h" |
|
44 #include "ov-base.h" |
3928
|
45 #include "ov-cell.h" |
|
46 #include "ov-ch-mat.h" |
2376
|
47 #include "ov-complex.h" |
|
48 #include "ov-cx-mat.h" |
3928
|
49 #include "ov-list.h" |
|
50 #include "ov-range.h" |
|
51 #include "ov-re-mat.h" |
|
52 #include "ov-scalar.h" |
2376
|
53 #include "ov-str-mat.h" |
4343
|
54 #include "ov-fcn-handle.h" |
5759
|
55 #include "parse.h" |
|
56 #include "utils.h" |
2948
|
57 #include "variables.h" |
2376
|
58 |
4612
|
59 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_base_value, |
|
60 "<unknown type>", "unknown"); |
2376
|
61 |
5759
|
62 // If TRUE, print the name along with the value. |
|
63 static bool Vprint_answer_id_name; |
|
64 |
|
65 // If TRUE, turn off printing of results in functions (as if a |
|
66 // semicolon has been appended to each statement). |
|
67 static bool Vsilent_functions; |
|
68 |
|
69 // Should we print a warning when converting `[97, 98, 99, "123"]' |
|
70 // to a character string? |
|
71 bool Vwarn_num_to_str; |
|
72 |
|
73 // If TRUE, print a warning when a matrix is resized by an indexed |
|
74 // assignment with indices outside the current bounds. |
|
75 bool Vwarn_resize_on_range_error; |
|
76 |
2376
|
77 octave_value |
4532
|
78 octave_base_value::squeeze (void) const |
|
79 { |
|
80 std::string nm = type_name (); |
|
81 error ("squeeze: invalid operation for %s type", nm.c_str ()); |
|
82 return octave_value (); |
|
83 } |
|
84 |
|
85 octave_value |
4247
|
86 octave_base_value::subsref (const std::string&, |
4219
|
87 const std::list<octave_value_list>&) |
3933
|
88 { |
|
89 std::string nm = type_name (); |
|
90 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
91 return octave_value (); |
|
92 } |
|
93 |
|
94 octave_value_list |
4247
|
95 octave_base_value::subsref (const std::string&, |
4219
|
96 const std::list<octave_value_list>&, int) |
3933
|
97 { |
|
98 std::string nm = type_name (); |
|
99 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
100 return octave_value (); |
|
101 } |
|
102 |
|
103 octave_value |
|
104 octave_base_value::do_index_op (const octave_value_list&, int) |
2974
|
105 { |
3523
|
106 std::string nm = type_name (); |
2974
|
107 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
108 return octave_value (); |
|
109 } |
|
110 |
5759
|
111 octave_value |
|
112 octave_base_value::do_index_op (const octave_value_list& idx) |
|
113 { |
|
114 return do_index_op (idx, 0); |
|
115 } |
|
116 |
2974
|
117 octave_value_list |
3544
|
118 octave_base_value::do_multi_index_op (int, const octave_value_list&) |
2376
|
119 { |
3523
|
120 std::string nm = type_name (); |
2376
|
121 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
122 return octave_value (); |
|
123 } |
|
124 |
|
125 idx_vector |
|
126 octave_base_value::index_vector (void) const |
|
127 { |
3523
|
128 std::string nm = type_name (); |
2376
|
129 error ("%s type invalid as index value", nm.c_str ()); |
|
130 return idx_vector (); |
|
131 } |
|
132 |
5759
|
133 int |
|
134 octave_base_value::ndims (void) const |
|
135 { |
|
136 dim_vector dv = dims (); |
|
137 |
|
138 int n_dims = dv.length (); |
|
139 |
|
140 // Remove trailing singleton dimensions. |
|
141 |
|
142 for (int i = n_dims; i > 2; i--) |
|
143 { |
|
144 if (dv(i-1) == 1) |
|
145 n_dims--; |
|
146 else |
|
147 break; |
|
148 } |
|
149 |
|
150 // The result is always >= 2. |
|
151 |
|
152 if (n_dims < 2) |
|
153 n_dims = 2; |
|
154 |
|
155 return n_dims; |
|
156 } |
|
157 |
2376
|
158 octave_value |
4247
|
159 octave_base_value::subsasgn (const std::string& type, |
4219
|
160 const std::list<octave_value_list>& idx, |
3933
|
161 const octave_value& rhs) |
2376
|
162 { |
3933
|
163 octave_value retval; |
2376
|
164 |
3933
|
165 if (is_defined ()) |
|
166 { |
4139
|
167 if (is_numeric_type ()) |
|
168 { |
|
169 switch (type[0]) |
|
170 { |
|
171 case '(': |
|
172 { |
|
173 if (type.length () == 1) |
|
174 retval = numeric_assign (type, idx, rhs); |
4436
|
175 else if (is_empty ()) |
|
176 { |
|
177 // Allow conversion of empty matrix to some other |
|
178 // type in cases like |
|
179 // |
|
180 // x = []; x(i).f = rhs |
|
181 |
|
182 octave_value tmp = octave_value::empty_conv (type, rhs); |
|
183 |
|
184 retval = tmp.subsasgn (type, idx, rhs); |
|
185 } |
4139
|
186 else |
|
187 { |
|
188 std::string nm = type_name (); |
|
189 error ("in indexed assignment of %s, last rhs index must be ()", |
|
190 nm.c_str ()); |
|
191 } |
|
192 } |
|
193 break; |
|
194 |
|
195 case '{': |
|
196 case '.': |
|
197 { |
|
198 std::string nm = type_name (); |
|
199 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
200 } |
|
201 break; |
|
202 |
|
203 default: |
|
204 panic_impossible (); |
|
205 } |
|
206 } |
|
207 else |
|
208 { |
|
209 std::string nm = type_name (); |
|
210 error ("can't perform indexed assignment for %s type", nm.c_str ()); |
|
211 } |
3933
|
212 } |
|
213 else |
|
214 { |
|
215 // Create new object of appropriate type for given index and rhs |
|
216 // types and then call subsasgn again for that object. |
|
217 |
|
218 octave_value tmp = octave_value::empty_conv (type, rhs); |
|
219 |
|
220 retval = tmp.subsasgn (type, idx, rhs); |
|
221 } |
|
222 |
|
223 return retval; |
2376
|
224 } |
|
225 |
5602
|
226 octave_idx_type |
|
227 octave_base_value::nnz (void) const |
|
228 { |
|
229 gripe_wrong_type_arg ("octave_base_value::nnz ()", type_name ()); |
|
230 return -1; |
|
231 } |
|
232 |
5604
|
233 octave_idx_type |
|
234 octave_base_value::nzmax (void) const |
|
235 { |
|
236 gripe_wrong_type_arg ("octave_base_value::nzmax ()", type_name ()); |
|
237 return -1; |
|
238 } |
|
239 |
2376
|
240 octave_value |
4567
|
241 octave_base_value::reshape (const dim_vector&) const |
|
242 { |
|
243 gripe_wrong_type_arg ("octave_base_value::reshape ()", type_name ()); |
|
244 return octave_value (); |
|
245 } |
|
246 |
|
247 octave_value |
4593
|
248 octave_base_value::permute (const Array<int>&, bool) const |
|
249 { |
|
250 gripe_wrong_type_arg ("octave_base_value::permute ()", type_name ()); |
|
251 return octave_value (); |
|
252 } |
|
253 |
|
254 octave_value |
5731
|
255 octave_base_value::resize (const dim_vector&, bool) const |
4915
|
256 { |
|
257 gripe_wrong_type_arg ("octave_base_value::resize ()", type_name ()); |
|
258 return octave_value (); |
|
259 } |
|
260 |
|
261 octave_value |
5759
|
262 octave_base_value::all (int) const |
|
263 { |
|
264 return 0.0; |
|
265 } |
|
266 |
|
267 octave_value |
|
268 octave_base_value::any (int) const |
|
269 { |
|
270 return 0.0; |
|
271 } |
|
272 |
|
273 octave_value |
|
274 octave_base_value::convert_to_str (bool pad, bool force, char type) const |
|
275 { |
|
276 octave_value retval = convert_to_str_internal (pad, force, type); |
|
277 |
|
278 if (! force && is_numeric_type () && Vwarn_num_to_str) |
|
279 gripe_implicit_conversion (type_name (), retval.type_name ()); |
|
280 |
|
281 return retval; |
|
282 } |
|
283 |
|
284 octave_value |
5279
|
285 octave_base_value::convert_to_str_internal (bool, bool, char) const |
2376
|
286 { |
4452
|
287 gripe_wrong_type_arg ("octave_base_value::convert_to_str_internal ()", |
2376
|
288 type_name ()); |
|
289 return octave_value (); |
|
290 } |
|
291 |
|
292 void |
|
293 octave_base_value::convert_to_row_or_column_vector (void) |
|
294 { |
|
295 gripe_wrong_type_arg |
|
296 ("octave_base_value::convert_to_row_or_column_vector ()", |
|
297 type_name ()); |
|
298 } |
|
299 |
|
300 void |
3523
|
301 octave_base_value::print (std::ostream&, bool) const |
2376
|
302 { |
3195
|
303 gripe_wrong_type_arg ("octave_base_value::print ()", type_name ()); |
2376
|
304 } |
|
305 |
2901
|
306 void |
3523
|
307 octave_base_value::print_raw (std::ostream&, bool) const |
2901
|
308 { |
3195
|
309 gripe_wrong_type_arg ("octave_base_value::print_raw ()", type_name ()); |
2901
|
310 } |
|
311 |
|
312 bool |
3523
|
313 octave_base_value::print_name_tag (std::ostream& os, const std::string& name) const |
2901
|
314 { |
4604
|
315 bool retval = false; |
|
316 |
2901
|
317 indent (os); |
4604
|
318 |
|
319 if (print_as_scalar ()) |
|
320 os << name << " = "; |
|
321 else |
|
322 { |
|
323 os << name << " ="; |
|
324 newline (os); |
|
325 newline (os); |
|
326 retval = true; |
|
327 } |
|
328 |
|
329 return retval; |
2901
|
330 } |
|
331 |
3933
|
332 void |
5759
|
333 octave_base_value::print_with_name (std::ostream& output_buf, |
|
334 const std::string& name, |
|
335 bool print_padding) const |
|
336 { |
|
337 if (! (evaluating_function_body && Vsilent_functions)) |
|
338 { |
|
339 bool pad_after = false; |
|
340 |
|
341 if (Vprint_answer_id_name) |
|
342 pad_after = print_name_tag (output_buf, name); |
|
343 |
|
344 print (output_buf); |
|
345 |
|
346 if (print_padding && pad_after) |
|
347 newline (output_buf); |
|
348 } |
|
349 } |
|
350 |
|
351 void |
3933
|
352 octave_base_value::print_info (std::ostream& os, |
4661
|
353 const std::string& /* prefix */) const |
3933
|
354 { |
|
355 os << "no info for type: " << type_name () << "\n"; |
|
356 } |
|
357 |
4254
|
358 #define INT_CONV_METHOD(T, F, MIN_LIMIT, MAX_LIMIT) \ |
|
359 T \ |
|
360 octave_base_value::F ## _value (bool require_int, bool frc_str_conv) const \ |
|
361 { \ |
|
362 T retval = 0; \ |
|
363 \ |
|
364 double d = double_value (frc_str_conv); \ |
|
365 \ |
|
366 if (! error_state) \ |
|
367 { \ |
|
368 if (require_int && D_NINT (d) != d) \ |
|
369 error ("conversion of %g to " #T " value failed", d); \ |
5054
|
370 else if (d < MIN_LIMIT) \ |
|
371 retval = MIN_LIMIT; \ |
|
372 else if (d > MAX_LIMIT) \ |
|
373 retval = MAX_LIMIT; \ |
4254
|
374 else \ |
4732
|
375 retval = static_cast<T> (fix (d)); \ |
4254
|
376 } \ |
|
377 else \ |
|
378 gripe_wrong_type_arg ("octave_base_value::" #F "_value ()", \ |
|
379 type_name ()); \ |
|
380 \ |
|
381 return retval; \ |
|
382 } |
3202
|
383 |
4254
|
384 INT_CONV_METHOD (short int, short, SHRT_MIN, SHRT_MAX) |
|
385 INT_CONV_METHOD (unsigned short int, ushort, 0, USHRT_MAX) |
3202
|
386 |
4254
|
387 INT_CONV_METHOD (int, int, INT_MIN, INT_MAX) |
|
388 INT_CONV_METHOD (unsigned int, uint, 0, UINT_MAX) |
3202
|
389 |
4254
|
390 INT_CONV_METHOD (long int, long, LONG_MIN, LONG_MAX) |
|
391 INT_CONV_METHOD (unsigned long int, ulong, 0, ULONG_MAX) |
3202
|
392 |
|
393 int |
|
394 octave_base_value::nint_value (bool frc_str_conv) const |
|
395 { |
|
396 int retval = 0; |
|
397 |
|
398 double d = double_value (frc_str_conv); |
|
399 |
|
400 if (! error_state) |
|
401 { |
|
402 if (xisnan (d)) |
|
403 { |
|
404 error ("conversion of NaN to integer value failed"); |
|
405 return retval; |
|
406 } |
|
407 |
4732
|
408 retval = static_cast<int> (fix (d)); |
3202
|
409 } |
|
410 else |
|
411 gripe_wrong_type_arg ("octave_base_value::nint_value ()", type_name ()); |
|
412 |
|
413 return retval; |
|
414 } |
|
415 |
2376
|
416 double |
|
417 octave_base_value::double_value (bool) const |
|
418 { |
4102
|
419 double retval = lo_ieee_nan_value (); |
2376
|
420 gripe_wrong_type_arg ("octave_base_value::double_value ()", type_name ()); |
|
421 return retval; |
|
422 } |
|
423 |
3351
|
424 Cell |
3539
|
425 octave_base_value::cell_value () const |
3351
|
426 { |
|
427 Cell retval; |
|
428 gripe_wrong_type_arg ("octave_base_value::cell_value()", type_name ()); |
|
429 return retval; |
|
430 } |
|
431 |
2376
|
432 Matrix |
|
433 octave_base_value::matrix_value (bool) const |
|
434 { |
|
435 Matrix retval; |
|
436 gripe_wrong_type_arg ("octave_base_value::matrix_value()", type_name ()); |
|
437 return retval; |
|
438 } |
|
439 |
4507
|
440 NDArray |
4550
|
441 octave_base_value::array_value (bool) const |
4505
|
442 { |
4507
|
443 NDArray retval; |
4550
|
444 gripe_wrong_type_arg ("octave_base_value::array_value()", type_name ()); |
4505
|
445 return retval; |
|
446 } |
|
447 |
2376
|
448 Complex |
|
449 octave_base_value::complex_value (bool) const |
|
450 { |
4102
|
451 double tmp = lo_ieee_nan_value (); |
|
452 Complex retval (tmp, tmp); |
2376
|
453 gripe_wrong_type_arg ("octave_base_value::complex_value()", type_name ()); |
|
454 return retval; |
|
455 } |
|
456 |
|
457 ComplexMatrix |
|
458 octave_base_value::complex_matrix_value (bool) const |
|
459 { |
|
460 ComplexMatrix retval; |
|
461 gripe_wrong_type_arg ("octave_base_value::complex_matrix_value()", |
|
462 type_name ()); |
|
463 return retval; |
|
464 } |
|
465 |
4550
|
466 ComplexNDArray |
|
467 octave_base_value::complex_array_value (bool) const |
|
468 { |
|
469 ComplexNDArray retval; |
|
470 gripe_wrong_type_arg ("octave_base_value::complex_array_value()", |
|
471 type_name ()); |
|
472 return retval; |
|
473 } |
|
474 |
|
475 bool |
|
476 octave_base_value::bool_value (void) const |
|
477 { |
|
478 bool retval = false; |
|
479 gripe_wrong_type_arg ("octave_base_value::bool_value()", type_name ()); |
|
480 return retval; |
|
481 } |
|
482 |
|
483 boolMatrix |
|
484 octave_base_value::bool_matrix_value (void) const |
|
485 { |
|
486 boolMatrix retval; |
|
487 gripe_wrong_type_arg ("octave_base_value::bool_matrix_value()", |
|
488 type_name ()); |
|
489 return retval; |
|
490 } |
|
491 |
|
492 boolNDArray |
4580
|
493 octave_base_value::bool_array_value (void) const |
4550
|
494 { |
|
495 boolNDArray retval; |
|
496 gripe_wrong_type_arg ("octave_base_value::bool_array_value()", |
|
497 type_name ()); |
|
498 return retval; |
|
499 } |
|
500 |
2376
|
501 charMatrix |
4741
|
502 octave_base_value::char_matrix_value (bool force) const |
2376
|
503 { |
|
504 charMatrix retval; |
4257
|
505 |
4741
|
506 octave_value tmp = convert_to_str (false, force); |
4257
|
507 |
4452
|
508 if (! error_state) |
|
509 retval = tmp.char_matrix_value (); |
|
510 |
2376
|
511 return retval; |
|
512 } |
|
513 |
4550
|
514 charNDArray |
|
515 octave_base_value::char_array_value (bool) const |
|
516 { |
|
517 charNDArray retval; |
|
518 gripe_wrong_type_arg ("octave_base_value::char_array_value()", |
|
519 type_name ()); |
|
520 return retval; |
|
521 } |
|
522 |
5164
|
523 SparseMatrix |
|
524 octave_base_value::sparse_matrix_value (bool) const |
|
525 { |
|
526 SparseMatrix retval; |
|
527 gripe_wrong_type_arg ("octave_base_value::sparse_matrix_value()", type_name ()); |
|
528 return retval; |
|
529 } |
|
530 |
|
531 SparseComplexMatrix |
|
532 octave_base_value::sparse_complex_matrix_value (bool) const |
|
533 { |
|
534 SparseComplexMatrix retval; |
|
535 gripe_wrong_type_arg ("octave_base_value::sparse_complex_matrix_value()", type_name ()); |
|
536 return retval; |
|
537 } |
|
538 |
|
539 SparseBoolMatrix |
|
540 octave_base_value::sparse_bool_matrix_value (bool) const |
|
541 { |
|
542 SparseBoolMatrix retval; |
|
543 gripe_wrong_type_arg ("octave_base_value::sparse_bool_matrix_value()", type_name ()); |
|
544 return retval; |
|
545 } |
|
546 |
4910
|
547 octave_int8 |
|
548 octave_base_value::int8_scalar_value (void) const |
|
549 { |
|
550 octave_int8 retval; |
|
551 gripe_wrong_type_arg ("octave_base_value::int8_scalar_value()", |
|
552 type_name ()); |
|
553 return retval; |
|
554 } |
|
555 |
|
556 octave_int16 |
|
557 octave_base_value::int16_scalar_value (void) const |
|
558 { |
|
559 octave_int16 retval; |
|
560 gripe_wrong_type_arg ("octave_base_value::int16_scalar_value()", |
|
561 type_name ()); |
|
562 return retval; |
|
563 } |
|
564 |
|
565 octave_int32 |
|
566 octave_base_value::int32_scalar_value (void) const |
|
567 { |
|
568 octave_int32 retval; |
|
569 gripe_wrong_type_arg ("octave_base_value::int32_scalar_value()", |
|
570 type_name ()); |
|
571 return retval; |
|
572 } |
|
573 |
|
574 octave_int64 |
|
575 octave_base_value::int64_scalar_value (void) const |
|
576 { |
|
577 octave_int64 retval; |
|
578 gripe_wrong_type_arg ("octave_base_value::int64_scalar_value()", |
|
579 type_name ()); |
|
580 return retval; |
|
581 } |
|
582 |
|
583 octave_uint8 |
|
584 octave_base_value::uint8_scalar_value (void) const |
|
585 { |
|
586 octave_uint8 retval; |
|
587 gripe_wrong_type_arg ("octave_base_value::uint8_scalar_value()", |
|
588 type_name ()); |
|
589 return retval; |
|
590 } |
|
591 |
|
592 octave_uint16 |
|
593 octave_base_value::uint16_scalar_value (void) const |
|
594 { |
|
595 octave_uint16 retval; |
|
596 gripe_wrong_type_arg ("octave_base_value::uint16_scalar_value()", |
|
597 type_name ()); |
|
598 return retval; |
|
599 } |
|
600 |
|
601 octave_uint32 |
|
602 octave_base_value::uint32_scalar_value (void) const |
|
603 { |
|
604 octave_uint32 retval; |
|
605 gripe_wrong_type_arg ("octave_base_value::uint32_scalar_value()", |
|
606 type_name ()); |
|
607 return retval; |
|
608 } |
|
609 |
|
610 octave_uint64 |
|
611 octave_base_value::uint64_scalar_value (void) const |
|
612 { |
|
613 octave_uint64 retval; |
|
614 gripe_wrong_type_arg ("octave_base_value::uint64_scalar_value()", |
|
615 type_name ()); |
|
616 return retval; |
|
617 } |
|
618 |
4906
|
619 int8NDArray |
|
620 octave_base_value::int8_array_value (void) const |
|
621 { |
|
622 int8NDArray retval; |
|
623 gripe_wrong_type_arg ("octave_base_value::int8_array_value()", |
|
624 type_name ()); |
4910
|
625 return retval; |
4906
|
626 } |
|
627 |
|
628 int16NDArray |
|
629 octave_base_value::int16_array_value (void) const |
|
630 { |
|
631 int16NDArray retval; |
|
632 gripe_wrong_type_arg ("octave_base_value::int16_array_value()", |
|
633 type_name ()); |
4910
|
634 return retval; |
4906
|
635 } |
|
636 |
|
637 int32NDArray |
|
638 octave_base_value::int32_array_value (void) const |
|
639 { |
|
640 int32NDArray retval; |
|
641 gripe_wrong_type_arg ("octave_base_value::int32_array_value()", |
|
642 type_name ()); |
4910
|
643 return retval; |
4906
|
644 } |
|
645 |
|
646 int64NDArray |
|
647 octave_base_value::int64_array_value (void) const |
|
648 { |
|
649 int64NDArray retval; |
|
650 gripe_wrong_type_arg ("octave_base_value::int64_array_value()", |
|
651 type_name ()); |
4910
|
652 return retval; |
4906
|
653 } |
|
654 |
|
655 uint8NDArray |
|
656 octave_base_value::uint8_array_value (void) const |
|
657 { |
|
658 uint8NDArray retval; |
|
659 gripe_wrong_type_arg ("octave_base_value::uint8_array_value()", |
|
660 type_name ()); |
4910
|
661 return retval; |
4906
|
662 } |
|
663 |
|
664 uint16NDArray |
|
665 octave_base_value::uint16_array_value (void) const |
|
666 { |
|
667 uint16NDArray retval; |
|
668 gripe_wrong_type_arg ("octave_base_value::uint16_array_value()", |
|
669 type_name ()); |
4910
|
670 return retval; |
4906
|
671 } |
|
672 |
|
673 uint32NDArray |
|
674 octave_base_value::uint32_array_value (void) const |
|
675 { |
|
676 uint32NDArray retval; |
|
677 gripe_wrong_type_arg ("octave_base_value::uint32_array_value()", |
|
678 type_name ()); |
4910
|
679 return retval; |
4906
|
680 } |
|
681 |
|
682 uint64NDArray |
|
683 octave_base_value::uint64_array_value (void) const |
|
684 { |
|
685 uint64NDArray retval; |
|
686 gripe_wrong_type_arg ("octave_base_value::uint64_array_value()", |
|
687 type_name ()); |
4910
|
688 return retval; |
4906
|
689 } |
|
690 |
2493
|
691 string_vector |
5715
|
692 octave_base_value::all_strings (bool pad) const |
2376
|
693 { |
2493
|
694 string_vector retval; |
4257
|
695 |
5715
|
696 octave_value tmp = convert_to_str (pad, true); |
4257
|
697 |
4452
|
698 if (! error_state) |
|
699 retval = tmp.all_strings (); |
4257
|
700 |
2376
|
701 return retval; |
|
702 } |
|
703 |
3536
|
704 std::string |
4457
|
705 octave_base_value::string_value (bool force) const |
2376
|
706 { |
3523
|
707 std::string retval; |
4257
|
708 |
4457
|
709 octave_value tmp = convert_to_str (force); |
4257
|
710 |
4452
|
711 if (! error_state) |
|
712 retval = tmp.string_value (); |
4257
|
713 |
2376
|
714 return retval; |
|
715 } |
|
716 |
|
717 Range |
|
718 octave_base_value::range_value (void) const |
|
719 { |
|
720 Range retval; |
|
721 gripe_wrong_type_arg ("octave_base_value::range_value()", type_name ()); |
|
722 return retval; |
|
723 } |
|
724 |
|
725 Octave_map |
|
726 octave_base_value::map_value (void) const |
|
727 { |
|
728 Octave_map retval; |
|
729 gripe_wrong_type_arg ("octave_base_value::map_value()", type_name ()); |
|
730 return retval; |
|
731 } |
|
732 |
3933
|
733 string_vector |
|
734 octave_base_value::map_keys (void) const |
|
735 { |
|
736 string_vector retval; |
|
737 gripe_wrong_type_arg ("octave_base_value::map_keys()", type_name ()); |
|
738 return retval; |
|
739 } |
|
740 |
4645
|
741 std::streamoff |
4643
|
742 octave_base_value::streamoff_value (void) const |
|
743 { |
4649
|
744 std::streamoff retval (-1); |
4645
|
745 gripe_wrong_type_arg ("octave_base_value::streamoff_value()", type_name ()); |
|
746 return retval; |
|
747 } |
|
748 |
|
749 streamoff_array |
|
750 octave_base_value::streamoff_array_value (void) const |
|
751 { |
4643
|
752 streamoff_array retval; |
4645
|
753 gripe_wrong_type_arg ("octave_base_value::streamoff_array_value()", |
|
754 type_name ()); |
4643
|
755 return retval; |
|
756 } |
|
757 |
2974
|
758 octave_function * |
|
759 octave_base_value::function_value (bool silent) |
|
760 { |
|
761 octave_function *retval = 0; |
|
762 |
|
763 if (! silent) |
|
764 gripe_wrong_type_arg ("octave_base_value::function_value()", |
|
765 type_name ()); |
|
766 return retval; |
|
767 } |
|
768 |
4700
|
769 octave_user_function * |
|
770 octave_base_value::user_function_value (bool silent) |
|
771 { |
|
772 octave_user_function *retval = 0; |
|
773 |
|
774 if (! silent) |
|
775 gripe_wrong_type_arg ("octave_base_value::user_function_value()", |
|
776 type_name ()); |
|
777 return retval; |
|
778 } |
|
779 |
4346
|
780 octave_fcn_handle * |
4343
|
781 octave_base_value::fcn_handle_value (bool silent) |
|
782 { |
4346
|
783 octave_fcn_handle *retval = 0; |
4343
|
784 |
|
785 if (! silent) |
|
786 gripe_wrong_type_arg ("octave_base_value::fcn_handle_value()", |
|
787 type_name ()); |
|
788 return retval; |
|
789 } |
|
790 |
4933
|
791 octave_fcn_inline * |
|
792 octave_base_value::fcn_inline_value (bool silent) |
|
793 { |
|
794 octave_fcn_inline *retval = 0; |
|
795 |
|
796 if (! silent) |
|
797 gripe_wrong_type_arg ("octave_base_value::fcn_inline_value()", |
|
798 type_name ()); |
|
799 return retval; |
|
800 } |
|
801 |
2882
|
802 octave_value_list |
|
803 octave_base_value::list_value (void) const |
|
804 { |
|
805 octave_value_list retval; |
|
806 gripe_wrong_type_arg ("octave_base_value::list_value()", type_name ()); |
|
807 return retval; |
|
808 } |
|
809 |
4687
|
810 bool |
|
811 octave_base_value::save_ascii (std::ostream&, bool&, bool) |
|
812 { |
|
813 gripe_wrong_type_arg ("octave_base_value::save_ascii()", type_name ()); |
|
814 return false; |
|
815 } |
|
816 |
|
817 bool |
|
818 octave_base_value::load_ascii (std::istream&) |
|
819 { |
|
820 gripe_wrong_type_arg ("octave_base_value::load_ascii()", type_name ()); |
|
821 return false; |
|
822 } |
|
823 |
|
824 bool |
|
825 octave_base_value::save_binary (std::ostream&, bool&) |
|
826 { |
|
827 gripe_wrong_type_arg ("octave_base_value::save_binary()", type_name ()); |
|
828 return false; |
|
829 } |
|
830 |
|
831 bool |
|
832 octave_base_value::load_binary (std::istream&, bool, |
|
833 oct_mach_info::float_format) |
|
834 { |
|
835 gripe_wrong_type_arg ("octave_base_value::load_binary()", type_name ()); |
|
836 return false; |
|
837 } |
|
838 |
|
839 #if defined (HAVE_HDF5) |
4944
|
840 |
4687
|
841 bool |
|
842 octave_base_value::save_hdf5 (hid_t, const char *, bool) |
|
843 { |
|
844 gripe_wrong_type_arg ("octave_base_value::save_binary()", type_name ()); |
|
845 |
|
846 return false; |
|
847 } |
|
848 |
|
849 bool |
|
850 octave_base_value::load_hdf5 (hid_t, const char *, bool) |
|
851 { |
|
852 gripe_wrong_type_arg ("octave_base_value::load_binary()", type_name ()); |
|
853 |
|
854 return false; |
|
855 } |
4944
|
856 |
4687
|
857 #endif |
|
858 |
4944
|
859 int |
|
860 octave_base_value::write (octave_stream&, int, oct_data_conv::data_type, |
|
861 int, oct_mach_info::float_format) const |
|
862 { |
|
863 gripe_wrong_type_arg ("octave_base_value::write()", type_name ()); |
|
864 |
|
865 return false; |
|
866 } |
|
867 |
5759
|
868 static void |
|
869 gripe_indexed_assignment (const std::string& tn1, const std::string& tn2) |
|
870 { |
|
871 error ("assignment of `%s' to indexed `%s' not implemented", |
|
872 tn2.c_str (), tn1.c_str ()); |
|
873 } |
|
874 |
|
875 static void |
|
876 gripe_assign_conversion_failed (const std::string& tn1, |
|
877 const std::string& tn2) |
|
878 { |
|
879 error ("type conversion for assignment of `%s' to indexed `%s' failed", |
|
880 tn2.c_str (), tn1.c_str ()); |
|
881 } |
|
882 |
|
883 static void |
|
884 gripe_no_conversion (const std::string& on, const std::string& tn1, |
|
885 const std::string& tn2) |
|
886 { |
|
887 error ("operator %s: no conversion for assignment of `%s' to indexed `%s'", |
|
888 on.c_str (), tn2.c_str (), tn1.c_str ()); |
|
889 } |
|
890 |
|
891 octave_value |
|
892 octave_base_value::numeric_assign (const std::string& type, |
|
893 const std::list<octave_value_list>& idx, |
|
894 const octave_value& rhs) |
|
895 { |
|
896 octave_value retval; |
|
897 |
|
898 int t_lhs = type_id (); |
|
899 int t_rhs = rhs.type_id (); |
|
900 |
|
901 octave_value_typeinfo::assign_op_fcn f |
|
902 = octave_value_typeinfo::lookup_assign_op (octave_value::op_asn_eq, |
|
903 t_lhs, t_rhs); |
|
904 |
|
905 bool done = false; |
|
906 |
|
907 if (f) |
|
908 { |
|
909 f (*this, idx.front (), rhs.get_rep ()); |
|
910 |
|
911 done = (! error_state); |
|
912 } |
|
913 |
|
914 if (done) |
|
915 { |
|
916 count++; |
|
917 retval = octave_value (this); |
|
918 } |
|
919 else |
|
920 { |
|
921 int t_result |
|
922 = octave_value_typeinfo::lookup_pref_assign_conv (t_lhs, t_rhs); |
|
923 |
|
924 if (t_result >= 0) |
|
925 { |
|
926 octave_base_value::type_conv_fcn cf |
|
927 = octave_value_typeinfo::lookup_widening_op (t_lhs, t_result); |
|
928 |
|
929 if (cf) |
|
930 { |
|
931 octave_base_value *tmp (cf (*this)); |
|
932 |
|
933 if (tmp) |
|
934 { |
|
935 retval = tmp->subsasgn (type, idx, rhs); |
|
936 |
|
937 done = (! error_state); |
|
938 } |
|
939 else |
|
940 gripe_assign_conversion_failed (type_name (), |
|
941 rhs.type_name ()); |
|
942 } |
|
943 else |
|
944 gripe_indexed_assignment (type_name (), rhs.type_name ()); |
|
945 } |
|
946 |
|
947 if (! (done || error_state)) |
|
948 { |
|
949 octave_value tmp_rhs; |
|
950 |
|
951 octave_base_value::type_conv_fcn cf_rhs |
|
952 = rhs.numeric_conversion_function (); |
|
953 |
|
954 if (cf_rhs) |
|
955 { |
|
956 octave_base_value *tmp = cf_rhs (rhs.get_rep ()); |
|
957 |
|
958 if (tmp) |
|
959 tmp_rhs = octave_value (tmp); |
|
960 else |
|
961 { |
|
962 gripe_assign_conversion_failed (type_name (), |
|
963 rhs.type_name ()); |
|
964 return octave_value (); |
|
965 } |
|
966 } |
|
967 else |
|
968 tmp_rhs = rhs; |
|
969 |
|
970 octave_base_value::type_conv_fcn cf_this |
|
971 = numeric_conversion_function (); |
|
972 |
|
973 octave_base_value *tmp_lhs = this; |
|
974 |
|
975 if (cf_this) |
|
976 { |
|
977 octave_base_value *tmp = cf_this (*this); |
|
978 |
|
979 if (tmp) |
|
980 tmp_lhs = tmp; |
|
981 else |
|
982 { |
|
983 gripe_assign_conversion_failed (type_name (), |
|
984 rhs.type_name ()); |
|
985 return octave_value (); |
|
986 } |
|
987 } |
|
988 |
|
989 if (cf_this || cf_rhs) |
|
990 { |
|
991 retval = tmp_lhs->subsasgn (type, idx, tmp_rhs); |
|
992 |
|
993 done = (! error_state); |
|
994 } |
|
995 else |
|
996 gripe_no_conversion (octave_value::assign_op_as_string (octave_value::op_asn_eq), |
|
997 type_name (), rhs.type_name ()); |
|
998 } |
|
999 } |
|
1000 |
|
1001 // The assignment may have converted to a type that is wider than |
|
1002 // necessary. |
|
1003 |
|
1004 retval.maybe_mutate (); |
|
1005 |
|
1006 return retval; |
|
1007 } |
|
1008 |
|
1009 // Current indentation. |
|
1010 int octave_base_value::curr_print_indent_level = 0; |
|
1011 |
|
1012 // TRUE means we are at the beginning of a line. |
|
1013 bool octave_base_value::beginning_of_line = true; |
|
1014 |
|
1015 // Each print() function should call this before printing anything. |
|
1016 // |
|
1017 // This doesn't need to be fast, but isn't there a better way? |
|
1018 |
|
1019 void |
|
1020 octave_base_value::indent (std::ostream& os) const |
|
1021 { |
|
1022 assert (curr_print_indent_level >= 0); |
|
1023 |
|
1024 if (beginning_of_line) |
|
1025 { |
5775
|
1026 // FIXME -- do we need this? |
5759
|
1027 // os << prefix; |
|
1028 |
|
1029 for (int i = 0; i < curr_print_indent_level; i++) |
|
1030 os << " "; |
|
1031 |
|
1032 beginning_of_line = false; |
|
1033 } |
|
1034 } |
|
1035 |
|
1036 // All print() functions should use this to print new lines. |
|
1037 |
|
1038 void |
|
1039 octave_base_value::newline (std::ostream& os) const |
|
1040 { |
|
1041 os << "\n"; |
|
1042 |
|
1043 beginning_of_line = true; |
|
1044 } |
|
1045 |
|
1046 // For ressetting print state. |
|
1047 |
|
1048 void |
|
1049 octave_base_value::reset (void) const |
|
1050 { |
|
1051 beginning_of_line = true; |
|
1052 curr_print_indent_level = 0; |
|
1053 } |
|
1054 |
3203
|
1055 CONVDECLX (matrix_conv) |
2376
|
1056 { |
|
1057 return new octave_matrix (); |
|
1058 } |
|
1059 |
3203
|
1060 CONVDECLX (complex_matrix_conv) |
2376
|
1061 { |
|
1062 return new octave_complex_matrix (); |
|
1063 } |
|
1064 |
3203
|
1065 CONVDECLX (string_conv) |
2376
|
1066 { |
|
1067 return new octave_char_matrix_str (); |
|
1068 } |
|
1069 |
3928
|
1070 CONVDECLX (cell_conv) |
|
1071 { |
|
1072 return new octave_cell (); |
|
1073 } |
|
1074 |
2376
|
1075 void |
|
1076 install_base_type_conversions (void) |
|
1077 { |
|
1078 INSTALL_ASSIGNCONV (octave_base_value, octave_scalar, octave_matrix); |
|
1079 INSTALL_ASSIGNCONV (octave_base_value, octave_matrix, octave_matrix); |
|
1080 INSTALL_ASSIGNCONV (octave_base_value, octave_complex, octave_complex_matrix); |
|
1081 INSTALL_ASSIGNCONV (octave_base_value, octave_complex_matrix, octave_complex_matrix); |
|
1082 INSTALL_ASSIGNCONV (octave_base_value, octave_range, octave_matrix); |
|
1083 INSTALL_ASSIGNCONV (octave_base_value, octave_char_matrix_str, octave_char_matrix_str); |
3928
|
1084 INSTALL_ASSIGNCONV (octave_base_value, octave_cell, octave_cell); |
2376
|
1085 |
|
1086 INSTALL_WIDENOP (octave_base_value, octave_matrix, matrix_conv); |
|
1087 INSTALL_WIDENOP (octave_base_value, octave_complex_matrix, complex_matrix_conv); |
|
1088 INSTALL_WIDENOP (octave_base_value, octave_char_matrix_str, string_conv); |
3928
|
1089 INSTALL_WIDENOP (octave_base_value, octave_cell, cell_conv); |
2376
|
1090 } |
|
1091 |
5759
|
1092 static int |
|
1093 print_answer_id_name (void) |
|
1094 { |
|
1095 Vprint_answer_id_name = check_preference ("print_answer_id_name"); |
|
1096 |
|
1097 return 0; |
|
1098 } |
|
1099 |
|
1100 static int |
|
1101 silent_functions (void) |
|
1102 { |
|
1103 Vsilent_functions = check_preference ("silent_functions"); |
|
1104 |
|
1105 return 0; |
|
1106 } |
|
1107 |
|
1108 static int |
|
1109 warn_num_to_str (void) |
|
1110 { |
|
1111 Vwarn_num_to_str = check_preference ("warn_num_to_str"); |
|
1112 |
|
1113 return 0; |
|
1114 } |
|
1115 |
|
1116 static int |
|
1117 warn_resize_on_range_error (void) |
|
1118 { |
|
1119 Vwarn_resize_on_range_error |
|
1120 = check_preference ("warn_resize_on_range_error"); |
|
1121 |
|
1122 liboctave_wrore_flag = Vwarn_resize_on_range_error; |
|
1123 |
|
1124 return 0; |
|
1125 } |
|
1126 |
|
1127 void |
|
1128 symbols_of_ov_base (void) |
|
1129 { |
|
1130 DEFVAR (print_answer_id_name, true, print_answer_id_name, |
|
1131 "-*- texinfo -*-\n\ |
|
1132 @defvr {Built-in Variable} print_answer_id_name\n\ |
|
1133 If the value of @code{print_answer_id_name} is nonzero, variable\n\ |
|
1134 names are printed along with the result. Otherwise, only the result\n\ |
|
1135 values are printed. The default value is 1.\n\ |
|
1136 @end defvr"); |
|
1137 |
|
1138 DEFVAR (silent_functions, false, silent_functions, |
|
1139 "-*- texinfo -*-\n\ |
|
1140 @defvr {Built-in Variable} silent_functions\n\ |
|
1141 If the value of @code{silent_functions} is nonzero, internal output\n\ |
|
1142 from a function is suppressed. Otherwise, the results of expressions\n\ |
|
1143 within a function body that are not terminated with a semicolon will\n\ |
|
1144 have their values printed. The default value is 0.\n\ |
|
1145 \n\ |
|
1146 For example, if the function\n\ |
|
1147 \n\ |
|
1148 @example\n\ |
|
1149 function f ()\n\ |
|
1150 2 + 2\n\ |
|
1151 endfunction\n\ |
|
1152 @end example\n\ |
|
1153 \n\ |
|
1154 @noindent\n\ |
|
1155 is executed, Octave will either print @samp{ans = 4} or nothing\n\ |
|
1156 depending on the value of @code{silent_functions}.\n\ |
|
1157 @end defvr"); |
|
1158 |
|
1159 DEFVAR (warn_num_to_str, true, warn_num_to_str, |
|
1160 "-*- texinfo -*-\n\ |
|
1161 @defvr {Built-in Variable} warn_num_to_str\n\ |
|
1162 If the value of @code{warn_num_to_str} is nonzero, a warning is\n\ |
|
1163 printed for implicit conversions of numbers to their ASCII character\n\ |
|
1164 equivalents when strings are constructed using a mixture of strings and\n\ |
|
1165 numbers in matrix notation. For example,\n\ |
|
1166 \n\ |
|
1167 @example\n\ |
|
1168 @group\n\ |
|
1169 [ \"f\", 111, 111 ]\n\ |
|
1170 @result{} \"foo\"\n\ |
|
1171 @end group\n\ |
|
1172 @end example\n\ |
|
1173 elicits a warning if @code{warn_num_to_str} is nonzero. The default\n\ |
|
1174 value is 1.\n\ |
|
1175 @end defvr"); |
|
1176 |
|
1177 DEFVAR (warn_resize_on_range_error, false, warn_resize_on_range_error, |
|
1178 "-*- texinfo -*-\n\ |
|
1179 @defvr {Built-in Variable} warn_resize_on_range_error\n\ |
|
1180 If the value of @code{warn_resize_on_range_error} is nonzero, print a\n\ |
|
1181 warning when a matrix is resized by an indexed assignment with\n\ |
|
1182 indices outside the current bounds. The default value is 0.\n\ |
|
1183 @end defvr"); |
|
1184 } |
|
1185 |
2376
|
1186 /* |
|
1187 ;;; Local Variables: *** |
|
1188 ;;; mode: C++ *** |
|
1189 ;;; End: *** |
|
1190 */ |