octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cell-array display in class


From: Oliver Heimlich
Subject: Re: cell-array display in class
Date: Thu, 30 Apr 2015 07:51:37 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.6.0

On 29.04.2015 23:38, Colin Macdonald wrote:
On 27/04/15 07:04, Oliver Heimlich wrote:
It is not so easy. First, you have to decide whether “argn” represents
coordinates of a cell-array. You could do this with a regular
expression, but can't be 100% sure.

thanks for this `argn`!

Cannot be 100% sure?  Do you have a particular counterexample?  This
seems to work for me:

I wasn't sure how cell array works internally, see below.

if (isempty(inputname(1)) && regexp(argn, '^\[\d+,\d+\]$'))
   % we're in a cell array
   ...
else
   % whatever I did before.
end

If my input was actually `display([1,2])` then it won't be my
@class/display that gets called :)

Okay, this kind of false positive can be eliminated from the list.

(Ok, needs to be a bit more complicated for all possible shapes of cell
array but that regexp gives idea.)

I looked into the code of cell array:

                  std::ostringstream buf;
                  buf << "[" << i+1 << "," << j+1 << "]";

                  octave_value val = matrix(i,j);

                  val.print_with_name (os, buf.str ());

So, the regexp should be sufficient. Cell array of higher dimensions cannot be displayed with content.

Second, you want to get access to the following variable (in ov-base.cc)
to correctly indent your output. I think there currently is no way to
access this value from within a m-file display method (unless you use an
oct-file kludge).
    int octave_base_value::curr_print_indent_level

Yes, that is unfortunate :(   I'm sure I have other things I should be
worrying about but perhaps Octave could pass to us the current indent
level as 2nd argument of display.  Thoughts?

Colin

The method's signature should stay compatible with the core functions, which check for nargin==1. Is it a good idea to pass current_print_indent_level as a global variable to the display method?

Oliver



reply via email to

[Prev in Thread] Current Thread [Next in Thread]