2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if defined (__GNUG__) |
|
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" |
2376
|
33 |
2974
|
34 #include "oct-obj.h" |
2979
|
35 #include "oct-lvalue.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" |
|
43 #include "ov-complex.h" |
|
44 #include "ov-cx-mat.h" |
|
45 #include "ov-ch-mat.h" |
|
46 #include "ov-str-mat.h" |
|
47 #include "ov-range.h" |
|
48 #include "ov-struct.h" |
2903
|
49 #include "ov-file.h" |
2880
|
50 #include "ov-list.h" |
2376
|
51 #include "ov-colon.h" |
|
52 #include "ov-va-args.h" |
2974
|
53 #include "ov-builtin.h" |
|
54 #include "ov-mapper.h" |
|
55 #include "ov-usr-fcn.h" |
2376
|
56 #include "ov-typeinfo.h" |
|
57 |
|
58 #include "defun.h" |
2880
|
59 #include "error.h" |
2376
|
60 #include "gripes.h" |
|
61 #include "pager.h" |
|
62 #include "pr-output.h" |
|
63 #include "utils.h" |
|
64 #include "variables.h" |
|
65 |
2477
|
66 // We are likely to have a lot of octave_value objects to allocate, so |
|
67 // make the grow_size large. |
3219
|
68 DEFINE_OCTAVE_ALLOCATOR2(octave_value, 1024); |
2477
|
69 |
2376
|
70 // If TRUE, allow assignments like |
|
71 // |
|
72 // octave> A(1) = 3; A(2) = 5 |
|
73 // |
|
74 // for A already defined and a matrix type. |
|
75 bool Vdo_fortran_indexing; |
|
76 |
|
77 // Should we allow things like: |
|
78 // |
|
79 // octave> 'abc' + 0 |
|
80 // 97 98 99 |
|
81 // |
|
82 // to happen? A positive value means yes. A negative value means |
|
83 // yes, but print a warning message. Zero means it should be |
|
84 // considered an error. |
|
85 int Vimplicit_str_to_num_ok; |
|
86 |
|
87 // Should we allow silent conversion of complex to real when a real |
|
88 // type is what we're really looking for? A positive value means yes. |
|
89 // A negative value means yes, but print a warning message. Zero |
|
90 // means it should be considered an error. |
|
91 int Vok_to_lose_imaginary_part; |
|
92 |
|
93 // If TRUE, create column vectors when doing assignments like: |
|
94 // |
|
95 // octave> A(1) = 3; A(2) = 5 |
|
96 // |
|
97 // (for A undefined). Only matters when resize_on_range_error is also |
|
98 // TRUE. |
|
99 bool Vprefer_column_vectors; |
|
100 |
|
101 // If TRUE, print the name along with the value. |
|
102 bool Vprint_answer_id_name; |
|
103 |
|
104 // Should operations on empty matrices return empty matrices or an |
|
105 // error? A positive value means yes. A negative value means yes, |
|
106 // but print a warning message. Zero means it should be considered an |
|
107 // error. |
|
108 int Vpropagate_empty_matrices; |
|
109 |
|
110 // How many levels of structure elements should we print? |
|
111 int Vstruct_levels_to_print; |
|
112 |
|
113 // Allow divide by zero errors to be suppressed. |
|
114 bool Vwarn_divide_by_zero; |
|
115 |
2948
|
116 // If TRUE, resize matrices when performing and indexed assignment and |
|
117 // the indices are outside the current bounds. |
3196
|
118 bool Vresize_on_range_error; |
2948
|
119 |
2880
|
120 // XXX FIXME XXX |
|
121 |
2376
|
122 // Octave's value type. |
|
123 |
|
124 string |
3203
|
125 octave_value::unary_op_as_string (unary_op op) |
|
126 { |
|
127 string retval; |
|
128 |
|
129 switch (op) |
|
130 { |
|
131 case not: |
|
132 retval = "!"; |
|
133 break; |
|
134 |
|
135 case uminus: |
|
136 retval = "-"; |
|
137 break; |
|
138 |
|
139 case transpose: |
|
140 retval = ".'"; |
|
141 break; |
|
142 |
|
143 case hermitian: |
|
144 retval = "'"; |
|
145 break; |
|
146 |
|
147 case incr: |
|
148 retval = "++"; |
|
149 break; |
|
150 |
|
151 case decr: |
|
152 retval = "--"; |
|
153 break; |
|
154 |
|
155 default: |
|
156 retval = "<unknown>"; |
|
157 } |
|
158 |
|
159 return retval; |
|
160 } |
|
161 |
|
162 string |
2376
|
163 octave_value::binary_op_as_string (binary_op op) |
|
164 { |
|
165 string retval; |
|
166 |
|
167 switch (op) |
|
168 { |
|
169 case add: |
|
170 retval = "+"; |
|
171 break; |
|
172 |
|
173 case sub: |
|
174 retval = "-"; |
|
175 break; |
|
176 |
|
177 case mul: |
|
178 retval = "*"; |
|
179 break; |
|
180 |
|
181 case div: |
|
182 retval = "/"; |
|
183 break; |
|
184 |
|
185 case pow: |
|
186 retval = "^"; |
|
187 break; |
|
188 |
|
189 case ldiv: |
|
190 retval = "\\"; |
|
191 break; |
|
192 |
2903
|
193 case lshift: |
|
194 retval = "<<"; |
|
195 break; |
|
196 |
|
197 case rshift: |
|
198 retval = ">>"; |
|
199 break; |
|
200 |
2376
|
201 case lt: |
|
202 retval = "<"; |
|
203 break; |
|
204 |
|
205 case le: |
|
206 retval = "<="; |
|
207 break; |
|
208 |
|
209 case eq: |
|
210 retval = "=="; |
|
211 break; |
|
212 |
|
213 case ge: |
|
214 retval = ">="; |
|
215 break; |
|
216 |
|
217 case gt: |
|
218 retval = ">"; |
|
219 break; |
|
220 |
|
221 case ne: |
|
222 retval = "!="; |
|
223 break; |
|
224 |
|
225 case el_mul: |
|
226 retval = ".*"; |
|
227 break; |
|
228 |
|
229 case el_div: |
|
230 retval = "./"; |
|
231 break; |
|
232 |
|
233 case el_pow: |
|
234 retval = ".^"; |
|
235 break; |
|
236 |
|
237 case el_ldiv: |
|
238 retval = ".\\"; |
|
239 break; |
|
240 |
|
241 case el_and: |
|
242 retval = "&"; |
|
243 break; |
|
244 |
|
245 case el_or: |
|
246 retval = "|"; |
|
247 break; |
|
248 |
|
249 case struct_ref: |
|
250 retval = "."; |
|
251 break; |
|
252 |
|
253 default: |
|
254 retval = "<unknown>"; |
|
255 } |
|
256 |
|
257 return retval; |
|
258 } |
|
259 |
2880
|
260 string |
|
261 octave_value::assign_op_as_string (assign_op op) |
|
262 { |
|
263 string retval; |
|
264 |
|
265 switch (op) |
|
266 { |
|
267 case asn_eq: |
|
268 retval = "="; |
|
269 break; |
|
270 |
|
271 case add_eq: |
|
272 retval = "+="; |
|
273 break; |
|
274 |
|
275 case sub_eq: |
|
276 retval = "-="; |
|
277 break; |
|
278 |
|
279 case mul_eq: |
|
280 retval = "*="; |
|
281 break; |
|
282 |
|
283 case div_eq: |
|
284 retval = "/="; |
|
285 break; |
|
286 |
3204
|
287 case ldiv_eq: |
|
288 retval = "\\="; |
|
289 break; |
|
290 |
2903
|
291 case lshift_eq: |
|
292 retval = "<<="; |
|
293 break; |
|
294 |
|
295 case rshift_eq: |
|
296 retval = ">>="; |
|
297 break; |
|
298 |
2880
|
299 case el_mul_eq: |
|
300 retval = ".*="; |
|
301 break; |
|
302 |
|
303 case el_div_eq: |
|
304 retval = "./="; |
|
305 break; |
|
306 |
3204
|
307 case el_ldiv_eq: |
|
308 retval = ".\\="; |
|
309 break; |
|
310 |
2880
|
311 case el_and_eq: |
|
312 retval = "&="; |
|
313 break; |
|
314 |
|
315 case el_or_eq: |
|
316 retval = "|="; |
|
317 break; |
|
318 |
|
319 default: |
|
320 retval = "<unknown>"; |
|
321 } |
|
322 |
|
323 return retval; |
|
324 } |
|
325 |
2376
|
326 octave_value::octave_value (void) |
2825
|
327 : rep (new octave_base_value ()) |
|
328 { |
|
329 rep->count = 1; |
|
330 } |
2376
|
331 |
|
332 octave_value::octave_value (double d) |
2825
|
333 : rep (new octave_scalar (d)) |
|
334 { |
|
335 rep->count = 1; |
|
336 } |
2376
|
337 |
3351
|
338 octave_value::octave_value (const Cell& c) |
|
339 : rep (new octave_cell (c)) |
|
340 { |
|
341 rep->count = 1; |
|
342 maybe_mutate (); |
|
343 } |
|
344 |
2376
|
345 octave_value::octave_value (const Matrix& m) |
2423
|
346 : rep (new octave_matrix (m)) |
|
347 { |
|
348 rep->count = 1; |
|
349 maybe_mutate (); |
|
350 } |
2376
|
351 |
|
352 octave_value::octave_value (const DiagMatrix& d) |
2423
|
353 : rep (new octave_matrix (d)) |
|
354 { |
|
355 rep->count = 1; |
|
356 maybe_mutate (); |
|
357 } |
2376
|
358 |
|
359 octave_value::octave_value (const RowVector& v, int pcv) |
2423
|
360 : rep (new octave_matrix (v, pcv)) |
|
361 { |
|
362 rep->count = 1; |
|
363 maybe_mutate (); |
|
364 } |
2376
|
365 |
|
366 octave_value::octave_value (const ColumnVector& v, int pcv) |
2423
|
367 : rep (new octave_matrix (v, pcv)) |
|
368 { |
|
369 rep->count = 1; |
|
370 maybe_mutate (); |
|
371 } |
2376
|
372 |
|
373 octave_value::octave_value (const Complex& C) |
2423
|
374 : rep (new octave_complex (C)) |
|
375 { |
|
376 rep->count = 1; |
|
377 maybe_mutate (); |
|
378 } |
2376
|
379 |
|
380 octave_value::octave_value (const ComplexMatrix& m) |
2423
|
381 : rep (new octave_complex_matrix (m)) |
|
382 { |
|
383 rep->count = 1; |
|
384 maybe_mutate (); |
|
385 } |
2376
|
386 |
|
387 octave_value::octave_value (const ComplexDiagMatrix& d) |
2423
|
388 : rep (new octave_complex_matrix (d)) |
|
389 { |
|
390 rep->count = 1; |
|
391 maybe_mutate (); |
|
392 } |
2376
|
393 |
|
394 octave_value::octave_value (const ComplexRowVector& v, int pcv) |
2423
|
395 : rep (new octave_complex_matrix (v, pcv)) |
|
396 { |
|
397 rep->count = 1; |
|
398 maybe_mutate (); |
|
399 } |
2376
|
400 |
|
401 octave_value::octave_value (const ComplexColumnVector& v, int pcv) |
2423
|
402 : rep (new octave_complex_matrix (v, pcv)) |
|
403 { |
|
404 rep->count = 1; |
|
405 maybe_mutate (); |
|
406 } |
2376
|
407 |
2825
|
408 octave_value::octave_value (bool b) |
|
409 : rep (new octave_bool (b)) |
|
410 { |
|
411 rep->count = 1; |
|
412 } |
|
413 |
|
414 octave_value::octave_value (const boolMatrix& bm) |
|
415 : rep (new octave_bool_matrix (bm)) |
|
416 { |
|
417 rep->count = 1; |
|
418 maybe_mutate (); |
|
419 } |
|
420 |
3189
|
421 octave_value::octave_value (char c) |
|
422 : rep (new octave_char_matrix_str (c)) |
|
423 { |
|
424 rep->count = 1; |
|
425 maybe_mutate (); |
|
426 } |
|
427 |
2376
|
428 octave_value::octave_value (const char *s) |
2423
|
429 : rep (new octave_char_matrix_str (s)) |
|
430 { |
|
431 rep->count = 1; |
|
432 maybe_mutate (); |
|
433 } |
2376
|
434 |
|
435 octave_value::octave_value (const string& s) |
2423
|
436 : rep (new octave_char_matrix_str (s)) |
|
437 { |
|
438 rep->count = 1; |
|
439 maybe_mutate (); |
|
440 } |
2376
|
441 |
|
442 octave_value::octave_value (const string_vector& s) |
2423
|
443 : rep (new octave_char_matrix_str (s)) |
|
444 { |
|
445 rep->count = 1; |
|
446 maybe_mutate (); |
|
447 } |
2376
|
448 |
|
449 octave_value::octave_value (const charMatrix& chm, bool is_string) |
2409
|
450 : rep (0) |
|
451 { |
|
452 if (is_string) |
|
453 rep = new octave_char_matrix_str (chm); |
|
454 else |
|
455 rep = new octave_char_matrix (chm); |
2376
|
456 |
2409
|
457 rep->count = 1; |
2423
|
458 maybe_mutate (); |
2409
|
459 } |
2376
|
460 |
|
461 octave_value::octave_value (double base, double limit, double inc) |
2423
|
462 : rep (new octave_range (base, limit, inc)) |
|
463 { |
|
464 rep->count = 1; |
|
465 maybe_mutate (); |
|
466 } |
2376
|
467 |
|
468 octave_value::octave_value (const Range& r) |
2423
|
469 : rep (new octave_range (r)) |
|
470 { |
|
471 rep->count = 1; |
|
472 maybe_mutate (); |
|
473 } |
2376
|
474 |
|
475 octave_value::octave_value (const Octave_map& m) |
2825
|
476 : rep (new octave_struct (m)) |
|
477 { |
|
478 rep->count = 1; |
2880
|
479 } |
|
480 |
3340
|
481 octave_value::octave_value (const octave_stream& s, int n) |
2903
|
482 : rep (new octave_file (s, n)) |
|
483 { |
|
484 rep->count = 1; |
|
485 } |
|
486 |
2974
|
487 octave_value::octave_value (octave_function *f) |
|
488 : rep (f) |
|
489 { |
|
490 rep->count = 1; |
|
491 } |
|
492 |
2880
|
493 octave_value::octave_value (const octave_value_list& l) |
|
494 : rep (new octave_list (l)) |
|
495 { |
|
496 rep->count = 1; |
|
497 } |
2376
|
498 |
|
499 octave_value::octave_value (octave_value::magic_colon) |
2825
|
500 : rep (new octave_magic_colon ()) |
|
501 { |
|
502 rep->count = 1; |
|
503 } |
2376
|
504 |
|
505 octave_value::octave_value (octave_value::all_va_args) |
2825
|
506 : rep (new octave_all_va_args ()) |
|
507 { |
|
508 rep->count = 1; |
|
509 } |
2376
|
510 |
|
511 octave_value::octave_value (octave_value *new_rep) |
2825
|
512 : rep (new_rep) |
|
513 { |
|
514 rep->count = 1; |
|
515 } |
2376
|
516 |
|
517 octave_value::~octave_value (void) |
|
518 { |
|
519 #if defined (MDEBUG) |
|
520 cerr << "~octave_value: rep: " << rep |
|
521 << " rep->count: " << rep->count << "\n"; |
|
522 #endif |
|
523 |
|
524 if (rep && --rep->count == 0) |
|
525 { |
|
526 delete rep; |
|
527 rep = 0; |
|
528 } |
|
529 } |
|
530 |
2880
|
531 octave_value * |
|
532 octave_value::clone (void) |
|
533 { |
|
534 panic_impossible (); |
|
535 } |
|
536 |
2409
|
537 void |
|
538 octave_value::maybe_mutate (void) |
|
539 { |
2410
|
540 octave_value *tmp = rep->try_narrowing_conversion (); |
2409
|
541 |
|
542 if (tmp && tmp != rep) |
|
543 { |
|
544 if (--rep->count == 0) |
|
545 delete rep; |
|
546 |
|
547 rep = tmp; |
|
548 rep->count = 1; |
|
549 } |
|
550 } |
|
551 |
2974
|
552 octave_value_list |
|
553 octave_value::do_index_op (int nargout, const octave_value_list& idx) |
|
554 { |
|
555 return rep->do_index_op (nargout, idx); |
|
556 } |
|
557 |
2376
|
558 static void |
3203
|
559 gripe_no_conversion (const string& on, const string& tn1, const string& tn2) |
2376
|
560 { |
3203
|
561 error ("operator %s: no conversion for assignment of `%s' to indexed `%s'", |
|
562 on.c_str (), tn2.c_str (), tn1.c_str ()); |
2376
|
563 } |
|
564 |
3204
|
565 static void |
|
566 gripe_assign_failed (const string& on, const string& tn1, const string& tn2) |
|
567 { |
|
568 error ("assignment failed for `%s %s %s'", |
|
569 tn1.c_str (), on.c_str (), tn2.c_str ()); |
|
570 } |
|
571 |
|
572 static void |
|
573 gripe_assign_failed_or_no_method (const string& on, const string& tn1, |
|
574 const string& tn2) |
|
575 { |
|
576 error ("assignment failed, or no method for `%s %s %s'", |
|
577 tn1.c_str (), on.c_str (), tn2.c_str ()); |
|
578 } |
|
579 |
2963
|
580 void |
3203
|
581 octave_value::assign (assign_op op, const octave_value& rhs) |
2880
|
582 { |
3203
|
583 if (op == asn_eq) |
|
584 operator = (rhs); |
|
585 else |
|
586 { |
3204
|
587 // XXX FIXME XXX -- only do the following stuff if we can't find |
|
588 // a specific function to call to handle the op= operation for |
|
589 // the types we have. |
|
590 |
|
591 binary_op binop = op_eq_to_binary_op (op); |
|
592 |
|
593 if (! error_state) |
|
594 { |
|
595 octave_value t = do_binary_op (binop, *this, rhs); |
|
596 |
|
597 if (! error_state) |
|
598 operator = (t); |
|
599 } |
|
600 |
|
601 if (error_state) |
|
602 gripe_assign_failed_or_no_method (assign_op_as_string (op), |
|
603 type_name (), rhs.type_name ()); |
|
604 } |
|
605 } |
|
606 |
|
607 void |
|
608 octave_value::simple_assign (octave_value::assign_op orig_op, |
|
609 const octave_value_list& idx, |
|
610 const octave_value& rhs) |
|
611 { |
|
612 make_unique (); |
|
613 |
|
614 bool assignment_ok = try_assignment (asn_eq, idx, rhs); |
|
615 |
|
616 if (! (error_state || assignment_ok)) |
|
617 { |
|
618 assignment_ok = try_assignment_with_conversion (asn_eq, idx, rhs); |
|
619 |
|
620 if (! (error_state || assignment_ok)) |
|
621 gripe_no_conversion (assign_op_as_string (orig_op), |
|
622 type_name (), rhs.type_name ()); |
3203
|
623 } |
2880
|
624 } |
|
625 |
2963
|
626 void |
2880
|
627 octave_value::assign (octave_value::assign_op op, |
|
628 const octave_value_list& idx, |
|
629 const octave_value& rhs) |
2409
|
630 { |
2948
|
631 if (Vresize_on_range_error || is_defined ()) |
|
632 { |
3204
|
633 if (op == asn_eq) |
|
634 simple_assign (op, idx, rhs); |
|
635 else |
|
636 { |
|
637 // XXX FIXME XXX -- only do the following stuff if we can't |
|
638 // find a specific function to call to handle the op= |
|
639 // operation for the types we have. |
|
640 |
|
641 octave_value t1 = *this; |
2948
|
642 |
3204
|
643 t1 = t1.do_index_op (idx); |
|
644 |
|
645 if (! error_state) |
|
646 { |
|
647 binary_op binop = op_eq_to_binary_op (op); |
|
648 |
|
649 if (! error_state) |
|
650 { |
|
651 octave_value t2 = do_binary_op (binop, t1, rhs); |
2948
|
652 |
3204
|
653 if (! error_state) |
|
654 { |
|
655 simple_assign (op, idx, t2); |
2948
|
656 |
3204
|
657 if (error_state) |
|
658 gripe_assign_failed (assign_op_as_string (op), |
|
659 type_name (), rhs.type_name ()); |
|
660 } |
|
661 else |
|
662 gripe_assign_failed_or_no_method (assign_op_as_string (op), |
|
663 type_name (), |
|
664 rhs.type_name ()); |
|
665 } |
|
666 else |
|
667 gripe_assign_failed_or_no_method (assign_op_as_string (op), |
|
668 type_name (), |
|
669 rhs.type_name ()); |
|
670 } |
|
671 else |
|
672 gripe_assign_failed (assign_op_as_string (op), |
3203
|
673 type_name (), rhs.type_name ()); |
2948
|
674 } |
|
675 |
|
676 if (! error_state) |
|
677 maybe_mutate (); |
|
678 } |
|
679 else |
|
680 { |
|
681 error ("indexed assignment to previously undefined variables"); |
|
682 error ("is only possible when resize_on_range_error is true"); |
|
683 } |
|
684 } |
|
685 |
|
686 void |
|
687 octave_value::assign_struct_elt (assign_op op, const string& elt_nm, |
|
688 const octave_value& rhs) |
|
689 { |
2409
|
690 make_unique (); |
2376
|
691 |
2948
|
692 rep->assign_struct_elt (op, elt_nm, rhs); |
|
693 } |
|
694 |
2409
|
695 |
2948
|
696 void |
|
697 octave_value::assign_struct_elt (assign_op op, const string& elt_nm, |
|
698 const octave_value_list& idx, |
|
699 const octave_value& rhs) |
|
700 { |
|
701 make_unique (); |
2409
|
702 |
2948
|
703 rep->assign_struct_elt (op, elt_nm, idx, rhs); |
|
704 } |
2376
|
705 |
2979
|
706 octave_lvalue |
2948
|
707 octave_value::struct_elt_ref (const string& nm) |
|
708 { |
|
709 return rep->struct_elt_ref (this, nm); |
|
710 } |
2409
|
711 |
2979
|
712 octave_lvalue |
2948
|
713 octave_value::struct_elt_ref (octave_value *, const string&) |
|
714 { |
|
715 panic_impossible (); |
|
716 |
2979
|
717 return octave_lvalue (); |
2376
|
718 } |
|
719 |
3351
|
720 Cell |
|
721 octave_value::cell_value (void) const |
|
722 { |
|
723 return rep->cell_value (); |
|
724 } |
|
725 |
2376
|
726 Octave_map |
|
727 octave_value::map_value (void) const |
|
728 { |
|
729 return rep->map_value (); |
|
730 } |
|
731 |
3340
|
732 octave_stream |
2903
|
733 octave_value::stream_value (void) const |
|
734 { |
|
735 return rep->stream_value (); |
|
736 } |
|
737 |
|
738 int |
|
739 octave_value::stream_number (void) const |
|
740 { |
|
741 return rep->stream_number (); |
|
742 } |
|
743 |
2974
|
744 octave_function * |
|
745 octave_value::function_value (bool silent) |
|
746 { |
|
747 return rep->function_value (silent); |
|
748 } |
|
749 |
2880
|
750 octave_value_list |
|
751 octave_value::list_value (void) const |
|
752 { |
|
753 return rep->list_value (); |
|
754 } |
|
755 |
2376
|
756 ColumnVector |
|
757 octave_value::vector_value (bool force_string_conv, |
|
758 bool force_vector_conversion) const |
|
759 { |
|
760 ColumnVector retval; |
|
761 |
|
762 Matrix m = matrix_value (force_string_conv); |
|
763 |
|
764 if (error_state) |
|
765 return retval; |
|
766 |
|
767 int nr = m.rows (); |
|
768 int nc = m.columns (); |
|
769 |
|
770 if (nr == 1) |
|
771 { |
|
772 retval.resize (nc); |
|
773 for (int i = 0; i < nc; i++) |
|
774 retval (i) = m (0, i); |
|
775 } |
|
776 else if (nc == 1) |
|
777 { |
|
778 retval.resize (nr); |
|
779 for (int i = 0; i < nr; i++) |
|
780 retval (i) = m (i, 0); |
|
781 } |
|
782 else if (nr > 0 && nc > 0 |
|
783 && (Vdo_fortran_indexing || force_vector_conversion)) |
|
784 { |
|
785 retval.resize (nr * nc); |
|
786 int k = 0; |
|
787 for (int j = 0; j < nc; j++) |
|
788 for (int i = 0; i < nr; i++) |
|
789 retval (k++) = m (i, j); |
|
790 } |
|
791 else |
|
792 { |
|
793 string tn = type_name (); |
|
794 gripe_invalid_conversion (tn.c_str (), "real vector"); |
|
795 } |
|
796 |
|
797 return retval; |
|
798 } |
|
799 |
|
800 ComplexColumnVector |
|
801 octave_value::complex_vector_value (bool force_string_conv, |
|
802 bool force_vector_conversion) const |
|
803 { |
|
804 ComplexColumnVector retval; |
|
805 |
|
806 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
807 |
|
808 if (error_state) |
|
809 return retval; |
|
810 |
|
811 int nr = m.rows (); |
|
812 int nc = m.columns (); |
|
813 |
|
814 if (nr == 1) |
|
815 { |
|
816 retval.resize (nc); |
|
817 for (int i = 0; i < nc; i++) |
|
818 retval (i) = m (0, i); |
|
819 } |
|
820 else if (nc == 1) |
|
821 { |
|
822 retval.resize (nr); |
|
823 for (int i = 0; i < nr; i++) |
|
824 retval (i) = m (i, 0); |
|
825 } |
|
826 else if (nr > 0 && nc > 0 |
|
827 && (Vdo_fortran_indexing || force_vector_conversion)) |
|
828 { |
|
829 retval.resize (nr * nc); |
|
830 int k = 0; |
|
831 for (int j = 0; j < nc; j++) |
|
832 for (int i = 0; i < nr; i++) |
|
833 retval (k++) = m (i, j); |
|
834 } |
|
835 else |
|
836 { |
|
837 string tn = type_name (); |
|
838 gripe_invalid_conversion (tn.c_str (), "complex vector"); |
|
839 } |
|
840 |
|
841 return retval; |
|
842 } |
|
843 |
|
844 void |
|
845 octave_value::print_with_name (ostream& output_buf, const string& name, |
2903
|
846 bool print_padding) const |
2376
|
847 { |
2903
|
848 bool pad_after = print_name_tag (output_buf, name); |
2376
|
849 |
|
850 print (output_buf); |
|
851 |
|
852 if (print_padding && pad_after) |
2903
|
853 newline (output_buf); |
2376
|
854 } |
|
855 |
|
856 static void |
2413
|
857 gripe_indexed_assignment (const string& tn1, const string& tn2) |
|
858 { |
2903
|
859 error ("assignment of `%s' to indexed `%s' not implemented", |
2413
|
860 tn2.c_str (), tn1.c_str ()); |
|
861 } |
|
862 |
|
863 static void |
3203
|
864 gripe_assign_conversion_failed (const string& tn1, const string& tn2) |
2413
|
865 { |
2903
|
866 error ("type conversion for assignment of `%s' to indexed `%s' failed", |
2413
|
867 tn2.c_str (), tn1.c_str ()); |
|
868 } |
|
869 |
|
870 bool |
2880
|
871 octave_value::convert_and_assign (octave_value::assign_op op, |
|
872 const octave_value_list& idx, |
2413
|
873 const octave_value& rhs) |
|
874 { |
|
875 bool assignment_ok = false; |
|
876 |
|
877 int t_lhs = type_id (); |
|
878 int t_rhs = rhs.type_id (); |
|
879 |
|
880 int t_result |
|
881 = octave_value_typeinfo::lookup_pref_assign_conv (t_lhs, t_rhs); |
|
882 |
|
883 if (t_result >= 0) |
|
884 { |
2427
|
885 type_conv_fcn cf |
2413
|
886 = octave_value_typeinfo::lookup_widening_op (t_lhs, t_result); |
|
887 |
|
888 if (cf) |
|
889 { |
|
890 octave_value *tmp = cf (*rep); |
|
891 |
|
892 if (tmp) |
|
893 { |
2589
|
894 octave_value *old_rep = rep; |
|
895 rep = tmp; |
|
896 rep->count = 1; |
|
897 |
2880
|
898 assignment_ok = try_assignment (op, idx, rhs); |
2589
|
899 |
|
900 if (! assignment_ok && old_rep) |
2413
|
901 { |
|
902 if (--rep->count == 0) |
|
903 delete rep; |
|
904 |
2589
|
905 rep = old_rep; |
|
906 old_rep = 0; |
2413
|
907 } |
|
908 |
2589
|
909 if (old_rep && --old_rep->count == 0) |
|
910 delete old_rep; |
2413
|
911 } |
|
912 else |
3203
|
913 gripe_assign_conversion_failed (type_name (), rhs.type_name ()); |
2413
|
914 } |
|
915 else |
|
916 gripe_indexed_assignment (type_name (), rhs.type_name ()); |
|
917 } |
|
918 |
|
919 return (assignment_ok && ! error_state); |
|
920 } |
|
921 |
|
922 bool |
2880
|
923 octave_value::try_assignment_with_conversion (octave_value::assign_op op, |
|
924 const octave_value_list& idx, |
2413
|
925 const octave_value& rhs) |
|
926 { |
2880
|
927 bool assignment_ok = convert_and_assign (op, idx, rhs); |
2413
|
928 |
|
929 if (! (error_state || assignment_ok)) |
|
930 { |
|
931 octave_value tmp_rhs; |
2427
|
932 type_conv_fcn cf_rhs = rhs.numeric_conversion_function (); |
2413
|
933 |
|
934 if (cf_rhs) |
3203
|
935 { |
|
936 octave_value *tmp = cf_rhs (*rhs.rep); |
|
937 |
|
938 if (tmp) |
|
939 tmp_rhs = octave_value (tmp); |
|
940 else |
|
941 { |
|
942 gripe_assign_conversion_failed (type_name (), rhs.type_name ()); |
|
943 return false; |
|
944 } |
|
945 } |
2413
|
946 else |
|
947 tmp_rhs = rhs; |
|
948 |
|
949 octave_value *old_rep = 0; |
2427
|
950 type_conv_fcn cf_this = numeric_conversion_function (); |
2413
|
951 |
|
952 if (cf_this) |
|
953 { |
|
954 old_rep = rep; |
3203
|
955 |
|
956 octave_value *tmp = cf_this (*rep); |
|
957 |
|
958 if (tmp) |
|
959 { |
|
960 rep = tmp; |
|
961 rep->count = 1; |
|
962 } |
|
963 else |
|
964 { |
|
965 gripe_assign_conversion_failed (type_name (), rhs.type_name ()); |
|
966 return false; |
|
967 } |
2413
|
968 } |
|
969 |
|
970 if (cf_this || cf_rhs) |
|
971 { |
2880
|
972 assignment_ok = try_assignment (op, idx, tmp_rhs); |
2413
|
973 |
|
974 if (! (error_state || assignment_ok)) |
2880
|
975 assignment_ok = convert_and_assign (op, idx, tmp_rhs); |
2413
|
976 } |
|
977 |
|
978 if (! assignment_ok && old_rep) |
|
979 { |
|
980 if (--rep->count == 0) |
|
981 delete rep; |
|
982 |
|
983 rep = old_rep; |
|
984 old_rep = 0; |
|
985 } |
|
986 |
|
987 if (old_rep && --old_rep->count == 0) |
|
988 delete old_rep; |
|
989 } |
|
990 |
|
991 return (assignment_ok && ! error_state); |
|
992 } |
|
993 |
|
994 bool |
2880
|
995 octave_value::try_assignment (octave_value::assign_op op, |
|
996 const octave_value_list& idx, |
2413
|
997 const octave_value& rhs) |
|
998 { |
|
999 bool retval = false; |
|
1000 |
|
1001 int t_lhs = type_id (); |
|
1002 int t_rhs = rhs.type_id (); |
|
1003 |
2880
|
1004 assign_op_fcn f |
|
1005 = octave_value_typeinfo::lookup_assign_op (op, t_lhs, t_rhs); |
2413
|
1006 |
|
1007 if (f) |
|
1008 { |
|
1009 f (*rep, idx, *(rhs.rep)); |
|
1010 |
|
1011 retval = (! error_state); |
|
1012 } |
3196
|
1013 else |
|
1014 { |
|
1015 f = octave_value_typeinfo::lookup_assignany_op (op, t_lhs); |
|
1016 |
|
1017 if (f) |
|
1018 { |
|
1019 f (*rep, idx, rhs); |
|
1020 |
|
1021 retval = (! error_state); |
|
1022 } |
|
1023 } |
2413
|
1024 |
|
1025 return retval; |
|
1026 } |
|
1027 |
|
1028 static void |
2376
|
1029 gripe_binary_op (const string& on, const string& tn1, const string& tn2) |
|
1030 { |
2903
|
1031 error ("binary operator `%s' not implemented for `%s' by `%s' operations", |
2376
|
1032 on.c_str (), tn1.c_str (), tn2.c_str ()); |
|
1033 } |
|
1034 |
3203
|
1035 static void |
|
1036 gripe_binary_op_conv (const string& on) |
|
1037 { |
|
1038 error ("type conversion failed for binary operator `%s'", on.c_str ()); |
|
1039 } |
|
1040 |
2376
|
1041 octave_value |
|
1042 do_binary_op (octave_value::binary_op op, const octave_value& v1, |
|
1043 const octave_value& v2) |
|
1044 { |
|
1045 octave_value retval; |
|
1046 |
|
1047 int t1 = v1.type_id (); |
|
1048 int t2 = v2.type_id (); |
|
1049 |
2427
|
1050 binary_op_fcn f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
2376
|
1051 |
|
1052 if (f) |
|
1053 retval = f (*v1.rep, *v2.rep); |
|
1054 else |
|
1055 { |
|
1056 octave_value tv1; |
2427
|
1057 type_conv_fcn cf1 = v1.numeric_conversion_function (); |
2376
|
1058 |
|
1059 if (cf1) |
|
1060 { |
3203
|
1061 octave_value *tmp = cf1 (*v1.rep); |
|
1062 |
|
1063 if (tmp) |
|
1064 { |
|
1065 tv1 = octave_value (tmp); |
|
1066 t1 = tv1.type_id (); |
|
1067 } |
|
1068 else |
|
1069 { |
|
1070 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
|
1071 return retval; |
|
1072 } |
2376
|
1073 } |
|
1074 else |
|
1075 tv1 = v1; |
|
1076 |
|
1077 octave_value tv2; |
2427
|
1078 type_conv_fcn cf2 = v2.numeric_conversion_function (); |
2376
|
1079 |
|
1080 if (cf2) |
|
1081 { |
3203
|
1082 octave_value *tmp = cf2 (*v2.rep); |
|
1083 |
|
1084 if (tmp) |
|
1085 { |
|
1086 tv2 = octave_value (tmp); |
|
1087 t2 = tv2.type_id (); |
|
1088 } |
|
1089 else |
|
1090 { |
|
1091 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
|
1092 return retval; |
|
1093 } |
2376
|
1094 } |
|
1095 else |
|
1096 tv2 = v2; |
|
1097 |
|
1098 if (cf1 || cf2) |
|
1099 { |
2427
|
1100 binary_op_fcn f |
2376
|
1101 = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
|
1102 |
|
1103 if (f) |
|
1104 retval = f (*tv1.rep, *tv2.rep); |
|
1105 else |
|
1106 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
1107 v1.type_name (), v2.type_name ()); |
|
1108 } |
|
1109 else |
|
1110 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
1111 v1.type_name (), v2.type_name ()); |
|
1112 } |
|
1113 |
|
1114 return retval; |
|
1115 } |
|
1116 |
3203
|
1117 static void |
|
1118 gripe_unary_op (const string& on, const string& tn) |
|
1119 { |
|
1120 error ("unary operator `%s' not implemented for `%s' operands", |
|
1121 on.c_str (), tn.c_str ()); |
|
1122 } |
|
1123 |
|
1124 static void |
|
1125 gripe_unary_op_conv (const string& on) |
|
1126 { |
|
1127 error ("type conversion failed for unary operator `%s'", on.c_str ()); |
|
1128 } |
|
1129 |
|
1130 octave_value |
|
1131 do_unary_op (octave_value::unary_op op, const octave_value& v) |
|
1132 { |
|
1133 octave_value retval; |
|
1134 |
|
1135 int t = v.type_id (); |
|
1136 |
|
1137 unary_op_fcn f = octave_value_typeinfo::lookup_unary_op (op, t); |
|
1138 |
|
1139 if (f) |
|
1140 retval = f (*v.rep); |
|
1141 else |
|
1142 { |
|
1143 octave_value tv; |
|
1144 type_conv_fcn cf = v.numeric_conversion_function (); |
|
1145 |
|
1146 if (cf) |
|
1147 { |
|
1148 octave_value *tmp = cf (*v.rep); |
|
1149 |
|
1150 if (tmp) |
|
1151 { |
|
1152 tv = octave_value (tmp); |
|
1153 t = tv.type_id (); |
|
1154 |
|
1155 unary_op_fcn f = octave_value_typeinfo::lookup_unary_op (op, t); |
|
1156 |
|
1157 if (f) |
|
1158 retval = f (*tv.rep); |
|
1159 else |
|
1160 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1161 v.type_name ()); |
|
1162 } |
|
1163 else |
|
1164 gripe_unary_op_conv (octave_value::unary_op_as_string (op)); |
|
1165 } |
|
1166 else |
|
1167 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1168 v.type_name ()); |
|
1169 } |
|
1170 |
|
1171 return retval; |
|
1172 } |
|
1173 |
|
1174 static void |
|
1175 gripe_unary_op_conversion_failed (const string& op, const string& tn) |
|
1176 { |
|
1177 error ("operator %s: type conversion for `%s' failed", |
|
1178 op.c_str (), tn.c_str ()); |
|
1179 } |
|
1180 |
|
1181 void |
|
1182 octave_value::do_non_const_unary_op (octave_value::unary_op op) |
|
1183 { |
|
1184 octave_value retval; |
|
1185 |
|
1186 int t = type_id (); |
|
1187 |
|
1188 non_const_unary_op_fcn f |
|
1189 = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
|
1190 |
|
1191 if (f) |
|
1192 { |
|
1193 make_unique (); |
|
1194 |
|
1195 f (*rep); |
|
1196 } |
|
1197 else |
|
1198 { |
|
1199 type_conv_fcn cf = numeric_conversion_function (); |
|
1200 |
|
1201 if (cf) |
|
1202 { |
|
1203 octave_value *tmp = cf (*rep); |
|
1204 |
|
1205 if (tmp) |
|
1206 { |
|
1207 octave_value *old_rep = rep; |
|
1208 rep = tmp; |
|
1209 rep->count = 1; |
|
1210 |
|
1211 t = type_id (); |
|
1212 |
|
1213 f = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
|
1214 |
|
1215 if (f) |
|
1216 { |
|
1217 f (*rep); |
|
1218 |
|
1219 if (old_rep && --old_rep->count == 0) |
|
1220 delete old_rep; |
|
1221 } |
|
1222 else |
|
1223 { |
|
1224 if (old_rep) |
|
1225 { |
|
1226 if (--rep->count == 0) |
|
1227 delete rep; |
|
1228 |
|
1229 rep = old_rep; |
|
1230 } |
|
1231 |
|
1232 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1233 type_name ()); |
|
1234 } |
|
1235 } |
|
1236 else |
|
1237 gripe_unary_op_conversion_failed |
|
1238 (octave_value::unary_op_as_string (op), type_name ()); |
|
1239 } |
|
1240 else |
|
1241 gripe_unary_op (octave_value::unary_op_as_string (op), type_name ()); |
|
1242 } |
|
1243 } |
|
1244 |
3205
|
1245 static void |
|
1246 gripe_unary_op_failed_or_no_method (const string& on, const string& tn) |
|
1247 { |
|
1248 error ("operator %s: no method, or unable to evaluate for %s operand", |
|
1249 on.c_str (), tn.c_str ()); |
|
1250 } |
|
1251 |
|
1252 void |
|
1253 octave_value::do_non_const_unary_op (octave_value::unary_op op, |
|
1254 const octave_value_list& idx) |
|
1255 { |
|
1256 // XXX FIXME XXX -- only do the following stuff if we can't find a |
|
1257 // specific function to call to handle the op= operation for the |
|
1258 // types we have. |
|
1259 |
|
1260 assign_op assop = unary_op_to_assign_op (op); |
|
1261 |
|
1262 if (! error_state) |
|
1263 assign (assop, idx, 1.0); |
|
1264 else |
|
1265 gripe_unary_op_failed_or_no_method (unary_op_as_string (op), |
|
1266 type_name ()); |
|
1267 } |
|
1268 |
2903
|
1269 // Current indentation. |
|
1270 int octave_value::curr_print_indent_level = 0; |
|
1271 |
3018
|
1272 // TRUE means we are at the beginning of a line. |
2903
|
1273 bool octave_value::beginning_of_line = true; |
|
1274 |
|
1275 // Each print() function should call this before printing anything. |
|
1276 // |
|
1277 // This doesn't need to be fast, but isn't there a better way? |
|
1278 |
|
1279 void |
|
1280 octave_value::indent (ostream& os) const |
|
1281 { |
|
1282 assert (curr_print_indent_level >= 0); |
|
1283 |
|
1284 if (beginning_of_line) |
|
1285 { |
|
1286 // XXX FIXME XXX -- do we need this? |
|
1287 // os << prefix; |
|
1288 |
|
1289 for (int i = 0; i < curr_print_indent_level; i++) |
|
1290 os << " "; |
|
1291 |
|
1292 beginning_of_line = false; |
|
1293 } |
|
1294 } |
|
1295 |
|
1296 // All print() functions should use this to print new lines. |
|
1297 |
|
1298 void |
|
1299 octave_value::newline (ostream& os) const |
|
1300 { |
|
1301 os << "\n"; |
|
1302 |
|
1303 beginning_of_line = true; |
|
1304 } |
|
1305 |
|
1306 // For ressetting print state. |
|
1307 |
|
1308 void |
|
1309 octave_value::reset (void) const |
|
1310 { |
|
1311 beginning_of_line = true; |
|
1312 curr_print_indent_level = 0; |
|
1313 } |
|
1314 |
3205
|
1315 octave_value::assign_op |
|
1316 octave_value::unary_op_to_assign_op (unary_op op) |
|
1317 { |
|
1318 assign_op binop = unknown_assign_op; |
|
1319 |
|
1320 switch (op) |
|
1321 { |
|
1322 case incr: |
|
1323 binop = add_eq; |
|
1324 break; |
|
1325 |
|
1326 case decr: |
|
1327 binop = sub_eq; |
|
1328 break; |
|
1329 |
|
1330 default: |
|
1331 { |
|
1332 string on = unary_op_as_string (op); |
|
1333 error ("operator %s: no assign operator found", on.c_str ()); |
|
1334 } |
|
1335 } |
|
1336 |
|
1337 return binop; |
|
1338 } |
|
1339 |
3204
|
1340 octave_value::binary_op |
|
1341 octave_value::op_eq_to_binary_op (assign_op op) |
|
1342 { |
|
1343 binary_op binop = unknown_binary_op; |
|
1344 |
|
1345 switch (op) |
|
1346 { |
|
1347 case add_eq: |
|
1348 binop = add; |
|
1349 break; |
|
1350 |
|
1351 case sub_eq: |
|
1352 binop = sub; |
|
1353 break; |
|
1354 |
|
1355 case mul_eq: |
|
1356 binop = mul; |
|
1357 break; |
|
1358 |
|
1359 case div_eq: |
|
1360 binop = div; |
|
1361 break; |
|
1362 |
|
1363 case ldiv_eq: |
|
1364 binop = ldiv; |
|
1365 break; |
|
1366 |
|
1367 case lshift_eq: |
|
1368 binop = lshift; |
|
1369 break; |
|
1370 |
|
1371 case rshift_eq: |
|
1372 binop = rshift; |
|
1373 break; |
|
1374 |
|
1375 case el_mul_eq: |
|
1376 binop = el_mul; |
|
1377 break; |
|
1378 |
|
1379 case el_div_eq: |
|
1380 binop = el_div; |
|
1381 break; |
|
1382 |
|
1383 case el_ldiv_eq: |
|
1384 binop = el_ldiv; |
|
1385 break; |
|
1386 |
|
1387 case el_and_eq: |
|
1388 binop = el_and; |
|
1389 break; |
|
1390 |
|
1391 case el_or_eq: |
|
1392 binop = el_or; |
|
1393 break; |
|
1394 |
|
1395 default: |
|
1396 { |
|
1397 string on = assign_op_as_string (op); |
|
1398 error ("operator %s: no binary operator found", on.c_str ()); |
|
1399 } |
|
1400 } |
|
1401 |
|
1402 return binop; |
|
1403 } |
|
1404 |
2376
|
1405 void |
|
1406 install_types (void) |
|
1407 { |
|
1408 octave_base_value::register_type (); |
|
1409 octave_scalar::register_type (); |
|
1410 octave_complex::register_type (); |
|
1411 octave_matrix::register_type (); |
|
1412 octave_complex_matrix::register_type (); |
|
1413 octave_range::register_type (); |
2825
|
1414 octave_bool::register_type (); |
|
1415 octave_bool_matrix::register_type (); |
2376
|
1416 octave_char_matrix::register_type (); |
|
1417 octave_char_matrix_str::register_type (); |
|
1418 octave_struct::register_type (); |
2903
|
1419 octave_file::register_type (); |
2880
|
1420 octave_list::register_type (); |
2376
|
1421 octave_all_va_args::register_type (); |
|
1422 octave_magic_colon::register_type (); |
2974
|
1423 octave_builtin::register_type (); |
|
1424 octave_mapper::register_type (); |
|
1425 octave_user_function::register_type (); |
2376
|
1426 } |
|
1427 |
|
1428 static int |
|
1429 do_fortran_indexing (void) |
|
1430 { |
|
1431 Vdo_fortran_indexing = check_preference ("do_fortran_indexing"); |
|
1432 |
|
1433 liboctave_dfi_flag = Vdo_fortran_indexing; |
|
1434 |
|
1435 return 0; |
|
1436 } |
|
1437 |
|
1438 static int |
|
1439 implicit_str_to_num_ok (void) |
|
1440 { |
|
1441 Vimplicit_str_to_num_ok = check_preference ("implicit_str_to_num_ok"); |
|
1442 |
|
1443 return 0; |
|
1444 } |
|
1445 |
|
1446 static int |
|
1447 ok_to_lose_imaginary_part (void) |
|
1448 { |
|
1449 Vok_to_lose_imaginary_part = check_preference ("ok_to_lose_imaginary_part"); |
|
1450 |
|
1451 return 0; |
|
1452 } |
|
1453 |
|
1454 static int |
|
1455 prefer_column_vectors (void) |
|
1456 { |
|
1457 Vprefer_column_vectors |
|
1458 = check_preference ("prefer_column_vectors"); |
|
1459 |
|
1460 liboctave_pcv_flag = Vprefer_column_vectors; |
|
1461 |
|
1462 return 0; |
|
1463 } |
|
1464 |
|
1465 static int |
|
1466 print_answer_id_name (void) |
|
1467 { |
|
1468 Vprint_answer_id_name = check_preference ("print_answer_id_name"); |
|
1469 |
|
1470 return 0; |
|
1471 } |
|
1472 |
|
1473 static int |
|
1474 propagate_empty_matrices (void) |
|
1475 { |
|
1476 Vpropagate_empty_matrices = check_preference ("propagate_empty_matrices"); |
|
1477 |
|
1478 return 0; |
|
1479 } |
|
1480 |
|
1481 static int |
|
1482 resize_on_range_error (void) |
|
1483 { |
|
1484 Vresize_on_range_error = check_preference ("resize_on_range_error"); |
|
1485 |
|
1486 liboctave_rre_flag = Vresize_on_range_error; |
|
1487 |
|
1488 return 0; |
|
1489 } |
|
1490 |
|
1491 static int |
|
1492 struct_levels_to_print (void) |
|
1493 { |
|
1494 double val; |
|
1495 if (builtin_real_scalar_variable ("struct_levels_to_print", val) |
|
1496 && ! xisnan (val)) |
|
1497 { |
|
1498 int ival = NINT (val); |
2800
|
1499 if (ival >= 0 && ival == val) |
2376
|
1500 { |
|
1501 Vstruct_levels_to_print = ival; |
|
1502 return 0; |
|
1503 } |
|
1504 } |
|
1505 gripe_invalid_value_specified ("struct_levels_to_print"); |
|
1506 return -1; |
|
1507 } |
|
1508 |
|
1509 static int |
|
1510 warn_divide_by_zero (void) |
|
1511 { |
|
1512 Vwarn_divide_by_zero = check_preference ("warn_divide_by_zero"); |
|
1513 |
|
1514 return 0; |
|
1515 } |
|
1516 |
|
1517 void |
2909
|
1518 symbols_of_ov (void) |
2376
|
1519 { |
3258
|
1520 DEFVAR (do_fortran_indexing, 0.0, do_fortran_indexing, |
2376
|
1521 "allow single indices for matrices"); |
|
1522 |
3258
|
1523 DEFVAR (implicit_str_to_num_ok, 0.0, implicit_str_to_num_ok, |
3361
|
1524 "-*- texinfo -*-\n\ |
|
1525 @defvr {Built-in Variable} implicit_str_to_num_ok\n\ |
|
1526 If the value of @code{implicit_str_to_num_ok} is nonzero, implicit\n\ |
|
1527 conversions of strings to their numeric ASCII equivalents are allowed.\n\ |
|
1528 Otherwise, an error message is printed and control is returned to the\n\ |
|
1529 top level. The default value is 0.\n\ |
|
1530 @end defvr") |
2376
|
1531 |
3258
|
1532 DEFVAR (ok_to_lose_imaginary_part, "warn", ok_to_lose_imaginary_part, |
2376
|
1533 "silently convert from complex to real by dropping imaginary part"); |
|
1534 |
3258
|
1535 DEFVAR (prefer_column_vectors, 1.0, prefer_column_vectors, |
2376
|
1536 "prefer column/row vectors"); |
|
1537 |
3258
|
1538 DEFVAR (print_answer_id_name, 1.0, print_answer_id_name, |
2376
|
1539 "set output style to print `var_name = ...'"); |
|
1540 |
3258
|
1541 DEFVAR (propagate_empty_matrices, 1.0, propagate_empty_matrices, |
3321
|
1542 "-*- texinfo -*-\n\ |
|
1543 @defvr {Built-in Variable} propagate_empty_matrices\n\ |
|
1544 If the value of @code{propagate_empty_matrices} is nonzero,\n\ |
|
1545 functions like @code{inverse} and @code{svd} will return an empty matrix\n\ |
|
1546 if they are given one as an argument. The default value is 1.\n\ |
3333
|
1547 @end defvr"); |
2376
|
1548 |
3258
|
1549 DEFVAR (resize_on_range_error, 1.0, resize_on_range_error, |
2376
|
1550 "enlarge matrices on assignment"); |
|
1551 |
3258
|
1552 DEFVAR (struct_levels_to_print, 2.0, struct_levels_to_print, |
3361
|
1553 "-*- texinfo -*-\n\ |
|
1554 @defvr {Built-in Variable} struct_levels_to_print\n\ |
|
1555 You can tell Octave how many structure levels to display by setting the\n\ |
|
1556 built-in variable @code{struct_levels_to_print}. The default value is 2.\n\ |
|
1557 @end defvr") |
2376
|
1558 |
3258
|
1559 DEFVAR (warn_divide_by_zero, 1.0, warn_divide_by_zero, |
2957
|
1560 "if TRUE, warn about division by zero"); |
2376
|
1561 } |
|
1562 |
|
1563 /* |
|
1564 ;;; Local Variables: *** |
|
1565 ;;; mode: C++ *** |
|
1566 ;;; End: *** |
|
1567 */ |