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