Mercurial > octave
changeset 26749:2c4ad1958cab
display property names and info by default for classdef objects
* ov-classdef.cc (octave_classdef::print_raw):
Display property names and info.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 20 Feb 2019 19:40:11 +0000 |
parents | a3dfdbb9d8c5 |
children | a89aa5b95a59 |
files | libinterp/octave-value/ov-classdef.cc |
diffstat | 1 files changed, 45 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-classdef.cc Tue Feb 19 21:33:23 2019 +0000 +++ b/libinterp/octave-value/ov-classdef.cc Wed Feb 20 19:40:11 2019 +0000 @@ -25,6 +25,7 @@ #endif #include <algorithm> +#include <iomanip> #include "call-stack.h" #include "defun.h" @@ -1018,12 +1019,50 @@ void octave_classdef::print_raw (std::ostream& os, bool) const { - indent (os); - os << "<object "; - if (object.is_array ()) - os << "array "; - os << class_name () << '>'; - newline (os); + cdef_class cls = object.get_class (); + + if (cls.ok ()) + { + indent (os); + os << class_name () << " object"; + if (object.is_array ()) + os << " array"; + os << " with properties:"; + newline (os); + newline (os); + + std::map<std::string, cdef_property> props; + + props = cls.get_property_map (); + + size_t max_len = 0; + for (const auto& nm_prop : props) + { + const std::string& nm = nm_prop.first; + + size_t sz = nm.size (); + + if (sz > max_len) + max_len = sz; + } + + for (auto& nm_prop : props) + { + const std::string& nm = nm_prop.first; + cdef_property& prop = nm_prop.second; + octave_value val = prop.get_value (object, false); + dim_vector dims = val.dims (); + + os << std::setw (max_len+2) << nm << ": "; + if (val.is_string ()) + os << val.string_value (); + else if (val.islogical ()) + os << val.bool_value (); + else + os << "[" << dims.str () << " " << val.class_name () << "]"; + newline (os); + } + } } bool