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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include "Array-flags.h" |
4970
|
28 #include "data-conv.h" |
|
29 #include "quit.h" |
2942
|
30 #include "str-vec.h" |
2376
|
31 |
2974
|
32 #include "oct-obj.h" |
4944
|
33 #include "oct-stream.h" |
2376
|
34 #include "ov.h" |
|
35 #include "ov-base.h" |
2825
|
36 #include "ov-bool.h" |
|
37 #include "ov-bool-mat.h" |
3351
|
38 #include "ov-cell.h" |
2376
|
39 #include "ov-scalar.h" |
|
40 #include "ov-re-mat.h" |
4901
|
41 #include "ov-int8.h" |
|
42 #include "ov-int16.h" |
|
43 #include "ov-int32.h" |
|
44 #include "ov-int64.h" |
|
45 #include "ov-uint8.h" |
|
46 #include "ov-uint16.h" |
|
47 #include "ov-uint32.h" |
|
48 #include "ov-uint64.h" |
2376
|
49 #include "ov-complex.h" |
|
50 #include "ov-cx-mat.h" |
|
51 #include "ov-ch-mat.h" |
|
52 #include "ov-str-mat.h" |
|
53 #include "ov-range.h" |
|
54 #include "ov-struct.h" |
2903
|
55 #include "ov-file.h" |
4643
|
56 #include "ov-streamoff.h" |
2880
|
57 #include "ov-list.h" |
3977
|
58 #include "ov-cs-list.h" |
2376
|
59 #include "ov-colon.h" |
|
60 #include "ov-va-args.h" |
2974
|
61 #include "ov-builtin.h" |
|
62 #include "ov-mapper.h" |
4649
|
63 #include "ov-dld-fcn.h" |
2974
|
64 #include "ov-usr-fcn.h" |
4342
|
65 #include "ov-fcn-handle.h" |
4966
|
66 #include "ov-fcn-inline.h" |
2376
|
67 #include "ov-typeinfo.h" |
|
68 |
|
69 #include "defun.h" |
2880
|
70 #include "error.h" |
2376
|
71 #include "gripes.h" |
|
72 #include "pager.h" |
4005
|
73 #include "parse.h" |
2376
|
74 #include "pr-output.h" |
|
75 #include "utils.h" |
|
76 #include "variables.h" |
|
77 |
2477
|
78 // We are likely to have a lot of octave_value objects to allocate, so |
|
79 // make the grow_size large. |
3219
|
80 DEFINE_OCTAVE_ALLOCATOR2(octave_value, 1024); |
2477
|
81 |
4005
|
82 // If TRUE, turn off printing of results in functions (as if a |
|
83 // semicolon has been appended to each statement). |
|
84 static bool Vsilent_functions; |
|
85 |
4455
|
86 // If TRUE, print a warning for assignments like |
2376
|
87 // |
|
88 // octave> A(1) = 3; A(2) = 5 |
|
89 // |
|
90 // for A already defined and a matrix type. |
4455
|
91 bool Vwarn_fortran_indexing; |
2376
|
92 |
4452
|
93 // Should we warn about conversions from complex to real? |
|
94 int Vwarn_imag_to_real; |
4257
|
95 |
4452
|
96 // Should we print a warning when converting `[97, 98, 99, "123"]' |
|
97 // to a character string? |
|
98 bool Vwarn_num_to_str; |
|
99 |
|
100 // If TRUE, warn for operations like |
2376
|
101 // |
|
102 // octave> 'abc' + 0 |
|
103 // 97 98 99 |
|
104 // |
4452
|
105 int Vwarn_str_to_num; |
2376
|
106 |
|
107 // If TRUE, print the name along with the value. |
|
108 bool Vprint_answer_id_name; |
|
109 |
|
110 // How many levels of structure elements should we print? |
|
111 int Vstruct_levels_to_print; |
|
112 |
|
113 // Allow divide by zero errors to be suppressed. |
|
114 bool Vwarn_divide_by_zero; |
|
115 |
4461
|
116 // If TRUE, print a warning when a matrix is resized by an indexed |
|
117 // assignment with indices outside the current bounds. |
|
118 bool Vwarn_resize_on_range_error; |
2948
|
119 |
2880
|
120 // XXX FIXME XXX |
|
121 |
2376
|
122 // Octave's value type. |
|
123 |
3536
|
124 std::string |
3203
|
125 octave_value::unary_op_as_string (unary_op op) |
|
126 { |
3523
|
127 std::string retval; |
3203
|
128 |
|
129 switch (op) |
|
130 { |
3533
|
131 case op_not: |
3203
|
132 retval = "!"; |
|
133 break; |
|
134 |
4965
|
135 case op_uplus: |
|
136 retval = "+"; |
|
137 break; |
|
138 |
3533
|
139 case op_uminus: |
3203
|
140 retval = "-"; |
|
141 break; |
|
142 |
3533
|
143 case op_transpose: |
3203
|
144 retval = ".'"; |
|
145 break; |
|
146 |
3533
|
147 case op_hermitian: |
3203
|
148 retval = "'"; |
|
149 break; |
|
150 |
3533
|
151 case op_incr: |
3203
|
152 retval = "++"; |
|
153 break; |
|
154 |
3533
|
155 case op_decr: |
3203
|
156 retval = "--"; |
|
157 break; |
|
158 |
|
159 default: |
|
160 retval = "<unknown>"; |
|
161 } |
|
162 |
|
163 return retval; |
|
164 } |
|
165 |
3536
|
166 std::string |
2376
|
167 octave_value::binary_op_as_string (binary_op op) |
|
168 { |
3523
|
169 std::string retval; |
2376
|
170 |
|
171 switch (op) |
|
172 { |
3533
|
173 case op_add: |
2376
|
174 retval = "+"; |
|
175 break; |
|
176 |
3533
|
177 case op_sub: |
2376
|
178 retval = "-"; |
|
179 break; |
|
180 |
3533
|
181 case op_mul: |
2376
|
182 retval = "*"; |
|
183 break; |
|
184 |
3533
|
185 case op_div: |
2376
|
186 retval = "/"; |
|
187 break; |
|
188 |
3533
|
189 case op_pow: |
2376
|
190 retval = "^"; |
|
191 break; |
|
192 |
3533
|
193 case op_ldiv: |
2376
|
194 retval = "\\"; |
|
195 break; |
|
196 |
3533
|
197 case op_lshift: |
2903
|
198 retval = "<<"; |
|
199 break; |
|
200 |
3533
|
201 case op_rshift: |
2903
|
202 retval = ">>"; |
|
203 break; |
|
204 |
3533
|
205 case op_lt: |
2376
|
206 retval = "<"; |
|
207 break; |
|
208 |
3533
|
209 case op_le: |
2376
|
210 retval = "<="; |
|
211 break; |
|
212 |
3533
|
213 case op_eq: |
2376
|
214 retval = "=="; |
|
215 break; |
|
216 |
3533
|
217 case op_ge: |
2376
|
218 retval = ">="; |
|
219 break; |
|
220 |
3533
|
221 case op_gt: |
2376
|
222 retval = ">"; |
|
223 break; |
|
224 |
3533
|
225 case op_ne: |
2376
|
226 retval = "!="; |
|
227 break; |
|
228 |
3533
|
229 case op_el_mul: |
2376
|
230 retval = ".*"; |
|
231 break; |
|
232 |
3533
|
233 case op_el_div: |
2376
|
234 retval = "./"; |
|
235 break; |
|
236 |
3533
|
237 case op_el_pow: |
2376
|
238 retval = ".^"; |
|
239 break; |
|
240 |
3533
|
241 case op_el_ldiv: |
2376
|
242 retval = ".\\"; |
|
243 break; |
|
244 |
3533
|
245 case op_el_and: |
2376
|
246 retval = "&"; |
|
247 break; |
|
248 |
3533
|
249 case op_el_or: |
2376
|
250 retval = "|"; |
|
251 break; |
|
252 |
3533
|
253 case op_struct_ref: |
2376
|
254 retval = "."; |
|
255 break; |
|
256 |
|
257 default: |
|
258 retval = "<unknown>"; |
|
259 } |
|
260 |
|
261 return retval; |
|
262 } |
|
263 |
3536
|
264 std::string |
2880
|
265 octave_value::assign_op_as_string (assign_op op) |
|
266 { |
3523
|
267 std::string retval; |
2880
|
268 |
|
269 switch (op) |
|
270 { |
3533
|
271 case op_asn_eq: |
2880
|
272 retval = "="; |
|
273 break; |
|
274 |
3533
|
275 case op_add_eq: |
2880
|
276 retval = "+="; |
|
277 break; |
|
278 |
3533
|
279 case op_sub_eq: |
2880
|
280 retval = "-="; |
|
281 break; |
|
282 |
3533
|
283 case op_mul_eq: |
2880
|
284 retval = "*="; |
|
285 break; |
|
286 |
3533
|
287 case op_div_eq: |
2880
|
288 retval = "/="; |
|
289 break; |
|
290 |
3533
|
291 case op_ldiv_eq: |
3204
|
292 retval = "\\="; |
|
293 break; |
|
294 |
4018
|
295 case op_pow_eq: |
|
296 retval = "^="; |
|
297 break; |
|
298 |
3533
|
299 case op_lshift_eq: |
2903
|
300 retval = "<<="; |
|
301 break; |
|
302 |
3533
|
303 case op_rshift_eq: |
2903
|
304 retval = ">>="; |
|
305 break; |
|
306 |
3533
|
307 case op_el_mul_eq: |
2880
|
308 retval = ".*="; |
|
309 break; |
|
310 |
3533
|
311 case op_el_div_eq: |
2880
|
312 retval = "./="; |
|
313 break; |
|
314 |
3533
|
315 case op_el_ldiv_eq: |
3204
|
316 retval = ".\\="; |
|
317 break; |
|
318 |
4018
|
319 case op_el_pow_eq: |
|
320 retval = ".^="; |
|
321 break; |
|
322 |
3533
|
323 case op_el_and_eq: |
2880
|
324 retval = "&="; |
|
325 break; |
|
326 |
3533
|
327 case op_el_or_eq: |
2880
|
328 retval = "|="; |
|
329 break; |
|
330 |
|
331 default: |
|
332 retval = "<unknown>"; |
|
333 } |
|
334 |
|
335 return retval; |
|
336 } |
|
337 |
4513
|
338 octave_value * |
|
339 octave_value::nil_rep (void) const |
|
340 { |
|
341 static octave_base_value *nr = new octave_base_value (); |
|
342 return nr; |
|
343 } |
|
344 |
2376
|
345 octave_value::octave_value (void) |
4513
|
346 : rep (nil_rep ()) |
2825
|
347 { |
4513
|
348 rep->count++; |
2825
|
349 } |
2376
|
350 |
4254
|
351 octave_value::octave_value (short int i) |
|
352 : rep (new octave_scalar (i)) |
|
353 { |
|
354 rep->count = 1; |
|
355 } |
|
356 |
|
357 octave_value::octave_value (unsigned short int i) |
|
358 : rep (new octave_scalar (i)) |
|
359 { |
|
360 rep->count = 1; |
|
361 } |
|
362 |
4233
|
363 octave_value::octave_value (int i) |
|
364 : rep (new octave_scalar (i)) |
|
365 { |
|
366 rep->count = 1; |
|
367 } |
|
368 |
4254
|
369 octave_value::octave_value (unsigned int i) |
|
370 : rep (new octave_scalar (i)) |
|
371 { |
|
372 rep->count = 1; |
|
373 } |
|
374 |
|
375 octave_value::octave_value (long int i) |
|
376 : rep (new octave_scalar (i)) |
|
377 { |
|
378 rep->count = 1; |
|
379 } |
|
380 |
|
381 octave_value::octave_value (unsigned long int i) |
|
382 : rep (new octave_scalar (i)) |
|
383 { |
|
384 rep->count = 1; |
|
385 } |
|
386 |
4353
|
387 #if defined (HAVE_LONG_LONG_INT) |
|
388 octave_value::octave_value (long long int i) |
|
389 : rep (new octave_scalar (i)) |
|
390 { |
|
391 rep->count = 1; |
|
392 } |
|
393 #endif |
|
394 |
4355
|
395 #if defined (HAVE_UNSIGNED_LONG_LONG_INT) |
4353
|
396 octave_value::octave_value (unsigned long long int i) |
|
397 : rep (new octave_scalar (i)) |
|
398 { |
|
399 rep->count = 1; |
|
400 } |
|
401 #endif |
|
402 |
4254
|
403 octave_value::octave_value (octave_time t) |
|
404 : rep (new octave_scalar (t)) |
|
405 { |
|
406 rep->count = 1; |
|
407 } |
|
408 |
2376
|
409 octave_value::octave_value (double d) |
2825
|
410 : rep (new octave_scalar (d)) |
|
411 { |
|
412 rep->count = 1; |
|
413 } |
2376
|
414 |
4587
|
415 octave_value::octave_value (const Cell& c, bool is_csl) |
4513
|
416 : rep (0) |
3351
|
417 { |
4587
|
418 if (is_csl) |
4513
|
419 rep = new octave_cs_list (c); |
|
420 else |
|
421 rep = new octave_cell (c); |
|
422 |
3351
|
423 rep->count = 1; |
|
424 } |
|
425 |
5147
|
426 octave_value::octave_value (const ArrayN<octave_value>& a, bool is_csl) |
|
427 : rep (0) |
|
428 { |
|
429 Cell c (a); |
|
430 |
|
431 if (is_csl) |
|
432 rep = new octave_cs_list (c); |
|
433 else |
|
434 rep = new octave_cell (c); |
|
435 |
|
436 rep->count = 1; |
|
437 } |
|
438 |
2376
|
439 octave_value::octave_value (const Matrix& m) |
2423
|
440 : rep (new octave_matrix (m)) |
|
441 { |
|
442 rep->count = 1; |
|
443 maybe_mutate (); |
|
444 } |
2376
|
445 |
4507
|
446 octave_value::octave_value (const NDArray& a) |
4513
|
447 : rep (new octave_matrix (a)) |
4478
|
448 { |
|
449 rep->count = 1; |
|
450 maybe_mutate (); |
|
451 } |
|
452 |
4911
|
453 octave_value::octave_value (const ArrayN<double>& a) |
|
454 : rep (new octave_matrix (a)) |
|
455 { |
|
456 rep->count = 1; |
|
457 maybe_mutate (); |
|
458 } |
|
459 |
2376
|
460 octave_value::octave_value (const DiagMatrix& d) |
2423
|
461 : rep (new octave_matrix (d)) |
|
462 { |
|
463 rep->count = 1; |
|
464 maybe_mutate (); |
|
465 } |
2376
|
466 |
3418
|
467 octave_value::octave_value (const RowVector& v) |
|
468 : rep (new octave_matrix (v)) |
2423
|
469 { |
|
470 rep->count = 1; |
|
471 maybe_mutate (); |
|
472 } |
2376
|
473 |
3418
|
474 octave_value::octave_value (const ColumnVector& v) |
|
475 : rep (new octave_matrix (v)) |
2423
|
476 { |
|
477 rep->count = 1; |
|
478 maybe_mutate (); |
|
479 } |
2376
|
480 |
|
481 octave_value::octave_value (const Complex& C) |
2423
|
482 : rep (new octave_complex (C)) |
|
483 { |
|
484 rep->count = 1; |
|
485 maybe_mutate (); |
|
486 } |
2376
|
487 |
|
488 octave_value::octave_value (const ComplexMatrix& m) |
2423
|
489 : rep (new octave_complex_matrix (m)) |
|
490 { |
|
491 rep->count = 1; |
|
492 maybe_mutate (); |
|
493 } |
2376
|
494 |
4513
|
495 octave_value::octave_value (const ComplexNDArray& a) |
|
496 : rep (new octave_complex_matrix (a)) |
4478
|
497 { |
|
498 rep->count = 1; |
|
499 maybe_mutate (); |
|
500 } |
|
501 |
4911
|
502 octave_value::octave_value (const ArrayN<Complex>& a) |
|
503 : rep (new octave_complex_matrix (a)) |
|
504 { |
|
505 rep->count = 1; |
|
506 maybe_mutate (); |
|
507 } |
|
508 |
2376
|
509 octave_value::octave_value (const ComplexDiagMatrix& d) |
2423
|
510 : rep (new octave_complex_matrix (d)) |
|
511 { |
|
512 rep->count = 1; |
|
513 maybe_mutate (); |
|
514 } |
2376
|
515 |
3418
|
516 octave_value::octave_value (const ComplexRowVector& v) |
|
517 : rep (new octave_complex_matrix (v)) |
2423
|
518 { |
|
519 rep->count = 1; |
|
520 maybe_mutate (); |
|
521 } |
2376
|
522 |
3418
|
523 octave_value::octave_value (const ComplexColumnVector& v) |
|
524 : rep (new octave_complex_matrix (v)) |
2423
|
525 { |
|
526 rep->count = 1; |
|
527 maybe_mutate (); |
|
528 } |
2376
|
529 |
2825
|
530 octave_value::octave_value (bool b) |
|
531 : rep (new octave_bool (b)) |
|
532 { |
|
533 rep->count = 1; |
|
534 } |
|
535 |
|
536 octave_value::octave_value (const boolMatrix& bm) |
|
537 : rep (new octave_bool_matrix (bm)) |
|
538 { |
|
539 rep->count = 1; |
|
540 maybe_mutate (); |
|
541 } |
|
542 |
4513
|
543 octave_value::octave_value (const boolNDArray& bnda) |
|
544 : rep (new octave_bool_matrix (bnda)) |
|
545 { |
|
546 rep->count = 1; |
|
547 maybe_mutate (); |
|
548 } |
|
549 |
3189
|
550 octave_value::octave_value (char c) |
|
551 : rep (new octave_char_matrix_str (c)) |
|
552 { |
|
553 rep->count = 1; |
|
554 maybe_mutate (); |
|
555 } |
|
556 |
2376
|
557 octave_value::octave_value (const char *s) |
2423
|
558 : rep (new octave_char_matrix_str (s)) |
|
559 { |
|
560 rep->count = 1; |
|
561 maybe_mutate (); |
|
562 } |
2376
|
563 |
3523
|
564 octave_value::octave_value (const std::string& s) |
2423
|
565 : rep (new octave_char_matrix_str (s)) |
|
566 { |
|
567 rep->count = 1; |
|
568 maybe_mutate (); |
|
569 } |
2376
|
570 |
|
571 octave_value::octave_value (const string_vector& s) |
2423
|
572 : rep (new octave_char_matrix_str (s)) |
|
573 { |
|
574 rep->count = 1; |
|
575 maybe_mutate (); |
|
576 } |
2376
|
577 |
4587
|
578 octave_value::octave_value (const charMatrix& chm, bool is_str) |
|
579 : rep (is_str |
4513
|
580 ? new octave_char_matrix_str (chm) |
|
581 : new octave_char_matrix (chm)) |
2409
|
582 { |
4513
|
583 rep->count = 1; |
|
584 maybe_mutate (); |
|
585 } |
2376
|
586 |
4587
|
587 octave_value::octave_value (const charNDArray& chm, bool is_str) |
|
588 : rep (is_str |
4513
|
589 ? new octave_char_matrix_str (chm) |
|
590 : new octave_char_matrix (chm)) |
|
591 { |
2409
|
592 rep->count = 1; |
2423
|
593 maybe_mutate (); |
2409
|
594 } |
2376
|
595 |
4997
|
596 octave_value::octave_value (const ArrayN<char>& chm, bool is_str) |
|
597 : rep (is_str |
|
598 ? new octave_char_matrix_str (chm) |
|
599 : new octave_char_matrix (chm)) |
|
600 { |
|
601 rep->count = 1; |
|
602 maybe_mutate (); |
|
603 } |
|
604 |
4901
|
605 octave_value::octave_value (const octave_int8& i) |
|
606 : rep (new octave_int8_scalar (i)) |
|
607 { |
|
608 rep->count = 1; |
|
609 maybe_mutate (); |
|
610 } |
|
611 |
|
612 octave_value::octave_value (const octave_uint8& i) |
|
613 : rep (new octave_uint8_scalar (i)) |
|
614 { |
|
615 rep->count = 1; |
|
616 maybe_mutate (); |
|
617 } |
|
618 |
|
619 octave_value::octave_value (const octave_int16& i) |
|
620 : rep (new octave_int16_scalar (i)) |
|
621 { |
|
622 rep->count = 1; |
|
623 maybe_mutate (); |
|
624 } |
|
625 |
|
626 octave_value::octave_value (const octave_uint16& i) |
|
627 : rep (new octave_uint16_scalar (i)) |
|
628 { |
|
629 rep->count = 1; |
|
630 maybe_mutate (); |
|
631 } |
|
632 |
|
633 octave_value::octave_value (const octave_int32& i) |
|
634 : rep (new octave_int32_scalar (i)) |
|
635 { |
|
636 rep->count = 1; |
|
637 maybe_mutate (); |
|
638 } |
|
639 |
|
640 octave_value::octave_value (const octave_uint32& i) |
|
641 : rep (new octave_uint32_scalar (i)) |
|
642 { |
|
643 rep->count = 1; |
|
644 maybe_mutate (); |
|
645 } |
|
646 |
|
647 octave_value::octave_value (const octave_int64& i) |
|
648 : rep (new octave_int64_scalar (i)) |
|
649 { |
|
650 rep->count = 1; |
|
651 maybe_mutate (); |
|
652 } |
|
653 |
|
654 octave_value::octave_value (const octave_uint64& i) |
|
655 : rep (new octave_uint64_scalar (i)) |
|
656 { |
|
657 rep->count = 1; |
|
658 maybe_mutate (); |
|
659 } |
|
660 |
|
661 octave_value::octave_value (const int8NDArray& inda) |
|
662 : rep (new octave_int8_matrix (inda)) |
|
663 { |
|
664 rep->count = 1; |
|
665 maybe_mutate (); |
|
666 } |
|
667 |
|
668 octave_value::octave_value (const uint8NDArray& inda) |
|
669 : rep (new octave_uint8_matrix (inda)) |
|
670 { |
|
671 rep->count = 1; |
|
672 maybe_mutate (); |
|
673 } |
|
674 |
|
675 octave_value::octave_value (const int16NDArray& inda) |
|
676 : rep (new octave_int16_matrix (inda)) |
|
677 { |
|
678 rep->count = 1; |
|
679 maybe_mutate (); |
|
680 } |
|
681 |
|
682 octave_value::octave_value (const uint16NDArray& inda) |
|
683 : rep (new octave_uint16_matrix (inda)) |
|
684 { |
|
685 rep->count = 1; |
|
686 maybe_mutate (); |
|
687 } |
|
688 |
|
689 octave_value::octave_value (const int32NDArray& inda) |
|
690 : rep (new octave_int32_matrix (inda)) |
|
691 { |
|
692 rep->count = 1; |
|
693 maybe_mutate (); |
|
694 } |
|
695 |
|
696 octave_value::octave_value (const uint32NDArray& inda) |
|
697 : rep (new octave_uint32_matrix (inda)) |
|
698 { |
|
699 rep->count = 1; |
|
700 maybe_mutate (); |
|
701 } |
|
702 |
|
703 octave_value::octave_value (const int64NDArray& inda) |
|
704 : rep (new octave_int64_matrix (inda)) |
|
705 { |
|
706 rep->count = 1; |
|
707 maybe_mutate (); |
|
708 } |
|
709 |
|
710 octave_value::octave_value (const uint64NDArray& inda) |
|
711 : rep (new octave_uint64_matrix (inda)) |
|
712 { |
|
713 rep->count = 1; |
|
714 maybe_mutate (); |
|
715 } |
|
716 |
2376
|
717 octave_value::octave_value (double base, double limit, double inc) |
2423
|
718 : rep (new octave_range (base, limit, inc)) |
|
719 { |
|
720 rep->count = 1; |
|
721 maybe_mutate (); |
|
722 } |
2376
|
723 |
|
724 octave_value::octave_value (const Range& r) |
2423
|
725 : rep (new octave_range (r)) |
|
726 { |
|
727 rep->count = 1; |
|
728 maybe_mutate (); |
|
729 } |
2376
|
730 |
|
731 octave_value::octave_value (const Octave_map& m) |
2825
|
732 : rep (new octave_struct (m)) |
|
733 { |
|
734 rep->count = 1; |
2880
|
735 } |
|
736 |
3340
|
737 octave_value::octave_value (const octave_stream& s, int n) |
2903
|
738 : rep (new octave_file (s, n)) |
|
739 { |
|
740 rep->count = 1; |
|
741 } |
|
742 |
4643
|
743 octave_value::octave_value (const streamoff_array& off) |
|
744 : rep (new octave_streamoff (off)) |
|
745 { |
|
746 rep->count = 1; |
|
747 } |
|
748 |
4587
|
749 octave_value::octave_value (const octave_value_list& l, bool is_csl) |
4591
|
750 : rep (0) |
2880
|
751 { |
4591
|
752 if (is_csl) |
|
753 rep = new octave_cs_list (l); |
|
754 else |
|
755 rep = new octave_list (l); |
|
756 |
2880
|
757 rep->count = 1; |
|
758 } |
2376
|
759 |
|
760 octave_value::octave_value (octave_value::magic_colon) |
2825
|
761 : rep (new octave_magic_colon ()) |
|
762 { |
|
763 rep->count = 1; |
|
764 } |
2376
|
765 |
|
766 octave_value::octave_value (octave_value::all_va_args) |
2825
|
767 : rep (new octave_all_va_args ()) |
|
768 { |
|
769 rep->count = 1; |
|
770 } |
2376
|
771 |
4276
|
772 octave_value::octave_value (octave_value *new_rep, int cnt) |
2825
|
773 : rep (new_rep) |
|
774 { |
4276
|
775 rep->count = cnt; |
2825
|
776 } |
2376
|
777 |
|
778 octave_value::~octave_value (void) |
|
779 { |
|
780 #if defined (MDEBUG) |
3531
|
781 std::cerr << "~octave_value: rep: " << rep |
|
782 << " rep->count: " << rep->count << "\n"; |
2376
|
783 #endif |
|
784 |
|
785 if (rep && --rep->count == 0) |
|
786 { |
|
787 delete rep; |
|
788 rep = 0; |
|
789 } |
|
790 } |
|
791 |
2880
|
792 octave_value * |
3933
|
793 octave_value::clone (void) const |
2880
|
794 { |
|
795 panic_impossible (); |
3546
|
796 return 0; |
2880
|
797 } |
|
798 |
2409
|
799 void |
|
800 octave_value::maybe_mutate (void) |
|
801 { |
2410
|
802 octave_value *tmp = rep->try_narrowing_conversion (); |
2409
|
803 |
|
804 if (tmp && tmp != rep) |
|
805 { |
|
806 if (--rep->count == 0) |
|
807 delete rep; |
|
808 |
|
809 rep = tmp; |
|
810 rep->count = 1; |
|
811 } |
|
812 } |
|
813 |
4247
|
814 octave_value |
4271
|
815 octave_value::single_subsref (const std::string& type, |
|
816 const octave_value_list& idx) |
4247
|
817 { |
|
818 std::list<octave_value_list> i; |
|
819 |
|
820 i.push_back (idx); |
|
821 |
|
822 return rep->subsref (type, i); |
|
823 } |
|
824 |
2974
|
825 octave_value_list |
4247
|
826 octave_value::subsref (const std::string& type, |
4219
|
827 const std::list<octave_value_list>& idx, int nargout) |
3933
|
828 { |
|
829 if (is_constant ()) |
|
830 return rep->subsref (type, idx); |
|
831 else |
|
832 return rep->subsref (type, idx, nargout); |
|
833 } |
|
834 |
|
835 octave_value |
4247
|
836 octave_value::next_subsref (const std::string& type, |
4219
|
837 const std::list<octave_value_list>& idx, |
4233
|
838 size_t skip) |
3933
|
839 { |
4582
|
840 if (! error_state && idx.size () > skip) |
3933
|
841 { |
4219
|
842 std::list<octave_value_list> new_idx (idx); |
4233
|
843 for (size_t i = 0; i < skip; i++) |
4219
|
844 new_idx.erase (new_idx.begin ()); |
3933
|
845 return subsref (type.substr (skip), new_idx); |
|
846 } |
|
847 else |
|
848 return *this; |
|
849 } |
|
850 |
|
851 octave_value_list |
4994
|
852 octave_value::next_subsref (int nargout, const std::string& type, |
|
853 const std::list<octave_value_list>& idx, |
|
854 size_t skip) |
|
855 { |
|
856 if (! error_state && idx.size () > skip) |
|
857 { |
|
858 std::list<octave_value_list> new_idx (idx); |
|
859 for (size_t i = 0; i < skip; i++) |
|
860 new_idx.erase (new_idx.begin ()); |
|
861 return subsref (type.substr (skip), new_idx, nargout); |
|
862 } |
|
863 else |
|
864 return *this; |
|
865 } |
|
866 |
|
867 octave_value_list |
3544
|
868 octave_value::do_multi_index_op (int nargout, const octave_value_list& idx) |
2974
|
869 { |
3544
|
870 return rep->do_multi_index_op (nargout, idx); |
2974
|
871 } |
|
872 |
2376
|
873 static void |
3933
|
874 gripe_no_conversion (const std::string& on, const std::string& tn1, |
|
875 const std::string& tn2) |
2376
|
876 { |
3203
|
877 error ("operator %s: no conversion for assignment of `%s' to indexed `%s'", |
|
878 on.c_str (), tn2.c_str (), tn1.c_str ()); |
2376
|
879 } |
|
880 |
3933
|
881 #if 0 |
3204
|
882 static void |
3933
|
883 gripe_assign_failed (const std::string& on, const std::string& tn1, |
|
884 const std::string& tn2) |
3204
|
885 { |
|
886 error ("assignment failed for `%s %s %s'", |
|
887 tn1.c_str (), on.c_str (), tn2.c_str ()); |
|
888 } |
3933
|
889 #endif |
3204
|
890 |
|
891 static void |
3933
|
892 gripe_assign_failed_or_no_method (const std::string& on, |
|
893 const std::string& tn1, |
3523
|
894 const std::string& tn2) |
3204
|
895 { |
|
896 error ("assignment failed, or no method for `%s %s %s'", |
|
897 tn1.c_str (), on.c_str (), tn2.c_str ()); |
|
898 } |
|
899 |
3933
|
900 octave_value |
4247
|
901 octave_value::subsasgn (const std::string& type, |
4219
|
902 const std::list<octave_value_list>& idx, |
3933
|
903 const octave_value& rhs) |
|
904 { |
|
905 return rep->subsasgn (type, idx, rhs); |
|
906 } |
|
907 |
|
908 octave_value |
4247
|
909 octave_value::assign (assign_op op, const std::string& type, |
4219
|
910 const std::list<octave_value_list>& idx, |
3933
|
911 const octave_value& rhs) |
|
912 { |
|
913 octave_value retval; |
|
914 |
|
915 make_unique (); |
|
916 |
|
917 octave_value t_rhs = rhs; |
|
918 |
|
919 if (op != op_asn_eq) |
|
920 { |
|
921 // XXX FIXME XXX -- only do the following stuff if we can't find |
|
922 // a specific function to call to handle the op= operation for |
|
923 // the types we have. |
|
924 |
5001
|
925 octave_value t; |
|
926 if (is_constant ()) |
|
927 t = subsref (type, idx); |
|
928 else |
|
929 { |
|
930 octave_value_list tl = subsref (type, idx, 1); |
|
931 if (tl.length () > 0) |
|
932 t = tl(0); |
|
933 } |
3933
|
934 |
|
935 if (! error_state) |
|
936 { |
|
937 binary_op binop = op_eq_to_binary_op (op); |
|
938 |
|
939 if (! error_state) |
|
940 t_rhs = do_binary_op (binop, t, rhs); |
|
941 } |
|
942 } |
|
943 |
|
944 if (! error_state) |
|
945 { |
|
946 if (type[0] == '.' && ! is_map ()) |
|
947 { |
|
948 octave_value tmp = Octave_map (); |
|
949 retval = tmp.subsasgn (type, idx, t_rhs); |
|
950 } |
|
951 else |
|
952 retval = subsasgn (type, idx, t_rhs); |
|
953 } |
|
954 |
|
955 if (error_state) |
|
956 gripe_assign_failed_or_no_method (assign_op_as_string (op), |
|
957 type_name (), rhs.type_name ()); |
|
958 |
|
959 return retval; |
|
960 } |
|
961 |
|
962 const octave_value& |
3203
|
963 octave_value::assign (assign_op op, const octave_value& rhs) |
2880
|
964 { |
3533
|
965 if (op == op_asn_eq) |
3203
|
966 operator = (rhs); |
|
967 else |
|
968 { |
3204
|
969 // XXX FIXME XXX -- only do the following stuff if we can't find |
|
970 // a specific function to call to handle the op= operation for |
|
971 // the types we have. |
|
972 |
|
973 binary_op binop = op_eq_to_binary_op (op); |
|
974 |
|
975 if (! error_state) |
|
976 { |
|
977 octave_value t = do_binary_op (binop, *this, rhs); |
|
978 |
|
979 if (! error_state) |
|
980 operator = (t); |
|
981 } |
|
982 |
|
983 if (error_state) |
|
984 gripe_assign_failed_or_no_method (assign_op_as_string (op), |
|
985 type_name (), rhs.type_name ()); |
|
986 } |
|
987 |
3933
|
988 return *this; |
2376
|
989 } |
|
990 |
4563
|
991 int |
|
992 octave_value::rows (void) const |
|
993 { |
|
994 dim_vector dv = dims (); |
|
995 |
|
996 return (dv.length () > 0) ? dv(0) : -1; |
|
997 } |
|
998 |
|
999 int |
|
1000 octave_value::columns (void) const |
|
1001 { |
|
1002 dim_vector dv = dims (); |
|
1003 |
|
1004 return (dv.length () > 1) ? dv(1) : -1; |
|
1005 } |
|
1006 |
|
1007 int |
|
1008 octave_value::length (void) const |
|
1009 { |
|
1010 int retval = 0; |
|
1011 |
|
1012 dim_vector dv = dims (); |
4584
|
1013 |
4563
|
1014 for (int i = 0; i < dv.length (); i++) |
|
1015 { |
|
1016 if (dv(i) < 0) |
|
1017 { |
|
1018 retval = -1; |
|
1019 break; |
|
1020 } |
|
1021 |
4584
|
1022 if (dv(i) == 0) |
|
1023 { |
|
1024 retval = 0; |
|
1025 break; |
|
1026 } |
|
1027 |
4563
|
1028 if (dv(i) > retval) |
|
1029 retval = dv(i); |
|
1030 } |
|
1031 |
|
1032 return retval; |
|
1033 } |
|
1034 |
|
1035 int |
|
1036 octave_value::ndims (void) const |
|
1037 { |
|
1038 dim_vector dv = dims (); |
|
1039 |
|
1040 int n_dims = dv.length (); |
|
1041 |
|
1042 // Remove trailing singleton dimensions. |
|
1043 |
|
1044 for (int i = n_dims; i > 2; i--) |
|
1045 { |
|
1046 if (dv(i-1) == 1) |
|
1047 n_dims--; |
|
1048 else |
|
1049 break; |
|
1050 } |
|
1051 |
|
1052 // The result is always >= 2. |
|
1053 |
|
1054 if (n_dims < 2) |
|
1055 n_dims = 2; |
|
1056 |
|
1057 return n_dims; |
|
1058 } |
|
1059 |
3351
|
1060 Cell |
|
1061 octave_value::cell_value (void) const |
|
1062 { |
|
1063 return rep->cell_value (); |
|
1064 } |
|
1065 |
2376
|
1066 Octave_map |
|
1067 octave_value::map_value (void) const |
|
1068 { |
|
1069 return rep->map_value (); |
|
1070 } |
|
1071 |
3340
|
1072 octave_stream |
2903
|
1073 octave_value::stream_value (void) const |
|
1074 { |
|
1075 return rep->stream_value (); |
|
1076 } |
|
1077 |
|
1078 int |
|
1079 octave_value::stream_number (void) const |
|
1080 { |
|
1081 return rep->stream_number (); |
|
1082 } |
|
1083 |
4645
|
1084 std::streamoff |
4643
|
1085 octave_value::streamoff_value (void) const |
|
1086 { |
|
1087 return rep->streamoff_value (); |
|
1088 } |
|
1089 |
4645
|
1090 streamoff_array |
|
1091 octave_value::streamoff_array_value (void) const |
|
1092 { |
|
1093 return rep->streamoff_array_value (); |
|
1094 } |
|
1095 |
2974
|
1096 octave_function * |
|
1097 octave_value::function_value (bool silent) |
|
1098 { |
|
1099 return rep->function_value (silent); |
|
1100 } |
|
1101 |
4700
|
1102 octave_user_function * |
|
1103 octave_value::user_function_value (bool silent) |
|
1104 { |
|
1105 return rep->user_function_value (silent); |
|
1106 } |
|
1107 |
4346
|
1108 octave_fcn_handle * |
4343
|
1109 octave_value::fcn_handle_value (bool silent) |
|
1110 { |
|
1111 return rep->fcn_handle_value (silent); |
|
1112 } |
|
1113 |
4933
|
1114 octave_fcn_inline * |
|
1115 octave_value::fcn_inline_value (bool silent) |
|
1116 { |
|
1117 return rep->fcn_inline_value (silent); |
|
1118 } |
|
1119 |
2880
|
1120 octave_value_list |
|
1121 octave_value::list_value (void) const |
|
1122 { |
|
1123 return rep->list_value (); |
|
1124 } |
|
1125 |
2376
|
1126 ColumnVector |
3419
|
1127 octave_value::column_vector_value (bool force_string_conv, |
4661
|
1128 bool /* frc_vec_conv */) const |
3419
|
1129 { |
|
1130 ColumnVector retval; |
|
1131 |
|
1132 Matrix m = matrix_value (force_string_conv); |
|
1133 |
|
1134 if (error_state) |
|
1135 return retval; |
|
1136 |
|
1137 int nr = m.rows (); |
|
1138 int nc = m.columns (); |
|
1139 |
|
1140 if (nc == 1) |
|
1141 { |
|
1142 retval.resize (nr); |
|
1143 for (int i = 0; i < nr; i++) |
|
1144 retval (i) = m (i, 0); |
|
1145 } |
|
1146 else |
|
1147 { |
3523
|
1148 std::string tn = type_name (); |
3419
|
1149 gripe_invalid_conversion (tn.c_str (), "real column vector"); |
|
1150 } |
|
1151 |
|
1152 return retval; |
|
1153 } |
|
1154 |
|
1155 ComplexColumnVector |
|
1156 octave_value::complex_column_vector_value (bool force_string_conv, |
4661
|
1157 bool /* frc_vec_conv */) const |
3419
|
1158 { |
|
1159 ComplexColumnVector retval; |
|
1160 |
|
1161 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
1162 |
|
1163 if (error_state) |
|
1164 return retval; |
|
1165 |
|
1166 int nr = m.rows (); |
|
1167 int nc = m.columns (); |
|
1168 |
|
1169 if (nc == 1) |
|
1170 { |
3465
|
1171 retval.resize (nr); |
|
1172 for (int i = 0; i < nr; i++) |
3419
|
1173 retval (i) = m (i, 0); |
|
1174 } |
|
1175 else |
|
1176 { |
3523
|
1177 std::string tn = type_name (); |
3419
|
1178 gripe_invalid_conversion (tn.c_str (), "complex column vector"); |
|
1179 } |
|
1180 |
|
1181 return retval; |
|
1182 } |
|
1183 |
|
1184 RowVector |
|
1185 octave_value::row_vector_value (bool force_string_conv, |
4661
|
1186 bool /* frc_vec_conv */) const |
3419
|
1187 { |
|
1188 RowVector retval; |
|
1189 |
|
1190 Matrix m = matrix_value (force_string_conv); |
|
1191 |
|
1192 if (error_state) |
|
1193 return retval; |
|
1194 |
|
1195 int nr = m.rows (); |
|
1196 int nc = m.columns (); |
|
1197 |
|
1198 if (nr == 1) |
|
1199 { |
|
1200 retval.resize (nc); |
|
1201 for (int i = 0; i < nc; i++) |
|
1202 retval (i) = m (0, i); |
|
1203 } |
|
1204 else |
|
1205 { |
3523
|
1206 std::string tn = type_name (); |
3419
|
1207 gripe_invalid_conversion (tn.c_str (), "real row vector"); |
|
1208 } |
|
1209 |
|
1210 return retval; |
|
1211 } |
|
1212 |
|
1213 ComplexRowVector |
|
1214 octave_value::complex_row_vector_value (bool force_string_conv, |
4661
|
1215 bool /* frc_vec_conv */) const |
3419
|
1216 { |
|
1217 ComplexRowVector retval; |
|
1218 |
|
1219 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
1220 |
|
1221 if (error_state) |
|
1222 return retval; |
|
1223 |
|
1224 int nr = m.rows (); |
|
1225 int nc = m.columns (); |
|
1226 |
|
1227 if (nr == 1) |
|
1228 { |
|
1229 retval.resize (nc); |
|
1230 for (int i = 0; i < nc; i++) |
|
1231 retval (i) = m (0, i); |
|
1232 } |
|
1233 else |
|
1234 { |
3523
|
1235 std::string tn = type_name (); |
3419
|
1236 gripe_invalid_conversion (tn.c_str (), "complex row vector"); |
|
1237 } |
|
1238 |
|
1239 return retval; |
|
1240 } |
|
1241 |
|
1242 // Sloppy... |
|
1243 |
|
1244 Array<double> |
2376
|
1245 octave_value::vector_value (bool force_string_conv, |
|
1246 bool force_vector_conversion) const |
|
1247 { |
3419
|
1248 Array<double> retval; |
2376
|
1249 |
|
1250 Matrix m = matrix_value (force_string_conv); |
|
1251 |
|
1252 if (error_state) |
|
1253 return retval; |
|
1254 |
|
1255 int nr = m.rows (); |
|
1256 int nc = m.columns (); |
|
1257 |
|
1258 if (nr == 1) |
|
1259 { |
|
1260 retval.resize (nc); |
|
1261 for (int i = 0; i < nc; i++) |
|
1262 retval (i) = m (0, i); |
|
1263 } |
|
1264 else if (nc == 1) |
|
1265 { |
|
1266 retval.resize (nr); |
|
1267 for (int i = 0; i < nr; i++) |
|
1268 retval (i) = m (i, 0); |
|
1269 } |
4455
|
1270 else if (nr > 0 && nc > 0) |
2376
|
1271 { |
4455
|
1272 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
1273 if (! force_vector_conversion && Vwarn_fortran_indexing) |
|
1274 gripe_implicit_conversion (type_name (), "real vector"); |
|
1275 |
2376
|
1276 retval.resize (nr * nc); |
|
1277 int k = 0; |
|
1278 for (int j = 0; j < nc; j++) |
|
1279 for (int i = 0; i < nr; i++) |
4153
|
1280 { |
|
1281 OCTAVE_QUIT; |
|
1282 |
|
1283 retval (k++) = m (i, j); |
|
1284 } |
2376
|
1285 } |
|
1286 else |
|
1287 { |
3523
|
1288 std::string tn = type_name (); |
2376
|
1289 gripe_invalid_conversion (tn.c_str (), "real vector"); |
|
1290 } |
|
1291 |
|
1292 return retval; |
|
1293 } |
|
1294 |
4044
|
1295 Array<int> |
|
1296 octave_value::int_vector_value (bool force_string_conv, bool require_int, |
|
1297 bool force_vector_conversion) const |
|
1298 { |
|
1299 Array<int> retval; |
|
1300 |
|
1301 Matrix m = matrix_value (force_string_conv); |
|
1302 |
|
1303 if (error_state) |
|
1304 return retval; |
|
1305 |
|
1306 int nr = m.rows (); |
|
1307 int nc = m.columns (); |
|
1308 |
|
1309 if (nr == 1) |
|
1310 { |
|
1311 retval.resize (nc); |
|
1312 for (int i = 0; i < nc; i++) |
|
1313 { |
4153
|
1314 OCTAVE_QUIT; |
|
1315 |
4044
|
1316 double d = m (0, i); |
|
1317 |
|
1318 if (require_int && D_NINT (d) != d) |
|
1319 { |
|
1320 error ("conversion to integer value failed"); |
|
1321 return retval; |
|
1322 } |
|
1323 |
|
1324 retval (i) = static_cast<int> (d); |
|
1325 } |
|
1326 } |
|
1327 else if (nc == 1) |
|
1328 { |
|
1329 retval.resize (nr); |
|
1330 for (int i = 0; i < nr; i++) |
|
1331 { |
4153
|
1332 OCTAVE_QUIT; |
|
1333 |
4044
|
1334 double d = m (i, 0); |
|
1335 |
|
1336 if (require_int && D_NINT (d) != d) |
|
1337 { |
|
1338 error ("conversion to integer value failed"); |
|
1339 return retval; |
|
1340 } |
|
1341 |
|
1342 retval (i) = static_cast<int> (d); |
|
1343 } |
|
1344 } |
4455
|
1345 else if (nr > 0 && nc > 0) |
4044
|
1346 { |
4455
|
1347 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
1348 if (! force_vector_conversion && Vwarn_fortran_indexing) |
|
1349 gripe_implicit_conversion (type_name (), "real vector"); |
|
1350 |
4044
|
1351 retval.resize (nr * nc); |
|
1352 int k = 0; |
|
1353 for (int j = 0; j < nc; j++) |
|
1354 { |
|
1355 for (int i = 0; i < nr; i++) |
|
1356 { |
4153
|
1357 OCTAVE_QUIT; |
|
1358 |
4044
|
1359 double d = m (i, j); |
|
1360 |
|
1361 if (require_int && D_NINT (d) != d) |
|
1362 { |
|
1363 error ("conversion to integer value failed"); |
|
1364 return retval; |
|
1365 } |
|
1366 |
|
1367 retval (k++) = static_cast<int> (d); |
|
1368 } |
|
1369 } |
|
1370 } |
|
1371 else |
|
1372 { |
|
1373 std::string tn = type_name (); |
|
1374 gripe_invalid_conversion (tn.c_str (), "real vector"); |
|
1375 } |
|
1376 |
|
1377 return retval; |
|
1378 } |
|
1379 |
3419
|
1380 Array<Complex> |
2376
|
1381 octave_value::complex_vector_value (bool force_string_conv, |
|
1382 bool force_vector_conversion) const |
|
1383 { |
3419
|
1384 Array<Complex> retval; |
2376
|
1385 |
|
1386 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
1387 |
|
1388 if (error_state) |
|
1389 return retval; |
|
1390 |
|
1391 int nr = m.rows (); |
|
1392 int nc = m.columns (); |
|
1393 |
|
1394 if (nr == 1) |
|
1395 { |
|
1396 retval.resize (nc); |
|
1397 for (int i = 0; i < nc; i++) |
4153
|
1398 { |
|
1399 OCTAVE_QUIT; |
|
1400 retval (i) = m (0, i); |
|
1401 } |
2376
|
1402 } |
|
1403 else if (nc == 1) |
|
1404 { |
|
1405 retval.resize (nr); |
|
1406 for (int i = 0; i < nr; i++) |
4153
|
1407 { |
|
1408 OCTAVE_QUIT; |
|
1409 retval (i) = m (i, 0); |
|
1410 } |
2376
|
1411 } |
4455
|
1412 else if (nr > 0 && nc > 0) |
2376
|
1413 { |
4455
|
1414 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
1415 if (! force_vector_conversion && Vwarn_fortran_indexing) |
|
1416 gripe_implicit_conversion (type_name (), "complex vector"); |
|
1417 |
2376
|
1418 retval.resize (nr * nc); |
|
1419 int k = 0; |
|
1420 for (int j = 0; j < nc; j++) |
|
1421 for (int i = 0; i < nr; i++) |
4153
|
1422 { |
|
1423 OCTAVE_QUIT; |
|
1424 retval (k++) = m (i, j); |
|
1425 } |
2376
|
1426 } |
|
1427 else |
|
1428 { |
3523
|
1429 std::string tn = type_name (); |
2376
|
1430 gripe_invalid_conversion (tn.c_str (), "complex vector"); |
|
1431 } |
|
1432 |
|
1433 return retval; |
|
1434 } |
|
1435 |
4452
|
1436 octave_value |
4457
|
1437 octave_value::convert_to_str (bool pad, bool force) const |
4452
|
1438 { |
4457
|
1439 octave_value retval = convert_to_str_internal (pad, force); |
4452
|
1440 |
4457
|
1441 if (! force && is_numeric_type () && Vwarn_num_to_str) |
4452
|
1442 gripe_implicit_conversion (type_name (), retval.type_name ()); |
|
1443 |
|
1444 return retval; |
|
1445 } |
|
1446 |
2376
|
1447 void |
4005
|
1448 octave_value::print_with_name (std::ostream& output_buf, |
|
1449 const std::string& name, |
2903
|
1450 bool print_padding) const |
2376
|
1451 { |
4005
|
1452 if (! (evaluating_function_body && Vsilent_functions)) |
|
1453 { |
4894
|
1454 bool pad_after = false; |
|
1455 |
|
1456 if (Vprint_answer_id_name) |
|
1457 pad_after = print_name_tag (output_buf, name); |
2376
|
1458 |
4005
|
1459 print (output_buf); |
2376
|
1460 |
4005
|
1461 if (print_padding && pad_after) |
|
1462 newline (output_buf); |
|
1463 } |
2376
|
1464 } |
|
1465 |
|
1466 static void |
3523
|
1467 gripe_indexed_assignment (const std::string& tn1, const std::string& tn2) |
2413
|
1468 { |
2903
|
1469 error ("assignment of `%s' to indexed `%s' not implemented", |
2413
|
1470 tn2.c_str (), tn1.c_str ()); |
|
1471 } |
|
1472 |
|
1473 static void |
3933
|
1474 gripe_assign_conversion_failed (const std::string& tn1, |
|
1475 const std::string& tn2) |
2413
|
1476 { |
2903
|
1477 error ("type conversion for assignment of `%s' to indexed `%s' failed", |
2413
|
1478 tn2.c_str (), tn1.c_str ()); |
|
1479 } |
|
1480 |
4944
|
1481 int |
|
1482 octave_value::write (octave_stream& os, int block_size, |
|
1483 oct_data_conv::data_type output_type, int skip, |
|
1484 oct_mach_info::float_format flt_fmt) const |
|
1485 { |
|
1486 return rep->write (os, block_size, output_type, skip, flt_fmt); |
|
1487 } |
|
1488 |
3933
|
1489 octave_value |
4247
|
1490 octave_value::numeric_assign (const std::string& type, |
4219
|
1491 const std::list<octave_value_list>& idx, |
2413
|
1492 const octave_value& rhs) |
|
1493 { |
3933
|
1494 octave_value retval; |
2413
|
1495 |
|
1496 int t_lhs = type_id (); |
|
1497 int t_rhs = rhs.type_id (); |
|
1498 |
2880
|
1499 assign_op_fcn f |
3933
|
1500 = octave_value_typeinfo::lookup_assign_op (op_asn_eq, t_lhs, t_rhs); |
|
1501 |
|
1502 bool done = false; |
2413
|
1503 |
|
1504 if (f) |
|
1505 { |
3933
|
1506 f (*this, idx.front (), rhs.get_rep ()); |
2413
|
1507 |
3933
|
1508 done = (! error_state); |
2413
|
1509 } |
3933
|
1510 |
|
1511 if (done) |
|
1512 retval = octave_value (this, count + 1); |
3196
|
1513 else |
|
1514 { |
3933
|
1515 int t_result |
|
1516 = octave_value_typeinfo::lookup_pref_assign_conv (t_lhs, t_rhs); |
|
1517 |
|
1518 if (t_result >= 0) |
|
1519 { |
|
1520 type_conv_fcn cf |
|
1521 = octave_value_typeinfo::lookup_widening_op (t_lhs, t_result); |
|
1522 |
|
1523 if (cf) |
|
1524 { |
|
1525 octave_value *tmp (cf (*this)); |
3196
|
1526 |
3933
|
1527 if (tmp) |
|
1528 { |
|
1529 retval = tmp->subsasgn (type, idx, rhs); |
|
1530 |
|
1531 done = (! error_state); |
|
1532 } |
|
1533 else |
|
1534 gripe_assign_conversion_failed (type_name (), |
|
1535 rhs.type_name ()); |
|
1536 } |
|
1537 else |
|
1538 gripe_indexed_assignment (type_name (), rhs.type_name ()); |
|
1539 } |
|
1540 |
|
1541 if (! (done || error_state)) |
3196
|
1542 { |
3933
|
1543 octave_value tmp_rhs; |
|
1544 type_conv_fcn cf_rhs = rhs.numeric_conversion_function (); |
|
1545 |
|
1546 if (cf_rhs) |
|
1547 { |
|
1548 octave_value *tmp = cf_rhs (rhs.get_rep ()); |
|
1549 |
|
1550 if (tmp) |
|
1551 tmp_rhs = octave_value (tmp); |
|
1552 else |
|
1553 { |
|
1554 gripe_assign_conversion_failed (type_name (), |
|
1555 rhs.type_name ()); |
|
1556 return octave_value (); |
|
1557 } |
|
1558 } |
|
1559 else |
|
1560 tmp_rhs = rhs; |
|
1561 |
|
1562 type_conv_fcn cf_this = numeric_conversion_function (); |
|
1563 |
|
1564 octave_value *tmp_lhs = this; |
3196
|
1565 |
3933
|
1566 if (cf_this) |
|
1567 { |
|
1568 octave_value *tmp = cf_this (*this); |
|
1569 |
|
1570 if (tmp) |
|
1571 tmp_lhs = tmp; |
|
1572 else |
|
1573 { |
|
1574 gripe_assign_conversion_failed (type_name (), |
|
1575 rhs.type_name ()); |
|
1576 return octave_value (); |
|
1577 } |
|
1578 } |
|
1579 |
|
1580 if (cf_this || cf_rhs) |
|
1581 { |
|
1582 retval = tmp_lhs->subsasgn (type, idx, tmp_rhs); |
|
1583 |
|
1584 done = (! error_state); |
|
1585 } |
|
1586 else |
|
1587 gripe_no_conversion (assign_op_as_string (op_asn_eq), |
|
1588 type_name (), rhs.type_name ()); |
3196
|
1589 } |
|
1590 } |
2413
|
1591 |
4858
|
1592 // The assignment may have converted to a type that is wider than |
|
1593 // necessary. |
|
1594 |
|
1595 retval.maybe_mutate (); |
|
1596 |
2413
|
1597 return retval; |
|
1598 } |
|
1599 |
|
1600 static void |
3933
|
1601 gripe_binary_op (const std::string& on, const std::string& tn1, |
|
1602 const std::string& tn2) |
2376
|
1603 { |
2903
|
1604 error ("binary operator `%s' not implemented for `%s' by `%s' operations", |
2376
|
1605 on.c_str (), tn1.c_str (), tn2.c_str ()); |
|
1606 } |
|
1607 |
3203
|
1608 static void |
3523
|
1609 gripe_binary_op_conv (const std::string& on) |
3203
|
1610 { |
|
1611 error ("type conversion failed for binary operator `%s'", on.c_str ()); |
|
1612 } |
|
1613 |
2376
|
1614 octave_value |
3933
|
1615 do_binary_op (octave_value::binary_op op, |
|
1616 const octave_value& v1, const octave_value& v2) |
2376
|
1617 { |
|
1618 octave_value retval; |
|
1619 |
|
1620 int t1 = v1.type_id (); |
|
1621 int t2 = v2.type_id (); |
|
1622 |
2427
|
1623 binary_op_fcn f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
2376
|
1624 |
|
1625 if (f) |
|
1626 retval = f (*v1.rep, *v2.rep); |
|
1627 else |
|
1628 { |
|
1629 octave_value tv1; |
2427
|
1630 type_conv_fcn cf1 = v1.numeric_conversion_function (); |
2376
|
1631 |
|
1632 if (cf1) |
|
1633 { |
3203
|
1634 octave_value *tmp = cf1 (*v1.rep); |
|
1635 |
|
1636 if (tmp) |
|
1637 { |
|
1638 tv1 = octave_value (tmp); |
|
1639 t1 = tv1.type_id (); |
|
1640 } |
|
1641 else |
|
1642 { |
|
1643 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
|
1644 return retval; |
|
1645 } |
2376
|
1646 } |
|
1647 else |
|
1648 tv1 = v1; |
|
1649 |
|
1650 octave_value tv2; |
2427
|
1651 type_conv_fcn cf2 = v2.numeric_conversion_function (); |
2376
|
1652 |
|
1653 if (cf2) |
|
1654 { |
3203
|
1655 octave_value *tmp = cf2 (*v2.rep); |
|
1656 |
|
1657 if (tmp) |
|
1658 { |
|
1659 tv2 = octave_value (tmp); |
|
1660 t2 = tv2.type_id (); |
|
1661 } |
|
1662 else |
|
1663 { |
|
1664 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
|
1665 return retval; |
|
1666 } |
2376
|
1667 } |
|
1668 else |
|
1669 tv2 = v2; |
|
1670 |
|
1671 if (cf1 || cf2) |
|
1672 { |
4587
|
1673 f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
2376
|
1674 |
|
1675 if (f) |
|
1676 retval = f (*tv1.rep, *tv2.rep); |
|
1677 else |
|
1678 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
1679 v1.type_name (), v2.type_name ()); |
|
1680 } |
|
1681 else |
|
1682 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
1683 v1.type_name (), v2.type_name ()); |
|
1684 } |
|
1685 |
|
1686 return retval; |
|
1687 } |
|
1688 |
4915
|
1689 static void |
|
1690 gripe_cat_op (const std::string& tn1, const std::string& tn2) |
|
1691 { |
|
1692 error ("concatenation operator not implemented for `%s' by `%s' operations", |
|
1693 tn1.c_str (), tn2.c_str ()); |
|
1694 } |
|
1695 |
|
1696 static void |
|
1697 gripe_cat_op_conv (void) |
|
1698 { |
|
1699 error ("type conversion failed for concatenation operator"); |
|
1700 } |
|
1701 |
|
1702 octave_value |
|
1703 do_cat_op (const octave_value& v1, const octave_value& v2, |
|
1704 const Array<int>& ra_idx) |
|
1705 { |
|
1706 octave_value retval; |
|
1707 |
|
1708 int t1 = v1.type_id (); |
|
1709 int t2 = v2.type_id (); |
|
1710 |
|
1711 cat_op_fcn f = octave_value_typeinfo::lookup_cat_op (t1, t2); |
|
1712 |
|
1713 if (f) |
|
1714 retval = f (*v1.rep, *v2.rep, ra_idx); |
|
1715 else |
|
1716 { |
|
1717 octave_value tv1; |
|
1718 type_conv_fcn cf1 = v1.numeric_conversion_function (); |
|
1719 |
|
1720 if (cf1) |
|
1721 { |
|
1722 octave_value *tmp = cf1 (*v1.rep); |
|
1723 |
|
1724 if (tmp) |
|
1725 { |
|
1726 tv1 = octave_value (tmp); |
|
1727 t1 = tv1.type_id (); |
|
1728 } |
|
1729 else |
|
1730 { |
|
1731 gripe_cat_op_conv (); |
|
1732 return retval; |
|
1733 } |
|
1734 } |
|
1735 else |
|
1736 tv1 = v1; |
|
1737 |
|
1738 octave_value tv2; |
|
1739 type_conv_fcn cf2 = v2.numeric_conversion_function (); |
|
1740 |
|
1741 if (cf2) |
|
1742 { |
|
1743 octave_value *tmp = cf2 (*v2.rep); |
|
1744 |
|
1745 if (tmp) |
|
1746 { |
|
1747 tv2 = octave_value (tmp); |
|
1748 t2 = tv2.type_id (); |
|
1749 } |
|
1750 else |
|
1751 { |
|
1752 gripe_cat_op_conv (); |
|
1753 return retval; |
|
1754 } |
|
1755 } |
|
1756 else |
|
1757 tv2 = v2; |
|
1758 |
|
1759 if (cf1 || cf2) |
|
1760 { |
|
1761 f = octave_value_typeinfo::lookup_cat_op (t1, t2); |
|
1762 |
|
1763 if (f) |
|
1764 retval = f (*tv1.rep, *tv2.rep, ra_idx); |
|
1765 else |
|
1766 gripe_cat_op (v1.type_name (), v2.type_name ()); |
|
1767 } |
|
1768 else |
|
1769 gripe_cat_op (v1.type_name (), v2.type_name ()); |
|
1770 } |
|
1771 |
|
1772 return retval; |
|
1773 } |
|
1774 |
3933
|
1775 void |
|
1776 octave_value::print_info (std::ostream& os, const std::string& prefix) const |
|
1777 { |
|
1778 os << prefix << "type_name: " << type_name () << "\n" |
|
1779 << prefix << "count: " << get_count () << "\n" |
|
1780 << prefix << "rep info: "; |
|
1781 |
|
1782 rep->print_info (os, prefix + " "); |
|
1783 } |
|
1784 |
3203
|
1785 static void |
3523
|
1786 gripe_unary_op (const std::string& on, const std::string& tn) |
3203
|
1787 { |
|
1788 error ("unary operator `%s' not implemented for `%s' operands", |
|
1789 on.c_str (), tn.c_str ()); |
|
1790 } |
|
1791 |
|
1792 static void |
3523
|
1793 gripe_unary_op_conv (const std::string& on) |
3203
|
1794 { |
|
1795 error ("type conversion failed for unary operator `%s'", on.c_str ()); |
|
1796 } |
|
1797 |
|
1798 octave_value |
|
1799 do_unary_op (octave_value::unary_op op, const octave_value& v) |
|
1800 { |
|
1801 octave_value retval; |
|
1802 |
|
1803 int t = v.type_id (); |
|
1804 |
|
1805 unary_op_fcn f = octave_value_typeinfo::lookup_unary_op (op, t); |
|
1806 |
|
1807 if (f) |
|
1808 retval = f (*v.rep); |
|
1809 else |
|
1810 { |
|
1811 octave_value tv; |
|
1812 type_conv_fcn cf = v.numeric_conversion_function (); |
|
1813 |
|
1814 if (cf) |
|
1815 { |
|
1816 octave_value *tmp = cf (*v.rep); |
|
1817 |
|
1818 if (tmp) |
|
1819 { |
|
1820 tv = octave_value (tmp); |
|
1821 t = tv.type_id (); |
|
1822 |
4587
|
1823 f = octave_value_typeinfo::lookup_unary_op (op, t); |
3203
|
1824 |
|
1825 if (f) |
|
1826 retval = f (*tv.rep); |
|
1827 else |
|
1828 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1829 v.type_name ()); |
|
1830 } |
|
1831 else |
|
1832 gripe_unary_op_conv (octave_value::unary_op_as_string (op)); |
|
1833 } |
|
1834 else |
|
1835 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1836 v.type_name ()); |
|
1837 } |
|
1838 |
|
1839 return retval; |
|
1840 } |
|
1841 |
|
1842 static void |
3933
|
1843 gripe_unary_op_conversion_failed (const std::string& op, |
|
1844 const std::string& tn) |
3203
|
1845 { |
|
1846 error ("operator %s: type conversion for `%s' failed", |
|
1847 op.c_str (), tn.c_str ()); |
|
1848 } |
|
1849 |
3933
|
1850 const octave_value& |
|
1851 octave_value::do_non_const_unary_op (unary_op op) |
3203
|
1852 { |
|
1853 octave_value retval; |
|
1854 |
|
1855 int t = type_id (); |
|
1856 |
|
1857 non_const_unary_op_fcn f |
|
1858 = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
|
1859 |
|
1860 if (f) |
|
1861 { |
|
1862 make_unique (); |
|
1863 |
|
1864 f (*rep); |
|
1865 } |
|
1866 else |
|
1867 { |
|
1868 type_conv_fcn cf = numeric_conversion_function (); |
|
1869 |
|
1870 if (cf) |
|
1871 { |
|
1872 octave_value *tmp = cf (*rep); |
|
1873 |
|
1874 if (tmp) |
|
1875 { |
|
1876 octave_value *old_rep = rep; |
|
1877 rep = tmp; |
|
1878 rep->count = 1; |
|
1879 |
|
1880 t = type_id (); |
|
1881 |
|
1882 f = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
|
1883 |
|
1884 if (f) |
|
1885 { |
|
1886 f (*rep); |
|
1887 |
|
1888 if (old_rep && --old_rep->count == 0) |
|
1889 delete old_rep; |
|
1890 } |
|
1891 else |
|
1892 { |
|
1893 if (old_rep) |
|
1894 { |
|
1895 if (--rep->count == 0) |
|
1896 delete rep; |
|
1897 |
|
1898 rep = old_rep; |
|
1899 } |
|
1900 |
|
1901 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1902 type_name ()); |
|
1903 } |
|
1904 } |
|
1905 else |
|
1906 gripe_unary_op_conversion_failed |
|
1907 (octave_value::unary_op_as_string (op), type_name ()); |
|
1908 } |
|
1909 else |
|
1910 gripe_unary_op (octave_value::unary_op_as_string (op), type_name ()); |
|
1911 } |
3933
|
1912 |
|
1913 return *this; |
3203
|
1914 } |
|
1915 |
3933
|
1916 #if 0 |
3205
|
1917 static void |
3933
|
1918 gripe_unary_op_failed_or_no_method (const std::string& on, |
|
1919 const std::string& tn) |
3205
|
1920 { |
|
1921 error ("operator %s: no method, or unable to evaluate for %s operand", |
|
1922 on.c_str (), tn.c_str ()); |
|
1923 } |
3933
|
1924 #endif |
3205
|
1925 |
|
1926 void |
4661
|
1927 octave_value::do_non_const_unary_op (unary_op, const octave_value_list&) |
3205
|
1928 { |
3933
|
1929 abort (); |
|
1930 } |
|
1931 |
|
1932 octave_value |
4247
|
1933 octave_value::do_non_const_unary_op (unary_op op, const std::string& type, |
4219
|
1934 const std::list<octave_value_list>& idx) |
3933
|
1935 { |
|
1936 octave_value retval; |
|
1937 |
|
1938 if (idx.empty ()) |
|
1939 { |
|
1940 do_non_const_unary_op (op); |
3205
|
1941 |
3933
|
1942 retval = *this; |
|
1943 } |
|
1944 else |
|
1945 { |
|
1946 // XXX FIXME XXX -- only do the following stuff if we can't find a |
|
1947 // specific function to call to handle the op= operation for the |
|
1948 // types we have. |
3205
|
1949 |
3933
|
1950 assign_op assop = unary_op_to_assign_op (op); |
|
1951 |
|
1952 retval = assign (assop, type, idx, 1.0); |
|
1953 } |
|
1954 |
|
1955 return retval; |
3205
|
1956 } |
|
1957 |
2903
|
1958 // Current indentation. |
|
1959 int octave_value::curr_print_indent_level = 0; |
|
1960 |
3018
|
1961 // TRUE means we are at the beginning of a line. |
2903
|
1962 bool octave_value::beginning_of_line = true; |
|
1963 |
|
1964 // Each print() function should call this before printing anything. |
|
1965 // |
|
1966 // This doesn't need to be fast, but isn't there a better way? |
|
1967 |
|
1968 void |
3523
|
1969 octave_value::indent (std::ostream& os) const |
2903
|
1970 { |
|
1971 assert (curr_print_indent_level >= 0); |
|
1972 |
|
1973 if (beginning_of_line) |
|
1974 { |
|
1975 // XXX FIXME XXX -- do we need this? |
|
1976 // os << prefix; |
|
1977 |
|
1978 for (int i = 0; i < curr_print_indent_level; i++) |
|
1979 os << " "; |
|
1980 |
|
1981 beginning_of_line = false; |
|
1982 } |
|
1983 } |
|
1984 |
|
1985 // All print() functions should use this to print new lines. |
|
1986 |
|
1987 void |
3523
|
1988 octave_value::newline (std::ostream& os) const |
2903
|
1989 { |
|
1990 os << "\n"; |
|
1991 |
|
1992 beginning_of_line = true; |
|
1993 } |
|
1994 |
|
1995 // For ressetting print state. |
|
1996 |
|
1997 void |
|
1998 octave_value::reset (void) const |
|
1999 { |
|
2000 beginning_of_line = true; |
|
2001 curr_print_indent_level = 0; |
|
2002 } |
|
2003 |
3205
|
2004 octave_value::assign_op |
|
2005 octave_value::unary_op_to_assign_op (unary_op op) |
|
2006 { |
|
2007 assign_op binop = unknown_assign_op; |
|
2008 |
|
2009 switch (op) |
|
2010 { |
3533
|
2011 case op_incr: |
|
2012 binop = op_add_eq; |
3205
|
2013 break; |
|
2014 |
3533
|
2015 case op_decr: |
|
2016 binop = op_sub_eq; |
3205
|
2017 break; |
|
2018 |
|
2019 default: |
|
2020 { |
3523
|
2021 std::string on = unary_op_as_string (op); |
3205
|
2022 error ("operator %s: no assign operator found", on.c_str ()); |
|
2023 } |
|
2024 } |
|
2025 |
|
2026 return binop; |
|
2027 } |
|
2028 |
3204
|
2029 octave_value::binary_op |
|
2030 octave_value::op_eq_to_binary_op (assign_op op) |
|
2031 { |
|
2032 binary_op binop = unknown_binary_op; |
|
2033 |
|
2034 switch (op) |
|
2035 { |
3533
|
2036 case op_add_eq: |
|
2037 binop = op_add; |
3204
|
2038 break; |
|
2039 |
3533
|
2040 case op_sub_eq: |
|
2041 binop = op_sub; |
3204
|
2042 break; |
|
2043 |
3533
|
2044 case op_mul_eq: |
|
2045 binop = op_mul; |
3204
|
2046 break; |
|
2047 |
3533
|
2048 case op_div_eq: |
|
2049 binop = op_div; |
3204
|
2050 break; |
|
2051 |
3533
|
2052 case op_ldiv_eq: |
|
2053 binop = op_ldiv; |
3204
|
2054 break; |
|
2055 |
4018
|
2056 case op_pow_eq: |
|
2057 binop = op_pow; |
|
2058 break; |
|
2059 |
3533
|
2060 case op_lshift_eq: |
|
2061 binop = op_lshift; |
3204
|
2062 break; |
|
2063 |
3533
|
2064 case op_rshift_eq: |
|
2065 binop = op_rshift; |
3204
|
2066 break; |
|
2067 |
3533
|
2068 case op_el_mul_eq: |
|
2069 binop = op_el_mul; |
3204
|
2070 break; |
|
2071 |
3533
|
2072 case op_el_div_eq: |
|
2073 binop = op_el_div; |
3204
|
2074 break; |
|
2075 |
3533
|
2076 case op_el_ldiv_eq: |
|
2077 binop = op_el_ldiv; |
3204
|
2078 break; |
|
2079 |
4018
|
2080 case op_el_pow_eq: |
|
2081 binop = op_el_pow; |
|
2082 break; |
|
2083 |
3533
|
2084 case op_el_and_eq: |
|
2085 binop = op_el_and; |
3204
|
2086 break; |
|
2087 |
3533
|
2088 case op_el_or_eq: |
|
2089 binop = op_el_or; |
3204
|
2090 break; |
|
2091 |
|
2092 default: |
|
2093 { |
3523
|
2094 std::string on = assign_op_as_string (op); |
3204
|
2095 error ("operator %s: no binary operator found", on.c_str ()); |
|
2096 } |
|
2097 } |
|
2098 |
|
2099 return binop; |
|
2100 } |
|
2101 |
3933
|
2102 octave_value |
|
2103 octave_value::empty_conv (const std::string& type, const octave_value& rhs) |
|
2104 { |
|
2105 octave_value retval; |
|
2106 |
|
2107 if (type.length () > 0) |
|
2108 { |
|
2109 switch (type[0]) |
|
2110 { |
|
2111 case '(': |
|
2112 { |
|
2113 if (type.length () > 1 && type[1] == '.') |
|
2114 retval = Octave_map (); |
|
2115 else |
|
2116 retval = octave_value (rhs.empty_clone ()); |
|
2117 } |
|
2118 break; |
|
2119 |
|
2120 case '{': |
|
2121 retval = Cell (); |
|
2122 break; |
|
2123 |
|
2124 case '.': |
|
2125 retval = Octave_map (); |
|
2126 break; |
|
2127 |
|
2128 default: |
|
2129 panic_impossible (); |
|
2130 } |
|
2131 } |
|
2132 else |
|
2133 retval = octave_value (rhs.empty_clone ()); |
|
2134 |
|
2135 return retval; |
|
2136 } |
|
2137 |
2376
|
2138 void |
|
2139 install_types (void) |
|
2140 { |
|
2141 octave_base_value::register_type (); |
3928
|
2142 octave_cell::register_type (); |
2376
|
2143 octave_scalar::register_type (); |
|
2144 octave_complex::register_type (); |
|
2145 octave_matrix::register_type (); |
|
2146 octave_complex_matrix::register_type (); |
|
2147 octave_range::register_type (); |
2825
|
2148 octave_bool::register_type (); |
|
2149 octave_bool_matrix::register_type (); |
2376
|
2150 octave_char_matrix::register_type (); |
|
2151 octave_char_matrix_str::register_type (); |
4901
|
2152 octave_int8_scalar::register_type (); |
|
2153 octave_int16_scalar::register_type (); |
|
2154 octave_int32_scalar::register_type (); |
|
2155 octave_int64_scalar::register_type (); |
|
2156 octave_uint8_scalar::register_type (); |
|
2157 octave_uint16_scalar::register_type (); |
|
2158 octave_uint32_scalar::register_type (); |
|
2159 octave_uint64_scalar::register_type (); |
|
2160 octave_int8_matrix::register_type (); |
|
2161 octave_int16_matrix::register_type (); |
|
2162 octave_int32_matrix::register_type (); |
|
2163 octave_int64_matrix::register_type (); |
|
2164 octave_uint8_matrix::register_type (); |
|
2165 octave_uint16_matrix::register_type (); |
|
2166 octave_uint32_matrix::register_type (); |
|
2167 octave_uint64_matrix::register_type (); |
2376
|
2168 octave_struct::register_type (); |
2903
|
2169 octave_file::register_type (); |
2880
|
2170 octave_list::register_type (); |
3977
|
2171 octave_cs_list::register_type (); |
2376
|
2172 octave_all_va_args::register_type (); |
|
2173 octave_magic_colon::register_type (); |
2974
|
2174 octave_builtin::register_type (); |
|
2175 octave_mapper::register_type (); |
|
2176 octave_user_function::register_type (); |
4649
|
2177 octave_dld_function::register_type (); |
4643
|
2178 octave_fcn_handle::register_type (); |
4966
|
2179 octave_fcn_inline::register_type (); |
4643
|
2180 octave_streamoff::register_type (); |
2376
|
2181 } |
|
2182 |
4970
|
2183 #if 0 |
|
2184 DEFUN (cast, args, , |
|
2185 "-*- texinfo -*-\n\ |
|
2186 @deftypefn {Built-in Function} {} cast (@var{val}, @var{type})\n\ |
|
2187 Convert @var{val} to the new data type @var{type}.\n\ |
|
2188 @end deftypefn\n\ |
|
2189 @seealso{class, typeinfo}") |
|
2190 { |
|
2191 octave_value retval; |
|
2192 |
|
2193 if (args.length () == 2) |
|
2194 error ("cast: not implemented"); |
|
2195 else |
|
2196 print_usage ("cast"); |
|
2197 |
|
2198 return retval; |
|
2199 } |
|
2200 #endif |
|
2201 |
4791
|
2202 DEFUN (sizeof, args, , |
|
2203 "-*- texinfo -*-\n\ |
|
2204 @deftypefn {Built-in Function} {} sizeof (@var{val})\n\ |
|
2205 Return the size of @var{val} in bytes\n\ |
|
2206 @end deftypefn") |
|
2207 { |
|
2208 octave_value retval; |
|
2209 |
|
2210 if (args.length () == 1) |
|
2211 retval = args(0).byte_size (); |
|
2212 else |
|
2213 print_usage ("sizeof"); |
|
2214 |
|
2215 return retval; |
|
2216 } |
|
2217 |
2376
|
2218 static int |
4455
|
2219 warn_fortran_indexing (void) |
2376
|
2220 { |
4455
|
2221 Vwarn_fortran_indexing = check_preference ("warn_fortran_indexing"); |
2376
|
2222 |
4455
|
2223 liboctave_wfi_flag = Vwarn_fortran_indexing; |
2376
|
2224 |
|
2225 return 0; |
|
2226 } |
|
2227 |
|
2228 static int |
4452
|
2229 warn_imag_to_real (void) |
4257
|
2230 { |
4452
|
2231 Vwarn_imag_to_real = check_preference ("warn_imag_to_real"); |
4257
|
2232 |
|
2233 return 0; |
|
2234 } |
|
2235 |
|
2236 static int |
4452
|
2237 warn_num_to_str (void) |
2376
|
2238 { |
4452
|
2239 Vwarn_num_to_str = check_preference ("warn_num_to_str"); |
2376
|
2240 |
|
2241 return 0; |
|
2242 } |
|
2243 |
|
2244 static int |
4452
|
2245 warn_str_to_num (void) |
2376
|
2246 { |
4452
|
2247 Vwarn_str_to_num = check_preference ("warn_str_to_num"); |
2376
|
2248 |
|
2249 return 0; |
|
2250 } |
|
2251 |
|
2252 static int |
|
2253 print_answer_id_name (void) |
|
2254 { |
|
2255 Vprint_answer_id_name = check_preference ("print_answer_id_name"); |
|
2256 |
|
2257 return 0; |
|
2258 } |
|
2259 |
|
2260 static int |
4461
|
2261 warn_resize_on_range_error (void) |
2376
|
2262 { |
4461
|
2263 Vwarn_resize_on_range_error |
|
2264 = check_preference ("warn_resize_on_range_error"); |
2376
|
2265 |
4461
|
2266 liboctave_wrore_flag = Vwarn_resize_on_range_error; |
2376
|
2267 |
|
2268 return 0; |
|
2269 } |
|
2270 |
|
2271 static int |
4005
|
2272 silent_functions (void) |
|
2273 { |
|
2274 Vsilent_functions = check_preference ("silent_functions"); |
|
2275 |
|
2276 return 0; |
|
2277 } |
|
2278 |
|
2279 static int |
2376
|
2280 struct_levels_to_print (void) |
|
2281 { |
|
2282 double val; |
|
2283 if (builtin_real_scalar_variable ("struct_levels_to_print", val) |
|
2284 && ! xisnan (val)) |
|
2285 { |
|
2286 int ival = NINT (val); |
3961
|
2287 if (ival == val) |
2376
|
2288 { |
|
2289 Vstruct_levels_to_print = ival; |
|
2290 return 0; |
|
2291 } |
|
2292 } |
|
2293 gripe_invalid_value_specified ("struct_levels_to_print"); |
|
2294 return -1; |
|
2295 } |
|
2296 |
|
2297 static int |
|
2298 warn_divide_by_zero (void) |
|
2299 { |
|
2300 Vwarn_divide_by_zero = check_preference ("warn_divide_by_zero"); |
|
2301 |
|
2302 return 0; |
|
2303 } |
|
2304 |
|
2305 void |
2909
|
2306 symbols_of_ov (void) |
2376
|
2307 { |
4233
|
2308 DEFVAR (print_answer_id_name, true, print_answer_id_name, |
3372
|
2309 "-*- texinfo -*-\n\ |
|
2310 @defvr {Built-in Variable} print_answer_id_name\n\ |
|
2311 If the value of @code{print_answer_id_name} is nonzero, variable\n\ |
|
2312 names are printed along with the result. Otherwise, only the result\n\ |
|
2313 values are printed. The default value is 1.\n\ |
|
2314 @end defvr"); |
2376
|
2315 |
4233
|
2316 DEFVAR (silent_functions, false, silent_functions, |
4005
|
2317 "-*- texinfo -*-\n\ |
|
2318 @defvr {Built-in Variable} silent_functions\n\ |
|
2319 If the value of @code{silent_functions} is nonzero, internal output\n\ |
|
2320 from a function is suppressed. Otherwise, the results of expressions\n\ |
|
2321 within a function body that are not terminated with a semicolon will\n\ |
|
2322 have their values printed. The default value is 0.\n\ |
|
2323 \n\ |
|
2324 For example, if the function\n\ |
|
2325 \n\ |
|
2326 @example\n\ |
|
2327 function f ()\n\ |
|
2328 2 + 2\n\ |
|
2329 endfunction\n\ |
|
2330 @end example\n\ |
|
2331 \n\ |
|
2332 @noindent\n\ |
|
2333 is executed, Octave will either print @samp{ans = 4} or nothing\n\ |
|
2334 depending on the value of @code{silent_functions}.\n\ |
|
2335 @end defvr"); |
|
2336 |
3258
|
2337 DEFVAR (struct_levels_to_print, 2.0, struct_levels_to_print, |
3361
|
2338 "-*- texinfo -*-\n\ |
|
2339 @defvr {Built-in Variable} struct_levels_to_print\n\ |
|
2340 You can tell Octave how many structure levels to display by setting the\n\ |
|
2341 built-in variable @code{struct_levels_to_print}. The default value is 2.\n\ |
3363
|
2342 @end defvr"); |
2376
|
2343 |
4233
|
2344 DEFVAR (warn_divide_by_zero, true, warn_divide_by_zero, |
3371
|
2345 "-*- texinfo -*-\n\ |
|
2346 @defvr {Built-in Variable} warn_divide_by_zero\n\ |
|
2347 If the value of @code{warn_divide_by_zero} is nonzero, a warning\n\ |
|
2348 is issued when Octave encounters a division by zero. If the value is\n\ |
|
2349 0, the warning is omitted. The default value is 1.\n\ |
|
2350 @end defvr"); |
4451
|
2351 |
4455
|
2352 DEFVAR (warn_fortran_indexing, false, warn_fortran_indexing, |
|
2353 "-*- texinfo -*-\n\ |
|
2354 @defvr {Built-in Variable} warn_fortran_indexing\n\ |
|
2355 If the value of @code{warn_fortran_indexing} is nonzero, a warning is\n\ |
|
2356 printed for expressions which select elements of a two-dimensional matrix\n\ |
|
2357 using a single index. The default value is 0.\n\ |
|
2358 @end defvr"); |
|
2359 |
4451
|
2360 DEFVAR (warn_imag_to_real, false, warn_imag_to_real, |
|
2361 "-*- texinfo -*-\n\ |
|
2362 @defvr {Built-in Variable} warn_imag_to_real\n\ |
|
2363 If the value of @code{warn_imag_to_real} is nonzero, a warning is\n\ |
|
2364 printed for implicit conversions of complex numbers to real numbers.\n\ |
|
2365 The default value is 0.\n\ |
|
2366 @end defvr"); |
4452
|
2367 |
|
2368 DEFVAR (warn_num_to_str, true, warn_num_to_str, |
|
2369 "-*- texinfo -*-\n\ |
|
2370 @defvr {Built-in Variable} warn_num_to_str\n\ |
|
2371 If the value of @code{warn_num_to_str} is nonzero, a warning is\n\ |
|
2372 printed for implicit conversions of numbers to their ASCII character\n\ |
|
2373 equivalents when strings are constructed using a mixture of strings and\n\ |
|
2374 numbers in matrix notation. For example,\n\ |
|
2375 \n\ |
|
2376 @example\n\ |
|
2377 @group\n\ |
|
2378 [ \"f\", 111, 111 ]\n\ |
|
2379 @result{} \"foo\"\n\ |
|
2380 @end group\n\ |
|
2381 @end example\n\ |
|
2382 elicits a warning if @code{warn_num_to_str} is nonzero. The default\n\ |
|
2383 value is 1.\n\ |
|
2384 @end defvr"); |
|
2385 |
4461
|
2386 DEFVAR (warn_resize_on_range_error, false, warn_resize_on_range_error, |
|
2387 "-*- texinfo -*-\n\ |
|
2388 @defvr {Built-in Variable} warn_resize_on_range_error\n\ |
|
2389 If the value of @code{warn_resize_on_range_error} is nonzero, print a\n\ |
|
2390 warning when a matrix is resized by an indexed assignment with\n\ |
|
2391 indices outside the current bounds. The default value is 0.\n\ |
|
2392 @end defvr"); |
|
2393 |
4452
|
2394 DEFVAR (warn_str_to_num, false, warn_str_to_num, |
|
2395 "-*- texinfo -*-\n\ |
|
2396 @defvr {Built-in Variable} warn_str_to_num\n\ |
|
2397 If the value of @code{warn_str_to_num} is nonzero, a warning is printed\n\ |
|
2398 for implicit conversions of strings to their numeric ASCII equivalents.\n\ |
|
2399 For example,\n\ |
|
2400 @example\n\ |
|
2401 @group\n\ |
|
2402 \"abc\" + 0\n\ |
|
2403 @result{} 97 98 99\n\ |
|
2404 @end group\n\ |
|
2405 @end example\n\ |
|
2406 elicits a warning if @code{warn_str_to_num} is nonzero. The default\n\ |
|
2407 value is 0.\n\ |
|
2408 @end defvr"); |
2376
|
2409 } |
|
2410 |
|
2411 /* |
|
2412 ;;; Local Variables: *** |
|
2413 ;;; mode: C++ *** |
|
2414 ;;; End: *** |
|
2415 */ |