Mercurial > octave-antonio
diff src/ov-cell.cc @ 8732:a669df7beb73
[mq]: x
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 12 Feb 2009 14:37:43 -0500 |
parents | 280fae940bb0 |
children | 3ef774603887 |
line wrap: on
line diff
--- a/src/ov-cell.cc Thu Feb 12 10:00:43 2009 +0100 +++ b/src/ov-cell.cc Thu Feb 12 14:37:43 2009 -0500 @@ -387,6 +387,58 @@ return retval; } +octave_value +octave_cell::sort (octave_idx_type dim, sortmode mode) const +{ + octave_value retval; + + if (is_cellstr ()) + { + Array<std::string> tmp = cellstr_value (); + + retval = Cell (tmp.sort (dim, mode)); + } + else + error ("sort: only cell arrays of character strings may be sorted"); + + return retval; +} + +octave_value +octave_cell::sort (Array<octave_idx_type> &sidx, octave_idx_type dim, + sortmode mode) const +{ + octave_value retval; + + if (is_cellstr ()) + { + Array<std::string> tmp = cellstr_value (); + + retval = Cell (tmp.sort (sidx, dim, mode)); + } + else + error ("sort: only cell arrays of character strings may be sorted"); + + return retval; +} + +Array<octave_idx_type> +octave_cell::sortrows_idx (sortmode mode) const +{ + Array<octave_idx_type> retval; + + if (is_cellstr ()) + { + Array<std::string> tmp = cellstr_value (); + + retval = tmp.sort_rows_idx (mode); + } + else + error ("sortrows: only cell arrays of character strings may be sorted"); + + return retval; +} + bool octave_cell::is_true (void) const { @@ -460,6 +512,27 @@ return retval; } +Array<std::string> +octave_cell::cellstr_value (void) const +{ + Array<std::string> retval (dims ()); + + if (is_cellstr ()) + { + octave_idx_type n = numel (); + + std::string *dst = retval.fortran_vec (); + const octave_value *src = matrix.data (); + + for (octave_idx_type i = 0; i < n; i++) + dst[i] = src[i].string_value (); + } + else + error ("invalid conversion from cell array to Array<std::string>"); + + return retval; +} + bool octave_cell::print_as_scalar (void) const {