X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fm%2Fmiscellaneous%2Fgetappdata.m;fp=octave_packages%2Fm%2Fmiscellaneous%2Fgetappdata.m;h=60ae41e8752f1e8c841214b6df1cec5ed91945c0;hp=0000000000000000000000000000000000000000;hb=1c0469ada9531828709108a4882a751d2816994a;hpb=63de9f36673d49121015e3695f2c336ea92bc278 diff --git a/octave_packages/m/miscellaneous/getappdata.m b/octave_packages/m/miscellaneous/getappdata.m new file mode 100644 index 0000000..60ae41e --- /dev/null +++ b/octave_packages/m/miscellaneous/getappdata.m @@ -0,0 +1,59 @@ +## Copyright (C) 2010-2012 Ben Abbott +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . + +## -*- texinfo -*- +## @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}) +## Return a structure, @var{appdata}, whose fields correspond to the appdata +## properties. +## @end deftypefn + +## Author: Ben Abbott +## Created: 2010-07-15 + +function val = getappdata (h, 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__"); + end_try_catch + if (! isfield (appdata, name)) + appdata.(name) = []; + endif + val(nh) = {appdata.(name)}; + endfor + 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 + +endfunction +