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