Mercurial > octave
comparison libinterp/octave-value/ov-cell.cc @ 20681:b0b37f0d7e6d
new cellstr_value function and elimination of error_state
* ov.h (octave_value::cellstr_value): New overloaded function with
extra error message.
* ov-base.h, ov-base.cc (octave_base_value::cellstr_value): Likewise.
* ov-cell.h, ov-cell.cc (octave_cell::cellstr_value): Likewise.
* ov-str-mat.h, ov-str-mat.cc (octave_str_mat::cellstr_value):
Likewise.
* graphics.cc, urlwrite.cc, ov-cell.cc, ov-class.cc, ov-struct.cc:
Use new cellstr_value function and eliminate use of error_state.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 05 Nov 2015 17:22:16 -0500 |
parents | 1a0a433c8263 |
children | 68e3a747ca02 |
comparison
equal
deleted
inserted
replaced
20680:8787e80a44b2 | 20681:b0b37f0d7e6d |
---|---|
478 octave_value | 478 octave_value |
479 octave_cell::sort (octave_idx_type dim, sortmode mode) const | 479 octave_cell::sort (octave_idx_type dim, sortmode mode) const |
480 { | 480 { |
481 octave_value retval; | 481 octave_value retval; |
482 | 482 |
483 if (is_cellstr ()) | 483 Array<std::string> tmp = cellstr_value ("sort: only cell arrays of character strings may be sorted"); |
484 { | 484 |
485 Array<std::string> tmp = cellstr_value (); | 485 tmp = tmp.sort (dim, mode); |
486 | 486 |
487 tmp = tmp.sort (dim, mode); | 487 // We already have the cache. |
488 | 488 retval = new octave_cell (tmp); |
489 // We already have the cache. | |
490 retval = new octave_cell (tmp); | |
491 } | |
492 else | |
493 error ("sort: only cell arrays of character strings may be sorted"); | |
494 | 489 |
495 return retval; | 490 return retval; |
496 } | 491 } |
497 | 492 |
498 octave_value | 493 octave_value |
499 octave_cell::sort (Array<octave_idx_type> &sidx, octave_idx_type dim, | 494 octave_cell::sort (Array<octave_idx_type> &sidx, octave_idx_type dim, |
500 sortmode mode) const | 495 sortmode mode) const |
501 { | 496 { |
502 octave_value retval; | 497 octave_value retval; |
503 | 498 |
504 if (is_cellstr ()) | 499 Array<std::string> tmp = cellstr_value ("sort: only cell arrays of character strings may be sorted"); |
505 { | 500 |
506 Array<std::string> tmp = cellstr_value (); | 501 tmp = tmp.sort (sidx, dim, mode); |
507 | 502 |
508 tmp = tmp.sort (sidx, dim, mode); | 503 // We already have the cache. |
509 | 504 retval = new octave_cell (tmp); |
510 // We already have the cache. | |
511 retval = new octave_cell (tmp); | |
512 } | |
513 else | |
514 error ("sort: only cell arrays of character strings may be sorted"); | |
515 | 505 |
516 return retval; | 506 return retval; |
517 } | 507 } |
518 | 508 |
519 sortmode | 509 sortmode |
520 octave_cell::is_sorted (sortmode mode) const | 510 octave_cell::is_sorted (sortmode mode) const |
521 { | 511 { |
522 sortmode retval = UNSORTED; | 512 sortmode retval = UNSORTED; |
523 | 513 |
524 if (is_cellstr ()) | 514 Array<std::string> tmp = cellstr_value ("issorted: A is not a cell array of strings"); |
525 { | 515 |
526 Array<std::string> tmp = cellstr_value (); | 516 retval = tmp.is_sorted (mode); |
527 | |
528 retval = tmp.is_sorted (mode); | |
529 } | |
530 else | |
531 error ("issorted: A is not a cell array of strings"); | |
532 | 517 |
533 return retval; | 518 return retval; |
534 } | 519 } |
535 | 520 |
536 | 521 |
537 Array<octave_idx_type> | 522 Array<octave_idx_type> |
538 octave_cell::sort_rows_idx (sortmode mode) const | 523 octave_cell::sort_rows_idx (sortmode mode) const |
539 { | 524 { |
540 Array<octave_idx_type> retval; | 525 Array<octave_idx_type> retval; |
541 | 526 |
542 if (is_cellstr ()) | 527 Array<std::string> tmp = cellstr_value ("sortrows: only cell arrays of character strings may be sorted"); |
543 { | 528 |
544 Array<std::string> tmp = cellstr_value (); | 529 retval = tmp.sort_rows_idx (mode); |
545 | |
546 retval = tmp.sort_rows_idx (mode); | |
547 } | |
548 else | |
549 error ("sortrows: only cell arrays of character strings may be sorted"); | |
550 | 530 |
551 return retval; | 531 return retval; |
552 } | 532 } |
553 | 533 |
554 sortmode | 534 sortmode |
555 octave_cell::is_sorted_rows (sortmode mode) const | 535 octave_cell::is_sorted_rows (sortmode mode) const |
556 { | 536 { |
557 sortmode retval = UNSORTED; | 537 sortmode retval = UNSORTED; |
558 | 538 |
559 if (is_cellstr ()) | 539 Array<std::string> tmp = cellstr_value ("issorted: A is not a cell array of strings"); |
560 { | 540 |
561 Array<std::string> tmp = cellstr_value (); | 541 retval = tmp.is_sorted_rows (mode); |
562 | |
563 retval = tmp.is_sorted_rows (mode); | |
564 } | |
565 else | |
566 error ("issorted: A is not a cell array of strings"); | |
567 | 542 |
568 return retval; | 543 return retval; |
569 } | 544 } |
570 | 545 |
571 bool | 546 bool |
655 | 630 |
656 return *cellstr_cache; | 631 return *cellstr_cache; |
657 } | 632 } |
658 else | 633 else |
659 error ("invalid conversion from cell array to array of strings"); | 634 error ("invalid conversion from cell array to array of strings"); |
635 | |
636 return retval; | |
637 } | |
638 | |
639 Array<std::string> | |
640 octave_cell::cellstr_value (const char *fmt, ...) const | |
641 { | |
642 Array<std::string> retval; | |
643 va_list args; | |
644 retval = cellstr_value (fmt, args); | |
645 va_end (args); | |
646 return retval; | |
647 } | |
648 | |
649 Array<std::string> | |
650 octave_cell::cellstr_value (const char *fmt, va_list args) const | |
651 { | |
652 Array<std::string> retval; | |
653 | |
654 if (! fmt) | |
655 return cellstr_value (); | |
656 | |
657 bool conversion_error = false; | |
658 | |
659 if (is_cellstr ()) | |
660 { | |
661 try | |
662 { | |
663 if (cellstr_cache->is_empty ()) | |
664 *cellstr_cache = matrix.cellstr_value (); | |
665 | |
666 retval = *cellstr_cache; | |
667 } | |
668 catch (const octave_execution_exception&) | |
669 { | |
670 conversion_error = true; | |
671 } | |
672 } | |
673 else | |
674 conversion_error = true; | |
675 | |
676 if (conversion_error) | |
677 verror (fmt, args); | |
660 | 678 |
661 return retval; | 679 return retval; |
662 } | 680 } |
663 | 681 |
664 bool | 682 bool |