Mercurial > hg > octave-nkf
changeset 11474:8a40037533e2
struct printing changes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 10 Jan 2011 14:05:12 -0500 |
parents | 44032aac5223 |
children | caf1fd72f587 |
files | doc/ChangeLog doc/interpreter/container.txi src/ChangeLog src/ov-cell.cc src/ov-class.cc src/ov-struct.cc src/pr-output.cc src/pr-output.h |
diffstat | 8 files changed, 91 insertions(+), 82 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2011-01-10 John W. Eaton <jwe@octave.org> + + * interpreter/container.txi (Basic Usage and Examples): + Document print_struct_array_contents. + 2011-01-05 Rik <octave@nomad.inbox5.com> * interpreter/octave.texi: Put statistics detailmenu in correct order.
--- a/doc/interpreter/container.txi +++ b/doc/interpreter/container.txi @@ -159,11 +159,15 @@ @noindent This prevents long and confusing output from large deeply nested -structures. The number of levels to print for nested structures can be -set with the function @code{struct_levels_to_print}: +structures. The number of levels to print for nested structures may be +set with the function @code{struct_levels_to_print}, and the function +@code{print_struct_array_contents} may be used to enable printing of the +contents of structure arrays. @DOCSTRING(struct_levels_to_print) +@DOCSTRING(print_struct_array_contents) + Functions can return structures. For example, the following function separates the real and complex parts of a matrix and stores them in two elements of the same structure variable.
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,18 @@ +2011-01-10 John W. Eaton <jwe@octave.org> + + * ov-cell.cc (octave_cell::print_as_scalar): Always return true. + (octave_cell::print_raw): Handle extra newlines here. + * ov-struct.cc (Fstruct_levels_to_print): Move here from pr-output.cc + (Vstruct_levels_to_print): Move here from pr-output.cc. Now static. + (Vprint_struct_array_contents): New static variable. + (Fprint_struct_array_contents): New function. + (octave_struct::print_raw): Use Vprint_struct_array_contents. + Simplify and improve output. + (octave_scalar_struct::print_raw): Simplify and improve output. + * pr-output.h (Vstruct_levels_to_print): Delete decl. + * ov-class.cc (octave_class::print_raw): Don't unwind_protect + Vstruct_levels_to_print. + 2011-01-09 David Bateman <dbateman@free.fr> * ls-mat5.cc (save_mat5_array_length (const float*, octave_idx_type,
--- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -678,7 +678,7 @@ bool octave_cell::print_as_scalar (void) const { - return (ndims () > 2 || numel () == 0); + return true; } void @@ -699,6 +699,7 @@ if (nr > 0 && nc > 0) { + newline (os); indent (os); os << "{"; newline (os);
--- a/src/ov-class.cc +++ b/src/ov-class.cc @@ -956,8 +956,6 @@ { unwind_protect frame; - frame.protect_var (Vstruct_levels_to_print); - indent (os); os << " <class " << class_name () << ">"; newline (os);
--- a/src/ov-struct.cc +++ b/src/ov-struct.cc @@ -51,6 +51,13 @@ DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(octave_struct, "struct", "struct"); +// How many levels of structure elements should we print? +static int Vstruct_levels_to_print = 2; + +// TRUE means print struct array contents, up to the number of levels +// specified by struct_levels_to_print. +static bool Vprint_struct_array_contents = false; + octave_base_value * octave_struct::try_narrowing_conversion (void) { @@ -601,26 +608,20 @@ if (Vstruct_levels_to_print >= 0) { - bool print_keys_only = Vstruct_levels_to_print-- == 0; + bool max_depth_reached = Vstruct_levels_to_print-- == 0; - indent (os); - os << "{"; - newline (os); + bool print_fieldnames_only + = (max_depth_reached || ! Vprint_struct_array_contents); increment_indent_level (); - octave_idx_type n = map.numel (); + newline (os); + indent (os); + dim_vector dv = dims (); + os << dv.str () << " struct array containing the fields:"; + newline (os); - if (n != 1 || print_keys_only) - { - indent (os); - dim_vector dv = dims (); - os << dv.str () << " struct array containing the fields:"; - newline (os); - newline (os); - - increment_indent_level (); - } + increment_indent_level (); string_vector key_list = map.fieldnames (); @@ -630,31 +631,25 @@ Cell val = map.contents (key); - octave_value tmp = (n == 1) ? val(0) : octave_value (val, true); + newline (os); - if (n != 1 || print_keys_only) + if (print_fieldnames_only) { indent (os); os << key; - if (n == 1) - { - dim_vector dv = tmp.dims (); - os << ": " << dv.str () << " " << tmp.type_name (); - } - newline (os); } else - tmp.print_with_name (os, key); + { + octave_value tmp (val); + tmp.print_with_name (os, key); + } } - if (n != 1 || print_keys_only) - decrement_indent_level (); + if (print_fieldnames_only) + newline (os); decrement_indent_level (); - - indent (os); - os << "}"; - newline (os); + decrement_indent_level (); } else { @@ -1323,26 +1318,19 @@ if (Vstruct_levels_to_print >= 0) { - bool print_keys_only = Vstruct_levels_to_print-- == 0; + bool max_depth_reached = Vstruct_levels_to_print-- == 0; - indent (os); - os << "{"; - newline (os); + bool print_fieldnames_only = max_depth_reached; increment_indent_level (); - octave_idx_type n = 1; + newline (os); + indent (os); + os << "scalar structure containing the fields:"; + newline (os); + newline (os); - if (n != 1 || print_keys_only) - { - indent (os); - dim_vector dv = dims (); - os << dv.str () << " struct array containing the fields:"; - newline (os); - newline (os); - - increment_indent_level (); - } + increment_indent_level (); string_vector key_list = map.fieldnames (); @@ -1352,31 +1340,22 @@ Cell val = map.contents (key); - octave_value tmp = (n == 1) ? val(0) : octave_value (val, true); + octave_value tmp = val(0); - if (n != 1 || print_keys_only) + if (print_fieldnames_only) { indent (os); os << key; - if (n == 1) - { - dim_vector dv = tmp.dims (); - os << ": " << dv.str () << " " << tmp.type_name (); - } + dim_vector dv = tmp.dims (); + os << ": " << dv.str () << " " << tmp.type_name (); newline (os); } else tmp.print_with_name (os, key); } - if (n != 1 || print_keys_only) - decrement_indent_level (); - decrement_indent_level (); - - indent (os); - os << "}"; - newline (os); + decrement_indent_level (); } else { @@ -2194,3 +2173,28 @@ %! assert (size (y), [1, 6]); */ +DEFUN (struct_levels_to_print, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} struct_levels_to_print ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} struct_levels_to_print (@var{new_val})\n\ +Query or set the internal variable that specifies the number of\n\ +structure levels to display.\n\ +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE_WITH_LIMITS (struct_levels_to_print, + -1, INT_MAX); +} + +DEFUN (print_struct_array_contents, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} print_struct_array_contents ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} print_struct_array_contents (@var{new_val})\n\ +Query or set the internal variable that specifies whether to print struct\n\ +array contents. If true, values of struct array elements are printed.\n\ +This variable does not affect scalar structures. Their elements\n\ +are always printed. In both cases, however, printing will be limited to\n\ +the number of levels specified by @var{struct_levels_to_print}.\n\ +@end deftypefn") +{ + return SET_INTERNAL_VARIABLE (print_struct_array_contents); +}
--- a/src/pr-output.cc +++ b/src/pr-output.cc @@ -79,9 +79,6 @@ // smaller slices that fit on the screen. static bool Vsplit_long_rows = true; -// How many levels of structure elements should we print? -int Vstruct_levels_to_print = 2; - // TRUE means don't do any fancy formatting. static bool free_format = false; @@ -4028,15 +4025,3 @@ { return SET_INTERNAL_VARIABLE_WITH_LIMITS (output_precision, -1, INT_MAX); } - -DEFUN (struct_levels_to_print, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {@var{val} =} struct_levels_to_print ()\n\ -@deftypefnx {Built-in Function} {@var{old_val} =} struct_levels_to_print (@var{new_val})\n\ -Query or set the internal variable that specifies the number of\n\ -structure levels to display.\n\ -@end deftypefn") -{ - return SET_INTERNAL_VARIABLE_WITH_LIMITS (struct_levels_to_print, - -1, INT_MAX); -}