Mercurial > octave
diff 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 |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-cell.cc Thu Nov 05 16:09:38 2015 -0500 +++ b/libinterp/octave-value/ov-cell.cc Thu Nov 05 17:22:16 2015 -0500 @@ -480,17 +480,12 @@ { octave_value retval; - if (is_cellstr ()) - { - Array<std::string> tmp = cellstr_value (); - - tmp = tmp.sort (dim, mode); + Array<std::string> tmp = cellstr_value ("sort: only cell arrays of character strings may be sorted"); - // We already have the cache. - retval = new octave_cell (tmp); - } - else - error ("sort: only cell arrays of character strings may be sorted"); + tmp = tmp.sort (dim, mode); + + // We already have the cache. + retval = new octave_cell (tmp); return retval; } @@ -501,17 +496,12 @@ { octave_value retval; - if (is_cellstr ()) - { - Array<std::string> tmp = cellstr_value (); - - tmp = tmp.sort (sidx, dim, mode); + Array<std::string> tmp = cellstr_value ("sort: only cell arrays of character strings may be sorted"); - // We already have the cache. - retval = new octave_cell (tmp); - } - else - error ("sort: only cell arrays of character strings may be sorted"); + tmp = tmp.sort (sidx, dim, mode); + + // We already have the cache. + retval = new octave_cell (tmp); return retval; } @@ -521,14 +511,9 @@ { sortmode retval = UNSORTED; - if (is_cellstr ()) - { - Array<std::string> tmp = cellstr_value (); + Array<std::string> tmp = cellstr_value ("issorted: A is not a cell array of strings"); - retval = tmp.is_sorted (mode); - } - else - error ("issorted: A is not a cell array of strings"); + retval = tmp.is_sorted (mode); return retval; } @@ -539,14 +524,9 @@ { Array<octave_idx_type> retval; - if (is_cellstr ()) - { - Array<std::string> tmp = cellstr_value (); + Array<std::string> tmp = cellstr_value ("sortrows: only cell arrays of character strings may be sorted"); - retval = tmp.sort_rows_idx (mode); - } - else - error ("sortrows: only cell arrays of character strings may be sorted"); + retval = tmp.sort_rows_idx (mode); return retval; } @@ -556,14 +536,9 @@ { sortmode retval = UNSORTED; - if (is_cellstr ()) - { - Array<std::string> tmp = cellstr_value (); + Array<std::string> tmp = cellstr_value ("issorted: A is not a cell array of strings"); - retval = tmp.is_sorted_rows (mode); - } - else - error ("issorted: A is not a cell array of strings"); + retval = tmp.is_sorted_rows (mode); return retval; } @@ -661,6 +636,49 @@ return retval; } +Array<std::string> +octave_cell::cellstr_value (const char *fmt, ...) const +{ + Array<std::string> retval; + va_list args; + retval = cellstr_value (fmt, args); + va_end (args); + return retval; +} + +Array<std::string> +octave_cell::cellstr_value (const char *fmt, va_list args) const +{ + Array<std::string> retval; + + if (! fmt) + return cellstr_value (); + + bool conversion_error = false; + + if (is_cellstr ()) + { + try + { + if (cellstr_cache->is_empty ()) + *cellstr_cache = matrix.cellstr_value (); + + retval = *cellstr_cache; + } + catch (const octave_execution_exception&) + { + conversion_error = true; + } + } + else + conversion_error = true; + + if (conversion_error) + verror (fmt, args); + + return retval; +} + bool octave_cell::print_as_scalar (void) const {