Mercurial > octave-nkf
changeset 18416:bcd71a2531d3
Support disp/display overloading in classdef
* ov-classdef.h (octave_classdef::print, octave_classdef::print_raw):
Move definition to C++ file.
(octave_classdef::print_as_scalar): Removed method.
(octave_classdef::print_name_tag, octave_classdef::print_with_name):
New methods.
* ov-classdef.cc (octave_classdef::print): Moved from header.
(octave_classdef::print_raw): Likewise. Call overloaded disp, if
defined and not called from builtin.
(octave_classdef::print_name_tag): New method.
(octave_classdef::print_with_name): New method, calls overloaded
"display" if defined.
* pr-output.cc (octave_print_internal(std::ostream, bool): Avoid
compilation warning.
(Frats, Fdisp, Ffdisp): Allow to call non-const octave_value::print.
* ov.h (octave_value::print): Make non-const.
* ov-base.h (octave_base_value::print): Likewise.
* ov-base.cc (octave_base_value::print): Likewise.
* ov-base-diag.h (octave_base_diag::print): Likewise.
* ov-base-diag.cc (octave_base_diag::print): Likewise.
* ov-base-mat.h (octave_base_matrix::print): Likewise.
* ov-base-mat.cc (octave_base_matrix::print): Likewise.
* ov-base-scalar.h (octave_base_scalar::print): Likewise.
* ov-base-scalar.cc (octave_base_scalar::print): Likewise.
* ov-base-sparse.h (octave_base_sparse::print): Likewise.
* ov-base-sparse.cc (octave_base_sparse::print): Likewise.
* ov-cell.h (octave_cell::print): Likewise.
* ov-cell.cc (octave_cell::print): Likewise.
* ov-class.h (octave_class::print): Likewise.
* ov-class.cc (octave_class::print): Likewise.
* ov-colon.h (octave_magic_colon::print): Likewise.
* ov-colon.cc (octave_magic_colon::print): Likewise.
* ov-fcn-handle.h (octave_fcn_handle::print): Likewise.
* ov-fcn-handle.cc (octave_fcn_handle::print): Likewise.
* ov-fcn-inline.h (octave_fcn_inline::print): Likewise.
* ov-fcn-inline.cc (octave_fcn_inline::print): Likewise.
* ov-java.h (octave_java::print): Likewise.
* ov-java.cc (octave_java::print): Likewise.
* ov-lazy-idx.h (octave_lazy_index::print): Likewise.
* ov-oncleanup.h (octave_oncleanup::print): Likewise.
* ov-oncleanup.cc (octave_oncleanup::print): Likewise.
* ov-perm.h (octave_perm_matrix::print): Likewise.
* ov-perm.cc (octave_perm_matrix::print): Likewise.
* ov-range.h (octave_range::print): Likewise.
* ov-range.cc (octave_range::print): Likewise.
* ov-struct.h (octave_struct::print, octave_scalar_struct): Likewise.
* ov-struct.cc (octave_struct::print, octave_scalar_struct): Likewise.
line wrap: on
line diff
--- a/libinterp/corefcn/pr-output.cc Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/corefcn/pr-output.cc Fri Jan 31 11:41:19 2014 -0500 @@ -3387,8 +3387,7 @@ } void -octave_print_internal (std::ostream&, const octave_value&, - bool pr_as_read_syntax) +octave_print_internal (std::ostream&, const octave_value&, bool) { panic_impossible (); } @@ -3439,7 +3438,7 @@ rat_format = true; std::ostringstream buf; - args(0).print (buf); + arg.print (buf); std::string s = buf.str (); std::list<std::string> lst; @@ -3501,11 +3500,12 @@ if (nargin == 1 && nargout < 2) { + octave_value arg = args(0); + if (nargout == 0) - args(0).print (octave_stdout); + arg.print (octave_stdout); else { - octave_value arg = args(0); std::ostringstream buf; arg.print (buf); retval = octave_value (buf.str (), arg.is_dq_string () ? '"' : '\''); @@ -3550,8 +3550,10 @@ { std::ostream *osp = os.output_stream (); + octave_value arg = args(1); + if (osp) - args(1).print (*osp); + arg.print (*osp); else error ("fdisp: stream FID not open for writing"); }
--- a/libinterp/octave-value/ov-base-diag.cc Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-base-diag.cc Fri Jan 31 11:41:19 2014 -0500 @@ -506,8 +506,7 @@ template <class DMT, class MT> void -octave_base_diag<DMT, MT>::print (std::ostream& os, - bool pr_as_read_syntax) const +octave_base_diag<DMT, MT>::print (std::ostream& os, bool pr_as_read_syntax) { print_raw (os, pr_as_read_syntax); newline (os);
--- a/libinterp/octave-value/ov-base-diag.h Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-base-diag.h Fri Jan 31 11:41:19 2014 -0500 @@ -203,7 +203,7 @@ bool print_as_scalar (void) const; - void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print (std::ostream& os, bool pr_as_read_syntax = false); void print_info (std::ostream& os, const std::string& prefix) const;
--- a/libinterp/octave-value/ov-base-mat.cc Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-base-mat.cc Fri Jan 31 11:41:19 2014 -0500 @@ -436,7 +436,7 @@ template <class MT> void -octave_base_matrix<MT>::print (std::ostream& os, bool pr_as_read_syntax) const +octave_base_matrix<MT>::print (std::ostream& os, bool pr_as_read_syntax) { print_raw (os, pr_as_read_syntax); newline (os);
--- a/libinterp/octave-value/ov-base-mat.h Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-base-mat.h Fri Jan 31 11:41:19 2014 -0500 @@ -153,7 +153,7 @@ bool print_as_scalar (void) const; - void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print (std::ostream& os, bool pr_as_read_syntax = false); void print_info (std::ostream& os, const std::string& prefix) const;
--- a/libinterp/octave-value/ov-base-scalar.cc Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-base-scalar.cc Fri Jan 31 11:41:19 2014 -0500 @@ -143,7 +143,7 @@ template <class ST> void -octave_base_scalar<ST>::print (std::ostream& os, bool pr_as_read_syntax) const +octave_base_scalar<ST>::print (std::ostream& os, bool pr_as_read_syntax) { print_raw (os, pr_as_read_syntax); newline (os);
--- a/libinterp/octave-value/ov-base-scalar.h Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-base-scalar.h Fri Jan 31 11:41:19 2014 -0500 @@ -132,7 +132,7 @@ bool is_true (void) const; - void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print (std::ostream& os, bool pr_as_read_syntax = false); void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
--- a/libinterp/octave-value/ov-base-sparse.cc Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-base-sparse.cc Fri Jan 31 11:41:19 2014 -0500 @@ -288,7 +288,7 @@ template <class T> void -octave_base_sparse<T>::print (std::ostream& os, bool pr_as_read_syntax) const +octave_base_sparse<T>::print (std::ostream& os, bool pr_as_read_syntax) { print_raw (os, pr_as_read_syntax); newline (os);
--- a/libinterp/octave-value/ov-base-sparse.h Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-base-sparse.h Fri Jan 31 11:41:19 2014 -0500 @@ -147,7 +147,7 @@ bool print_as_scalar (void) const; - void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print (std::ostream& os, bool pr_as_read_syntax = false); void print_info (std::ostream& os, const std::string& prefix) const;
--- a/libinterp/octave-value/ov-base.cc Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-base.cc Fri Jan 31 11:41:19 2014 -0500 @@ -397,7 +397,7 @@ } void -octave_base_value::print (std::ostream&, bool) const +octave_base_value::print (std::ostream&, bool) { gripe_wrong_type_arg ("octave_base_value::print ()", type_name ()); }
--- a/libinterp/octave-value/ov-base.h Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-base.h Fri Jan 31 11:41:19 2014 -0500 @@ -606,7 +606,7 @@ virtual bool print_as_scalar (void) const { return false; } - virtual void print (std::ostream& os, bool pr_as_read_syntax = false) const; + virtual void print (std::ostream& os, bool pr_as_read_syntax = false); virtual void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
--- a/libinterp/octave-value/ov-cell.cc Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-cell.cc Fri Jan 31 11:41:19 2014 -0500 @@ -687,7 +687,7 @@ } void -octave_cell::print (std::ostream& os, bool) const +octave_cell::print (std::ostream& os, bool) { print_raw (os); }
--- a/libinterp/octave-value/ov-cell.h Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-cell.h Fri Jan 31 11:41:19 2014 -0500 @@ -147,7 +147,7 @@ bool print_as_scalar (void) const; - void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print (std::ostream& os, bool pr_as_read_syntax = false); void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
--- a/libinterp/octave-value/ov-class.cc Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-class.cc Fri Jan 31 11:41:19 2014 -0500 @@ -1045,7 +1045,7 @@ void -octave_class::print (std::ostream& os, bool) const +octave_class::print (std::ostream& os, bool) { print_raw (os); }
--- a/libinterp/octave-value/ov-class.h Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-class.h Fri Jan 31 11:41:19 2014 -0500 @@ -169,7 +169,7 @@ string_vector all_strings (bool pad) const; - void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print (std::ostream& os, bool pr_as_read_syntax = false); void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
--- a/libinterp/octave-value/ov-classdef.cc Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-classdef.cc Fri Jan 31 11:41:19 2014 -0500 @@ -1018,6 +1018,73 @@ return octave_value (); } +void +octave_classdef::print (std::ostream& os, bool) +{ + if (! called_from_builtin ()) + { + cdef_method meth = object.get_class ().find_method ("disp"); + + if (meth.ok ()) + { + octave_value_list args; + + count++; + args(0) = octave_value (this); + + indent (os); + meth.execute (args, 0, true, "disp"); + + return; + } + } + + print_raw (os); +} + +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); +} + +bool +octave_classdef::print_name_tag (std::ostream& os, + const std::string& name) const +{ + return octave_base_value::print_name_tag (os, name); +} + +void +octave_classdef::print_with_name (std::ostream& os, const std::string& name, + bool print_padding) +{ + cdef_method meth = object.get_class ().find_method ("display"); + + if (meth.ok ()) + { + octave_value_list args; + + count++; + args(0) = octave_value (this); + + string_vector arg_names (1); + + arg_names[0] = name; + args.stash_name_tags (arg_names); + + indent (os); + meth.execute (args, 0, true, "display"); + } + else + octave_base_value::print_with_name (os, name, print_padding); +} + //---------------------------------------------------------------------------- class octave_classdef_meta : public octave_function
--- a/libinterp/octave-value/ov-classdef.h Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-classdef.h Fri Jan 31 11:41:19 2014 -0500 @@ -1413,26 +1413,18 @@ bool is_object (void) const { return true; } - bool print_as_scalar (void) const { return true; } + void print (std::ostream& os, bool pr_as_read_syntax = false); - void print(std::ostream& os, bool pr_as_read_syntax = false) const - { - // FIXME: should call "display" method - print_raw(os, pr_as_read_syntax); - newline(os); - } + void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; - void print_raw(std::ostream& os, bool /* pr_as_read_syntax */ = false) const - { - if (object.is_array ()) - os << "array (" << object.dims ().str () << ") of " - << object.class_name () << " objects"; - else - os << object.class_name () << " object"; - } + bool print_name_tag (std::ostream& os, const std::string& name) const; + + void print_with_name (std::ostream& os, const std::string& name, + bool print_padding = true); octave_value_list subsref (const std::string& type, - const std::list<octave_value_list>& idx, int nargout); + const std::list<octave_value_list>& idx, + int nargout); octave_value subsref (const std::string& type, const std::list<octave_value_list>& idx)
--- a/libinterp/octave-value/ov-colon.cc Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-colon.cc Fri Jan 31 11:41:19 2014 -0500 @@ -35,7 +35,7 @@ "magic-colon", "magic-colon"); void -octave_magic_colon::print (std::ostream& os, bool) const +octave_magic_colon::print (std::ostream& os, bool) { indent (os); print_raw (os);
--- a/libinterp/octave-value/ov-colon.h Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-colon.h Fri Jan 31 11:41:19 2014 -0500 @@ -67,7 +67,7 @@ bool is_magic_colon (void) const { return true; } - void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print (std::ostream& os, bool pr_as_read_syntax = false); void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
--- a/libinterp/octave-value/ov-fcn-handle.cc Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-fcn-handle.cc Fri Jan 31 11:41:19 2014 -0500 @@ -1387,7 +1387,7 @@ */ void -octave_fcn_handle::print (std::ostream& os, bool pr_as_read_syntax) const +octave_fcn_handle::print (std::ostream& os, bool pr_as_read_syntax) { print_raw (os, pr_as_read_syntax); newline (os);
--- a/libinterp/octave-value/ov-fcn-handle.h Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-fcn-handle.h Fri Jan 31 11:41:19 2014 -0500 @@ -153,7 +153,7 @@ bool load_hdf5 (hid_t loc_id, const char *name); #endif - void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print (std::ostream& os, bool pr_as_read_syntax = false); void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
--- a/libinterp/octave-value/ov-fcn-inline.cc Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-fcn-inline.cc Fri Jan 31 11:41:19 2014 -0500 @@ -598,7 +598,7 @@ #endif void -octave_fcn_inline::print (std::ostream& os, bool pr_as_read_syntax) const +octave_fcn_inline::print (std::ostream& os, bool pr_as_read_syntax) { print_raw (os, pr_as_read_syntax); newline (os);
--- a/libinterp/octave-value/ov-fcn-inline.h Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-fcn-inline.h Fri Jan 31 11:41:19 2014 -0500 @@ -86,7 +86,7 @@ bool load_hdf5 (hid_t loc_id, const char *name); #endif - void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print (std::ostream& os, bool pr_as_read_syntax = false); void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
--- a/libinterp/octave-value/ov-java.cc Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-java.cc Fri Jan 31 11:41:19 2014 -0500 @@ -1762,7 +1762,7 @@ } void -octave_java::print (std::ostream& os, bool) const +octave_java::print (std::ostream& os, bool) { print_raw (os); newline (os);
--- a/libinterp/octave-value/ov-java.h Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-java.h Fri Jan 31 11:41:19 2014 -0500 @@ -149,7 +149,7 @@ dim_vector dims (void) const; - void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print (std::ostream& os, bool pr_as_read_syntax = false); void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
--- a/libinterp/octave-value/ov-lazy-idx.h Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-lazy-idx.h Fri Jan 31 11:41:19 2014 -0500 @@ -128,7 +128,7 @@ bool print_as_scalar (void) const { return make_value ().print_as_scalar (); } - void print (std::ostream& os, bool pr_as_read_syntax = false) const + void print (std::ostream& os, bool pr_as_read_syntax = false) { make_value ().print (os, pr_as_read_syntax); } void print_info (std::ostream& os, const std::string& prefix) const
--- a/libinterp/octave-value/ov-oncleanup.cc Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-oncleanup.cc Fri Jan 31 11:41:19 2014 -0500 @@ -170,7 +170,7 @@ #endif void -octave_oncleanup::print (std::ostream& os, bool pr_as_read_syntax) const +octave_oncleanup::print (std::ostream& os, bool pr_as_read_syntax) { print_raw (os, pr_as_read_syntax); newline (os);
--- a/libinterp/octave-value/ov-oncleanup.h Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-oncleanup.h Fri Jan 31 11:41:19 2014 -0500 @@ -87,7 +87,7 @@ bool load_hdf5 (hid_t loc_id, const char *name); #endif - void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print (std::ostream& os, bool pr_as_read_syntax = false); void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
--- a/libinterp/octave-value/ov-perm.cc Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-perm.cc Fri Jan 31 11:41:19 2014 -0500 @@ -389,7 +389,7 @@ } void -octave_perm_matrix::print (std::ostream& os, bool pr_as_read_syntax) const +octave_perm_matrix::print (std::ostream& os, bool pr_as_read_syntax) { print_raw (os, pr_as_read_syntax); newline (os);
--- a/libinterp/octave-value/ov-perm.h Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-perm.h Fri Jan 31 11:41:19 2014 -0500 @@ -211,7 +211,7 @@ bool print_as_scalar (void) const; - void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print (std::ostream& os, bool pr_as_read_syntax = false); void print_info (std::ostream& os, const std::string& prefix) const;
--- a/libinterp/octave-value/ov-range.cc Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-range.cc Fri Jan 31 11:41:19 2014 -0500 @@ -352,7 +352,7 @@ } void -octave_range::print (std::ostream& os, bool pr_as_read_syntax) const +octave_range::print (std::ostream& os, bool pr_as_read_syntax) { print_raw (os, pr_as_read_syntax); newline (os);
--- a/libinterp/octave-value/ov-range.h Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-range.h Fri Jan 31 11:41:19 2014 -0500 @@ -249,7 +249,7 @@ octave_value convert_to_str_internal (bool pad, bool force, char type) const; - void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print (std::ostream& os, bool pr_as_read_syntax = false); void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
--- a/libinterp/octave-value/ov-struct.cc Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-struct.cc Fri Jan 31 11:41:19 2014 -0500 @@ -648,7 +648,7 @@ } void -octave_struct::print (std::ostream& os, bool) const +octave_struct::print (std::ostream& os, bool) { print_raw (os); } @@ -1359,7 +1359,7 @@ } void -octave_scalar_struct::print (std::ostream& os, bool) const +octave_scalar_struct::print (std::ostream& os, bool) { print_raw (os); }
--- a/libinterp/octave-value/ov-struct.h Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov-struct.h Fri Jan 31 11:41:19 2014 -0500 @@ -126,7 +126,7 @@ string_vector map_keys (void) const { return map.fieldnames (); } - void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print (std::ostream& os, bool pr_as_read_syntax = false); void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; @@ -249,7 +249,7 @@ string_vector map_keys (void) const { return map.fieldnames (); } - void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print (std::ostream& os, bool pr_as_read_syntax = false); void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
--- a/libinterp/octave-value/ov.h Thu Jan 30 17:56:43 2014 -0800 +++ b/libinterp/octave-value/ov.h Fri Jan 31 11:41:19 2014 -0500 @@ -1017,7 +1017,7 @@ bool print_as_scalar (void) const { return rep->print_as_scalar (); } - void print (std::ostream& os, bool pr_as_read_syntax = false) const + void print (std::ostream& os, bool pr_as_read_syntax = false) { rep->print (os, pr_as_read_syntax); } void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const