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