Mercurial > octave
diff libinterp/corefcn/pr-output.cc @ 24745:d2467914ce33
enable (or improve) display for more types in the variable editor
* pr-output.h, pr-output.cc (make_format): Provide versions for Range,
FloatNDArray, FloatComplexNDArray, intNDArray, double, float, Complex,
FloatComplex, and octave_int types. Use format when printing scalar
integer values.
* ov-base-diag.cc, ov-base-diag.h
(octave_base_diag<DMT, MT>::get_edit_display_format,
octave_base_diag<DMT, MT>::edit_display): Pass format to
octave_print_internal.
* ov-base-int.cc, ov-base-int.h
(octave_base_int_matrix<T>::edit_display,
octave_base_int_scalar<ST>::edit_display): New functions.
* ov-base-scalar.cc, ov-base-scalar.h
(octave_base_scalar<ST>::get_edit_display_format): New function.
(octave_base_scalar<ST>::edit_display): Pass format to
octave_print_internal.
* ov-base-sparse.cc, ov-base-sparse.h
(octave_base_sparse<MT>::get_edit_display_format,
octave_base_sparse<MT>::edit_display): New functions.
* ov-perm.cc, ov-perm.h (octave_perm_matrix::get_edit_display_format,
octave_perm_matrix::edit_display): Pass format to
octave_print_internal.
* ov-range.cc, ov-range.h (octave_range::get_edit_display_format,
octave_range::edit_display): New functions.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 13 Feb 2018 01:54:16 -0500 |
parents | 5be92b26ef8f |
children | 6114be517240 |
line wrap: on
line diff
--- a/libinterp/corefcn/pr-output.cc Mon Feb 12 16:03:18 2018 -0800 +++ b/libinterp/corefcn/pr-output.cc Tue Feb 13 01:54:16 2018 -0500 @@ -1602,6 +1602,15 @@ template <> float_display_format +make_format (const Range& rng) +{ + int fw = 0; + double scale = 0; + return make_format (rng, fw, scale); +} + +template <> +float_display_format make_format (const NDArray& nda) { int fw = 0; @@ -1611,6 +1620,15 @@ template <> float_display_format +make_format (const FloatNDArray& nda) +{ + int fw = 0; + double scale = 0; + return make_format (FloatMatrix (nda), fw, scale); +} + +template <> +float_display_format make_format (const ComplexNDArray& nda) { int r_fw = 0; @@ -1619,6 +1637,107 @@ return make_format (ComplexMatrix (nda), r_fw, i_fw, scale); } +template <> +float_display_format +make_format (const FloatComplexNDArray& nda) +{ + int r_fw = 0; + int i_fw = 0; + double scale = 0; + return make_format (FloatComplexMatrix (nda), r_fw, i_fw, scale); +} + +#define MAKE_INT_MATRIX_FORMAT(TYPE) \ + template <> \ + float_display_format \ + make_format (const intNDArray<TYPE>& nda) \ + { \ + bool isneg = false; \ + int digits = 0; \ + \ + for (octave_idx_type i = 0; i < nda.numel (); i++) \ + { \ + int new_digits \ + = static_cast<int> \ + (std::floor (log10 (double (abs (nda(i).value ()))) + 1.0)); \ + \ + if (new_digits > digits) \ + digits = new_digits; \ + \ + if (! isneg) \ + isneg = (abs (nda(i).value ()) != nda(i).value ()); \ + } \ + \ + return float_display_format (float_format (digits + isneg, 0, 0)); \ + } + +MAKE_INT_MATRIX_FORMAT (octave_int8) +MAKE_INT_MATRIX_FORMAT (octave_uint8) +MAKE_INT_MATRIX_FORMAT (octave_int16) +MAKE_INT_MATRIX_FORMAT (octave_uint16) +MAKE_INT_MATRIX_FORMAT (octave_int32) +MAKE_INT_MATRIX_FORMAT (octave_uint32) +MAKE_INT_MATRIX_FORMAT (octave_int64) +MAKE_INT_MATRIX_FORMAT (octave_uint64) + +template <> +float_display_format +make_format (const double& d) +{ + int fw = 0; + return make_format (d, fw); +} + +template <> +float_display_format +make_format (const float& f) +{ + int fw = 0; + return make_format (f, fw); +} + +template <> +float_display_format +make_format (const Complex& c) +{ + int r_fw = 0; + int i_fw = 0; + return make_format (c, r_fw, i_fw); +} + +template <> +float_display_format +make_format (const FloatComplex& c) +{ + int r_fw = 0; + int i_fw = 0; + return make_format (c, r_fw, i_fw); +} + +#define MAKE_INT_SCALAR_FORMAT(TYPE) \ + template <> \ + float_display_format \ + make_format (const octave_int<TYPE>& val) \ + { \ + bool isneg = false; \ + int digits \ + = static_cast<int> \ + (std::floor (log10 (double (abs (val.value ()))) + 1.0)); \ + \ + isneg = (abs (val.value ()) != val.value ()); \ + \ + return float_display_format (float_format (digits + isneg, 0, 0)); \ + } + +MAKE_INT_SCALAR_FORMAT (int8_t) +MAKE_INT_SCALAR_FORMAT (uint8_t) +MAKE_INT_SCALAR_FORMAT (int16_t) +MAKE_INT_SCALAR_FORMAT (uint16_t) +MAKE_INT_SCALAR_FORMAT (int32_t) +MAKE_INT_SCALAR_FORMAT (uint32_t) +MAKE_INT_SCALAR_FORMAT (int64_t) +MAKE_INT_SCALAR_FORMAT (uint64_t) + void octave_print_internal (std::ostream&, char, bool) { @@ -3033,8 +3152,9 @@ template <typename T> void -octave_print_internal_template (std::ostream& os, const octave_int<T>& val, - bool) +octave_print_internal_template (std::ostream& os, + const float_display_format& fmt, + const octave_int<T>& val, bool) { if (plus_format) { @@ -3045,15 +3165,21 @@ if (free_format) os << typename octave_print_conv<octave_int<T>>::print_conv_type (val); else - pr_int (os, val); + { + float_format r_fmt = fmt.real_format (); + + pr_int (os, val, r_fmt.fw); + } } } #define PRINT_INT_SCALAR_INTERNAL(TYPE) \ OCTINTERP_API void \ - octave_print_internal (std::ostream& os, const octave_int<TYPE>& val, bool dummy) \ + octave_print_internal (std::ostream& os, \ + const float_display_format& fmt, \ + const octave_int<TYPE>& val, bool dummy) \ { \ - octave_print_internal_template (os, val, dummy); \ + octave_print_internal_template (os, fmt, val, dummy); \ } PRINT_INT_SCALAR_INTERNAL (int8_t) @@ -3076,7 +3202,8 @@ if (nda.isempty ()) print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); else if (nda.numel () == 1) - octave_print_internal_template (os, nda(0), pr_as_read_syntax); + octave_print_internal_template (os, float_display_format (), nda(0), + pr_as_read_syntax); else if (plus_format && ! pr_as_read_syntax) { int ndims = nda.ndims ();