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