Mercurial > hg > octave-nkf
diff src/graphics.cc @ 13210:d0f9d7353ee5
return get(h) as a struct array when h is a vector of handles
* graphics.cc (get_graphics_object_type): New function.
(Fget): Use it. Return struct array instead of cell array of scalar
structures when argument is a vector of graphics handles.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 24 Sep 2011 17:27:53 -0400 |
parents | e81ddf9cacd5 |
children | 78744376463a |
line wrap: on
line diff
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -45,6 +45,7 @@ #include "graphics.h" #include "input.h" #include "ov.h" +#include "oct-locbuf.h" #include "oct-obj.h" #include "oct-map.h" #include "ov-fcn-handle.h" @@ -7121,6 +7122,21 @@ return retval; } +static std::string +get_graphics_object_type (const double val) +{ + std::string retval; + + graphics_object obj = gh_manager::get_object (val); + + if (obj) + retval = obj.type (); + else + error ("get: invalid handle (= %g)", val); + + return retval; +} + DEFUN (get, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} get (@var{h}, @var{p})\n\ @@ -7154,31 +7170,57 @@ vals.resize (dim_vector (len, 1)); - for (octave_idx_type n = 0; n < len; n++) + if (nargin == 1 && len > 1) { - graphics_object obj = gh_manager::get_object (hcv(n)); - - if (obj) + std::string t0 = get_graphics_object_type (hcv(0)); + + if (! error_state) { - if (nargin == 1) - vals(n) = obj.get (); - else + for (octave_idx_type n = 1; n < len; n++) { - caseless_str property = args(1).string_value (); - - if (! error_state) - vals(n) = obj.get (property); - else + std::string t = get_graphics_object_type (hcv(n)); + + if (error_state) + break; + + if (t != t0) { - error ("get: expecting property name as second argument"); + error ("get: vector of handles must all have same type"); break; } } + } - else + } + + if (! error_state) + { + for (octave_idx_type n = 0; n < len; n++) { - error ("get: invalid handle (= %g)", hcv(n)); - break; + graphics_object obj = gh_manager::get_object (hcv(n)); + + if (obj) + { + if (nargin == 1) + vals(n) = obj.get (); + else + { + caseless_str property = args(1).string_value (); + + if (! error_state) + vals(n) = obj.get (property); + else + { + error ("get: expecting property name as second argument"); + break; + } + } + } + else + { + error ("get: invalid handle (= %g)", hcv(n)); + break; + } } } } @@ -7196,6 +7238,15 @@ retval = Matrix (); else if (len == 1) retval = vals(0); + else if (len > 1 && nargin == 1) + { + OCTAVE_LOCAL_BUFFER (octave_scalar_map, tmp, len); + + for (octave_idx_type n = 0; n < len; n++) + tmp[n] = vals(n).scalar_map_value (); + + retval = octave_map::cat (0, len, tmp); + } else retval = vals; }