Mercurial > hg > octave-terminal
changeset 12597:e12a7c0a1fc5 stable
getappdata.m: If no property name is provided, return a structure representing the appdata.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Tue, 12 Apr 2011 18:50:20 -0400 |
parents | 5161d02c96b7 |
children | b1913cd27f76 |
files | scripts/ChangeLog scripts/miscellaneous/getappdata.m |
diffstat | 2 files changed, 31 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2011-04-12 Ben Abbott <bpabbott@mac.com> + + * miscellaneous/getappdata.m: If no property name is provided, return + a structure representing the appdata. + 2011-04-12 Marco Caliari <marco.caliari@univr.it> * general/quadgk.m: Fix problem with -Inf bound on integral (bug
--- a/scripts/miscellaneous/getappdata.m +++ b/scripts/miscellaneous/getappdata.m @@ -18,6 +18,9 @@ ## @deftypefn {Function File} {@var{value} =} getappdata (@var{h}, @var{name}) ## Return the @var{value} for named application data for the object(s) with ## handle(s) @var{h}. +## @deftypefnx {Function File} {@var{appdata} =} getappdata (@var{h}) +## Returns a structure, @var{appdata}, whose fields correspond to the appdata +## properties. ## @end deftypefn ## Author: Ben Abbott <bpabbott@mac.com> @@ -25,25 +28,31 @@ function val = getappdata (h, name) - if (! (all (ishandle (h)) && ischar (name))) + if (all (ishandle (h)) && nargin == 2 && ischar (name)) + ## FIXME - Is there a better way to handle non-existent appdata + ## and missing fields? + val = cell (numel (h), 1); + appdata = struct(); + for nh = 1:numel(h) + try + appdata = get (h(nh), "__appdata__"); + catch + appdata.(name) = []; + end_try_catch + val(nh) = {appdata.(name)}; + end + if (nh == 1) + val = val{1}; + endif + elseif (ishandle (h) && numel (h) == 1 && nargin == 1) + try + val = get (h, "__appdata__"); + catch + val = struct (); + end_try_catch + else error ("getappdata: invalid input"); endif - ## FIXME - Is there a better way to handle non-existent appdata - ## and missing fields? - val = cell (numel (h), 1); - appdata = struct(); - for nh = 1:numel(h) - try - appdata = get (h(nh), "__appdata__"); - catch - appdata.(name) = []; - end_try_catch - val(nh) = {appdata.(name)}; - end - if (nh == 1) - val = val{1}; - endif - endfunction