Mercurial > hg > octave-jordi
changeset 17870:1d2e709bbbda
rework short_disp methods
* ov.h (octave_value::short_disp): Pass std::ostream as
argument instead of returning std::string. Change all uses.
* ov-base.h (octave_base_value::short_disp): Likewise. Change all
derived classes.
* ov-base-scalar.cc (octave_base_scalar<ST>::short_disp): Strip
leading whitepace from number.
* ov-base-mat.cc (octave_base_matrix<MT>::short_disp): Strip
leading whitepace from numbers.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 07 Nov 2013 00:52:48 -0500 |
parents | e8330a9e8c78 |
children | 5ac0545fb4c0 |
files | libinterp/corefcn/symtab.cc libinterp/octave-value/ov-base-mat.cc libinterp/octave-value/ov-base-mat.h libinterp/octave-value/ov-base-scalar.cc libinterp/octave-value/ov-base-scalar.h libinterp/octave-value/ov-base.h libinterp/octave-value/ov-cell.cc libinterp/octave-value/ov-cell.h libinterp/octave-value/ov-range.cc libinterp/octave-value/ov-range.h libinterp/octave-value/ov-str-mat.cc libinterp/octave-value/ov-str-mat.h libinterp/octave-value/ov.h |
diffstat | 13 files changed, 46 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/symtab.cc +++ b/libinterp/corefcn/symtab.cc @@ -25,6 +25,8 @@ #include <config.h> #endif +#include <sstream> + #include "file-ops.h" #include "file-stat.h" #include "oct-env.h" @@ -1418,8 +1420,12 @@ else if (sr.is_inherited ()) storage = 'i'; + std::ostringstream buf; + val.short_disp (buf); + std::string short_disp_str = buf.str (); + workspace_element elt (storage, nm, val.class_name (), - val.short_disp (), dv.str (), + short_disp_str, dv.str (), val.is_complex_type ()); retval.push_back (elt);
--- a/libinterp/octave-value/ov-base-mat.cc +++ b/libinterp/octave-value/ov-base-mat.cc @@ -450,13 +450,11 @@ } template <class MT> -std::string -octave_base_matrix<MT>::short_disp (void) const +void +octave_base_matrix<MT>::short_disp (std::ostream& os) const { - std::ostringstream buf; - if (matrix.is_empty ()) - buf << "[]"; + os << "[]"; else if (matrix.ndims () == 2) { // FIXME: should this be configurable? @@ -468,32 +466,34 @@ octave_idx_type nr = matrix.rows (); octave_idx_type nc = matrix.columns (); - buf << "["; + os << "["; 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); + std::ostringstream buf; + octave_print_internal (buf, matrix(j*nr+i)); + std::string tmp = buf.str (); + size_t pos = tmp.find_first_not_of (" "); + os << tmp.substr (pos); if (++elts >= max_elts) goto done; if (j < nc - 1) - buf << ", "; + os << ", "; } if (i < nr - 1 && elts < max_elts) - buf << "; "; + os << "; "; } done: if (nel <= max_elts) - buf << "]"; + os << "]"; } - - return buf.str (); } template <class MT>
--- a/libinterp/octave-value/ov-base-mat.h +++ b/libinterp/octave-value/ov-base-mat.h @@ -157,7 +157,7 @@ void print_info (std::ostream& os, const std::string& prefix) const; - std::string short_disp (void) const; + void short_disp (std::ostream& os) const; MT& matrix_ref (void) {
--- a/libinterp/octave-value/ov-base-scalar.cc +++ b/libinterp/octave-value/ov-base-scalar.cc @@ -169,12 +169,14 @@ } template <class ST> -std::string -octave_base_scalar<ST>::short_disp (void) const +void +octave_base_scalar<ST>::short_disp (std::ostream& os) const { std::ostringstream buf; - octave_print_internal (buf, scalar, true); - return buf.str (); + octave_print_internal (buf, scalar); + std::string tmp = buf.str (); + size_t pos = tmp.find_first_not_of (" "); + os << tmp.substr (pos); } template <class ST>
--- a/libinterp/octave-value/ov-base-scalar.h +++ b/libinterp/octave-value/ov-base-scalar.h @@ -138,7 +138,7 @@ bool print_name_tag (std::ostream& os, const std::string& name) const; - std::string short_disp (void) const; + void short_disp (std::ostream& os) const; // Unsafe. This function exists to support the MEX interface. // You should not use it anywhere else.
--- a/libinterp/octave-value/ov-base.h +++ b/libinterp/octave-value/ov-base.h @@ -618,7 +618,7 @@ print_with_name (std::ostream& output_buf, const std::string& name, bool print_padding = true); - virtual std::string short_disp (void) const { return "..."; } + virtual void short_disp (std::ostream& os) const { os << "..."; } virtual void print_info (std::ostream& os, const std::string& prefix) const;
--- a/libinterp/octave-value/ov-cell.cc +++ b/libinterp/octave-value/ov-cell.cc @@ -750,10 +750,10 @@ } } -std::string -octave_cell::short_disp (void) const +void +octave_cell::short_disp (std::ostream& os) const { - return matrix.is_empty () ? "{}" : ""; + os << matrix.is_empty () ? "{}" : "..."; } #define CELL_ELT_TAG "<cell-element>"
--- a/libinterp/octave-value/ov-cell.h +++ b/libinterp/octave-value/ov-cell.h @@ -151,7 +151,7 @@ void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; - std::string short_disp (void) const; + void short_disp (std::ostream& os) const; bool save_ascii (std::ostream& os);
--- a/libinterp/octave-value/ov-range.cc +++ b/libinterp/octave-value/ov-range.cc @@ -388,29 +388,25 @@ return retval; } -std::string -octave_range::short_disp (void) const +void +octave_range::short_disp (std::ostream& os) const { - std::ostringstream buf; - octave_idx_type len = range.nelem (); if (len == 0) - buf << "[]"; + os << "[]"; else { - buf << range.base () << ":"; + os << range.base () << ":"; if (len > 1) { if (range.inc () != 1) - buf << range.inc () << ":"; + os << range.inc () << ":"; - buf << range.limit (); + os << range.limit (); } } - - return buf.str (); } // Skip white space and comments on stream IS.
--- a/libinterp/octave-value/ov-range.h +++ b/libinterp/octave-value/ov-range.h @@ -255,7 +255,7 @@ bool print_name_tag (std::ostream& os, const std::string& name) const; - std::string short_disp (void) const; + void short_disp (std::ostream& os) const; bool save_ascii (std::ostream& os);
--- a/libinterp/octave-value/ov-str-mat.cc +++ b/libinterp/octave-value/ov-str-mat.cc @@ -270,25 +270,20 @@ current_print_indent_level (), true); } -std::string -octave_char_matrix_str::short_disp (void) const +void +octave_char_matrix_str::short_disp (std::ostream& os) const { - std::string retval; - if (matrix.ndims () == 2 && numel () > 0) { - retval = string_value (); + std::string tmp = string_value (); // FIXME: should this be configurable? + size_t max_len = 100; - if (retval.length () > 100) - retval = retval.substr (0, 100); + os << (tmp.length () > max_len) ? tmp.substr (0, 100) : tmp; } - - return retval; } - bool octave_char_matrix_str::save_ascii (std::ostream& os) {
--- a/libinterp/octave-value/ov-str-mat.h +++ b/libinterp/octave-value/ov-str-mat.h @@ -142,7 +142,7 @@ void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; - std::string short_disp (void) const; + void short_disp (std::ostream& os) const; bool save_ascii (std::ostream& os);
--- a/libinterp/octave-value/ov.h +++ b/libinterp/octave-value/ov.h @@ -1027,7 +1027,7 @@ void print_with_name (std::ostream& os, const std::string& name) const { rep->print_with_name (os, name, true); } - std::string short_disp (void) const { return rep->short_disp (); } + void short_disp (std::ostream& os) const { rep->short_disp (os); } int type_id (void) const { return rep->type_id (); }