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