# HG changeset patch # User John W. Eaton # Date 1383783479 18000 # Node ID ea0ecbe2eaf543441f79be098c25b2b23550b799 # Parent dde06c2ac6c6f7db418540706eaa74797647f725 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::short_disp): New function. * ov-cell.h, ov-cell.cc (octave_cell::short_disp): New function. diff -r dde06c2ac6c6 -r ea0ecbe2eaf5 libinterp/corefcn/pr-output.cc --- 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\ diff -r dde06c2ac6c6 -r ea0ecbe2eaf5 libinterp/corefcn/pr-output.h --- 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; diff -r dde06c2ac6c6 -r ea0ecbe2eaf5 libinterp/octave-value/ov-base-mat.cc --- 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 +std::string +octave_base_matrix::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 octave_value octave_base_matrix::fast_elem_extract (octave_idx_type n) const { diff -r dde06c2ac6c6 -r ea0ecbe2eaf5 libinterp/octave-value/ov-base-mat.h --- 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 (); diff -r dde06c2ac6c6 -r ea0ecbe2eaf5 libinterp/octave-value/ov-cell.cc --- 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 "" bool diff -r dde06c2ac6c6 -r ea0ecbe2eaf5 libinterp/octave-value/ov-cell.h --- 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);