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