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