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