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