Mercurial > octave-nkf
changeset 17866:ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
* pr-output.h, pr-output.cc (octave_print_internal): Provide dummy
versions for char and octave_value objects.
(octave_print_internal (ostream&, double, bool),
octave_print_internal (ostream&, const Complex&, bool)):
Handle print_as_read_syntax.
* ov-base-mat.h, ov-base-mat.cc (octave_base_mat<MT>::short_disp):
New function.
* ov-cell.h, ov-cell.cc (octave_cell::short_disp): New function.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 06 Nov 2013 19:17:59 -0500 |
parents | dde06c2ac6c6 |
children | 49d573a1deda |
files | libinterp/corefcn/pr-output.cc libinterp/corefcn/pr-output.h libinterp/octave-value/ov-base-mat.cc libinterp/octave-value/ov-base-mat.h libinterp/octave-value/ov-cell.cc libinterp/octave-value/ov-cell.h |
diffstat | 6 files changed, 84 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/pr-output.cc Wed Nov 06 18:00:48 2013 -0500 +++ b/libinterp/corefcn/pr-output.cc Wed Nov 06 19:17:59 2013 -0500 @@ -1699,13 +1699,19 @@ } void -octave_print_internal (std::ostream& os, double d, - bool /* pr_as_read_syntax */) +octave_print_internal (std::ostream&, char, bool) { - if (plus_format) - { - pr_plus_format (os, d); - } + panic_impossible (); +} + +void +octave_print_internal (std::ostream& os, double d, + bool pr_as_read_syntax) +{ + if (pr_as_read_syntax) + os << d; + else if (plus_format) + pr_plus_format (os, d); else { set_format (d); @@ -3380,6 +3386,13 @@ panic_impossible (); } +void +octave_print_internal (std::ostream&, const octave_value&, + bool pr_as_read_syntax) +{ + panic_impossible (); +} + DEFUN (rats, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} rats (@var{x}, @var{len})\n\
--- a/libinterp/corefcn/pr-output.h Wed Nov 06 18:00:48 2013 -0500 +++ b/libinterp/corefcn/pr-output.h Wed Nov 06 19:17:59 2013 -0500 @@ -47,6 +47,7 @@ class charNDArray; class PermMatrix; class Cell; +class octave_value; #include "intNDArray.h" #include "oct-inttypes.h" @@ -57,6 +58,10 @@ bool pr_as_read_syntax = false); extern OCTINTERP_API void +octave_print_internal (std::ostream& os, char c, + bool pr_as_read_syntax = false); + +extern OCTINTERP_API void octave_print_internal (std::ostream& os, double d, bool pr_as_read_syntax = false); @@ -252,6 +257,10 @@ int extra_indent = 0, bool pr_as_string = false); +extern OCTINTERP_API void +octave_print_internal (std::ostream& os, const octave_value& ov, + bool pr_as_read_syntax = false); + // TRUE means that the dimensions of empty objects should be printed // like this: x = [](2x0). extern bool Vprint_empty_dimensions;
--- a/libinterp/octave-value/ov-base-mat.cc Wed Nov 06 18:00:48 2013 -0500 +++ b/libinterp/octave-value/ov-base-mat.cc Wed Nov 06 19:17:59 2013 -0500 @@ -450,6 +450,53 @@ } template <class MT> +std::string +octave_base_matrix<MT>::short_disp (void) const +{ + std::ostringstream buf; + + if (matrix.is_empty ()) + buf << "[]"; + else if (matrix.ndims () == 2) + { + // FIXME: should this be configurable? + octave_idx_type max_elts = 10; + octave_idx_type elts = 0; + + octave_idx_type nel = matrix.numel (); + + octave_idx_type nr = matrix.rows (); + octave_idx_type nc = matrix.columns (); + + buf << "["; + + for (octave_idx_type i = 0; i < nr; i++) + { + for (octave_idx_type j = 0; j < nc; j++) + { + octave_print_internal (buf, matrix(j*nr+i), true); + + if (++elts >= max_elts) + goto done; + + if (j < nc - 1) + buf << ", "; + } + + if (i < nr - 1 && elts < max_elts) + buf << "; "; + } + + done: + + if (nel <= max_elts) + buf << "]"; + } + + return buf.str (); +} + +template <class MT> octave_value octave_base_matrix<MT>::fast_elem_extract (octave_idx_type n) const {
--- a/libinterp/octave-value/ov-base-mat.h Wed Nov 06 18:00:48 2013 -0500 +++ b/libinterp/octave-value/ov-base-mat.h Wed Nov 06 19:17:59 2013 -0500 @@ -157,6 +157,8 @@ void print_info (std::ostream& os, const std::string& prefix) const; + std::string short_disp (void) const; + MT& matrix_ref (void) { clear_cached_info ();
--- a/libinterp/octave-value/ov-cell.cc Wed Nov 06 18:00:48 2013 -0500 +++ b/libinterp/octave-value/ov-cell.cc Wed Nov 06 19:17:59 2013 -0500 @@ -750,6 +750,12 @@ } } +std::string +octave_cell::short_disp (void) const +{ + return matrix.is_empty () ? "{}" : ""; +} + #define CELL_ELT_TAG "<cell-element>" bool
--- a/libinterp/octave-value/ov-cell.h Wed Nov 06 18:00:48 2013 -0500 +++ b/libinterp/octave-value/ov-cell.h Wed Nov 06 19:17:59 2013 -0500 @@ -151,6 +151,7 @@ void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; + std::string short_disp (void) const; bool save_ascii (std::ostream& os);