# HG changeset patch # User Ben Abbott # Date 1302648620 14400 # Node ID e12a7c0a1fc51d99fca565070ff4876d761b758f # Parent 5161d02c96b7ac06dacedb98f9c8666340aff434 getappdata.m: If no property name is provided, return a structure representing the appdata. diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2011-04-12 Ben Abbott + + * miscellaneous/getappdata.m: If no property name is provided, return + a structure representing the appdata. + 2011-04-12 Marco Caliari * general/quadgk.m: Fix problem with -Inf bound on integral (bug diff --git a/scripts/miscellaneous/getappdata.m b/scripts/miscellaneous/getappdata.m --- 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 @@ -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