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