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 |
5885
|
95 octave_base_value::do_index_op (const octave_value_list&, bool) |
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 |
|
102 octave_value_list |
3544
|
103 octave_base_value::do_multi_index_op (int, const octave_value_list&) |
2376
|
104 { |
3523
|
105 std::string nm = type_name (); |
2376
|
106 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
107 return octave_value (); |
|
108 } |
|
109 |
|
110 idx_vector |
|
111 octave_base_value::index_vector (void) const |
|
112 { |
3523
|
113 std::string nm = type_name (); |
2376
|
114 error ("%s type invalid as index value", nm.c_str ()); |
|
115 return idx_vector (); |
|
116 } |
|
117 |
5759
|
118 int |
|
119 octave_base_value::ndims (void) const |
|
120 { |
|
121 dim_vector dv = dims (); |
|
122 |
|
123 int n_dims = dv.length (); |
|
124 |
|
125 // Remove trailing singleton dimensions. |
|
126 |
|
127 for (int i = n_dims; i > 2; i--) |
|
128 { |
|
129 if (dv(i-1) == 1) |
|
130 n_dims--; |
|
131 else |
|
132 break; |
|
133 } |
|
134 |
|
135 // The result is always >= 2. |
|
136 |
|
137 if (n_dims < 2) |
|
138 n_dims = 2; |
|
139 |
|
140 return n_dims; |
|
141 } |
|
142 |
2376
|
143 octave_value |
4247
|
144 octave_base_value::subsasgn (const std::string& type, |
4219
|
145 const std::list<octave_value_list>& idx, |
3933
|
146 const octave_value& rhs) |
2376
|
147 { |
3933
|
148 octave_value retval; |
2376
|
149 |
3933
|
150 if (is_defined ()) |
|
151 { |
4139
|
152 if (is_numeric_type ()) |
|
153 { |
|
154 switch (type[0]) |
|
155 { |
|
156 case '(': |
|
157 { |
|
158 if (type.length () == 1) |
|
159 retval = numeric_assign (type, idx, rhs); |
4436
|
160 else if (is_empty ()) |
|
161 { |
|
162 // Allow conversion of empty matrix to some other |
|
163 // type in cases like |
|
164 // |
|
165 // x = []; x(i).f = rhs |
|
166 |
|
167 octave_value tmp = octave_value::empty_conv (type, rhs); |
|
168 |
|
169 retval = tmp.subsasgn (type, idx, rhs); |
|
170 } |
4139
|
171 else |
|
172 { |
|
173 std::string nm = type_name (); |
|
174 error ("in indexed assignment of %s, last rhs index must be ()", |
|
175 nm.c_str ()); |
|
176 } |
|
177 } |
|
178 break; |
|
179 |
|
180 case '{': |
|
181 case '.': |
|
182 { |
|
183 std::string nm = type_name (); |
|
184 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
185 } |
|
186 break; |
|
187 |
|
188 default: |
|
189 panic_impossible (); |
|
190 } |
|
191 } |
|
192 else |
|
193 { |
|
194 std::string nm = type_name (); |
|
195 error ("can't perform indexed assignment for %s type", nm.c_str ()); |
|
196 } |
3933
|
197 } |
|
198 else |
|
199 { |
|
200 // Create new object of appropriate type for given index and rhs |
|
201 // types and then call subsasgn again for that object. |
|
202 |
|
203 octave_value tmp = octave_value::empty_conv (type, rhs); |
|
204 |
|
205 retval = tmp.subsasgn (type, idx, rhs); |
|
206 } |
|
207 |
|
208 return retval; |
2376
|
209 } |
|
210 |
5602
|
211 octave_idx_type |
|
212 octave_base_value::nnz (void) const |
|
213 { |
|
214 gripe_wrong_type_arg ("octave_base_value::nnz ()", type_name ()); |
|
215 return -1; |
|
216 } |
|
217 |
5604
|
218 octave_idx_type |
|
219 octave_base_value::nzmax (void) const |
|
220 { |
|
221 gripe_wrong_type_arg ("octave_base_value::nzmax ()", type_name ()); |
|
222 return -1; |
|
223 } |
|
224 |
2376
|
225 octave_value |
4567
|
226 octave_base_value::reshape (const dim_vector&) const |
|
227 { |
|
228 gripe_wrong_type_arg ("octave_base_value::reshape ()", type_name ()); |
|
229 return octave_value (); |
|
230 } |
|
231 |
|
232 octave_value |
4593
|
233 octave_base_value::permute (const Array<int>&, bool) const |
|
234 { |
|
235 gripe_wrong_type_arg ("octave_base_value::permute ()", type_name ()); |
|
236 return octave_value (); |
|
237 } |
|
238 |
|
239 octave_value |
5731
|
240 octave_base_value::resize (const dim_vector&, bool) const |
4915
|
241 { |
|
242 gripe_wrong_type_arg ("octave_base_value::resize ()", type_name ()); |
|
243 return octave_value (); |
|
244 } |
|
245 |
5785
|
246 MatrixType |
|
247 octave_base_value::matrix_type (void) const |
|
248 { |
|
249 gripe_wrong_type_arg ("octave_base_value::matrix_type ()", type_name ()); |
|
250 return MatrixType (); |
|
251 } |
|
252 |
|
253 MatrixType |
|
254 octave_base_value::matrix_type (const MatrixType&) const |
|
255 { |
|
256 gripe_wrong_type_arg ("octave_base_value::matrix_type ()", type_name ()); |
|
257 return MatrixType (); |
|
258 } |
|
259 |
4915
|
260 octave_value |
5759
|
261 octave_base_value::all (int) const |
|
262 { |
|
263 return 0.0; |
|
264 } |
|
265 |
|
266 octave_value |
|
267 octave_base_value::any (int) const |
|
268 { |
|
269 return 0.0; |
|
270 } |
|
271 |
|
272 octave_value |
|
273 octave_base_value::convert_to_str (bool pad, bool force, char type) const |
|
274 { |
|
275 octave_value retval = convert_to_str_internal (pad, force, type); |
|
276 |
5781
|
277 if (! force && is_numeric_type ()) |
|
278 gripe_implicit_conversion ("Octave:num-to-str", |
|
279 type_name (), retval.type_name ()); |
5759
|
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 { |
5874
|
931 octave_base_value *tmp = cf (*this); |
5759
|
932 |
|
933 if (tmp) |
|
934 { |
5874
|
935 octave_value val (tmp); |
|
936 |
|
937 retval = val.subsasgn (type, idx, rhs); |
5759
|
938 |
|
939 done = (! error_state); |
|
940 } |
|
941 else |
|
942 gripe_assign_conversion_failed (type_name (), |
|
943 rhs.type_name ()); |
|
944 } |
|
945 else |
|
946 gripe_indexed_assignment (type_name (), rhs.type_name ()); |
|
947 } |
|
948 |
|
949 if (! (done || error_state)) |
|
950 { |
|
951 octave_value tmp_rhs; |
|
952 |
|
953 octave_base_value::type_conv_fcn cf_rhs |
|
954 = rhs.numeric_conversion_function (); |
|
955 |
|
956 if (cf_rhs) |
|
957 { |
|
958 octave_base_value *tmp = cf_rhs (rhs.get_rep ()); |
|
959 |
|
960 if (tmp) |
|
961 tmp_rhs = octave_value (tmp); |
|
962 else |
|
963 { |
|
964 gripe_assign_conversion_failed (type_name (), |
|
965 rhs.type_name ()); |
|
966 return octave_value (); |
|
967 } |
|
968 } |
|
969 else |
|
970 tmp_rhs = rhs; |
|
971 |
|
972 octave_base_value::type_conv_fcn cf_this |
|
973 = numeric_conversion_function (); |
|
974 |
|
975 octave_base_value *tmp_lhs = this; |
|
976 |
|
977 if (cf_this) |
|
978 { |
|
979 octave_base_value *tmp = cf_this (*this); |
|
980 |
|
981 if (tmp) |
|
982 tmp_lhs = tmp; |
|
983 else |
|
984 { |
|
985 gripe_assign_conversion_failed (type_name (), |
|
986 rhs.type_name ()); |
|
987 return octave_value (); |
|
988 } |
|
989 } |
|
990 |
|
991 if (cf_this || cf_rhs) |
|
992 { |
|
993 retval = tmp_lhs->subsasgn (type, idx, tmp_rhs); |
|
994 |
|
995 done = (! error_state); |
|
996 } |
|
997 else |
|
998 gripe_no_conversion (octave_value::assign_op_as_string (octave_value::op_asn_eq), |
|
999 type_name (), rhs.type_name ()); |
|
1000 } |
|
1001 } |
|
1002 |
|
1003 // The assignment may have converted to a type that is wider than |
|
1004 // necessary. |
|
1005 |
|
1006 retval.maybe_mutate (); |
|
1007 |
|
1008 return retval; |
|
1009 } |
|
1010 |
|
1011 // Current indentation. |
|
1012 int octave_base_value::curr_print_indent_level = 0; |
|
1013 |
|
1014 // TRUE means we are at the beginning of a line. |
|
1015 bool octave_base_value::beginning_of_line = true; |
|
1016 |
|
1017 // Each print() function should call this before printing anything. |
|
1018 // |
|
1019 // This doesn't need to be fast, but isn't there a better way? |
|
1020 |
|
1021 void |
|
1022 octave_base_value::indent (std::ostream& os) const |
|
1023 { |
|
1024 assert (curr_print_indent_level >= 0); |
|
1025 |
|
1026 if (beginning_of_line) |
|
1027 { |
5775
|
1028 // FIXME -- do we need this? |
5759
|
1029 // os << prefix; |
|
1030 |
|
1031 for (int i = 0; i < curr_print_indent_level; i++) |
|
1032 os << " "; |
|
1033 |
|
1034 beginning_of_line = false; |
|
1035 } |
|
1036 } |
|
1037 |
|
1038 // All print() functions should use this to print new lines. |
|
1039 |
|
1040 void |
|
1041 octave_base_value::newline (std::ostream& os) const |
|
1042 { |
|
1043 os << "\n"; |
|
1044 |
|
1045 beginning_of_line = true; |
|
1046 } |
|
1047 |
|
1048 // For ressetting print state. |
|
1049 |
|
1050 void |
|
1051 octave_base_value::reset (void) const |
|
1052 { |
|
1053 beginning_of_line = true; |
|
1054 curr_print_indent_level = 0; |
|
1055 } |
|
1056 |
3203
|
1057 CONVDECLX (matrix_conv) |
2376
|
1058 { |
|
1059 return new octave_matrix (); |
|
1060 } |
|
1061 |
3203
|
1062 CONVDECLX (complex_matrix_conv) |
2376
|
1063 { |
|
1064 return new octave_complex_matrix (); |
|
1065 } |
|
1066 |
3203
|
1067 CONVDECLX (string_conv) |
2376
|
1068 { |
|
1069 return new octave_char_matrix_str (); |
|
1070 } |
|
1071 |
3928
|
1072 CONVDECLX (cell_conv) |
|
1073 { |
|
1074 return new octave_cell (); |
|
1075 } |
|
1076 |
2376
|
1077 void |
|
1078 install_base_type_conversions (void) |
|
1079 { |
|
1080 INSTALL_ASSIGNCONV (octave_base_value, octave_scalar, octave_matrix); |
|
1081 INSTALL_ASSIGNCONV (octave_base_value, octave_matrix, octave_matrix); |
|
1082 INSTALL_ASSIGNCONV (octave_base_value, octave_complex, octave_complex_matrix); |
|
1083 INSTALL_ASSIGNCONV (octave_base_value, octave_complex_matrix, octave_complex_matrix); |
|
1084 INSTALL_ASSIGNCONV (octave_base_value, octave_range, octave_matrix); |
|
1085 INSTALL_ASSIGNCONV (octave_base_value, octave_char_matrix_str, octave_char_matrix_str); |
3928
|
1086 INSTALL_ASSIGNCONV (octave_base_value, octave_cell, octave_cell); |
2376
|
1087 |
|
1088 INSTALL_WIDENOP (octave_base_value, octave_matrix, matrix_conv); |
|
1089 INSTALL_WIDENOP (octave_base_value, octave_complex_matrix, complex_matrix_conv); |
|
1090 INSTALL_WIDENOP (octave_base_value, octave_char_matrix_str, string_conv); |
3928
|
1091 INSTALL_WIDENOP (octave_base_value, octave_cell, cell_conv); |
2376
|
1092 } |
|
1093 |
5794
|
1094 DEFUN (print_answer_id_name, args, nargout, |
|
1095 "-*- texinfo -*-\n\ |
|
1096 @deftypefn {Built-in Function} {@var{val} =} print_answer_id_name ()\n\ |
|
1097 @deftypefnx {Built-in Function} {@var{old_val} =} print_answer_id_name (@var{new_val})\n\ |
|
1098 Query or set the internal variable that controls whether variable\n\ |
|
1099 names are printed along with results produced by evaluating an expression.\n\ |
|
1100 @end deftypefn") |
5759
|
1101 { |
5794
|
1102 return SET_INTERNAL_VARIABLE (print_answer_id_name); |
5759
|
1103 } |
|
1104 |
5794
|
1105 DEFUN (silent_functions, args, nargout, |
|
1106 "-*- texinfo -*-\n\ |
|
1107 @deftypefn {Built-in Function} {@var{val} =} silent_functions ()\n\ |
|
1108 @deftypefnx {Built-in Function} {@var{old_val} =} silent_functions (@var{new_val})\n\ |
|
1109 Query or set the internal variable that controls whether internal\n\ |
|
1110 output from a function is suppressed. If this option is disabled,\n\ |
|
1111 Octave will display the results produced by evaluating expressions\n\ |
|
1112 within a function body that are not terminated with a semicolon.\n\ |
|
1113 @end deftypefn") |
5759
|
1114 { |
5794
|
1115 return SET_INTERNAL_VARIABLE (silent_functions); |
5759
|
1116 } |
|
1117 |
2376
|
1118 /* |
|
1119 ;;; Local Variables: *** |
|
1120 ;;; mode: C++ *** |
|
1121 ;;; End: *** |
|
1122 */ |