]> Creatis software - CreaPhase.git/blob - octave_packages/m/miscellaneous/getappdata.m
update packages
[CreaPhase.git] / octave_packages / m / miscellaneous / getappdata.m
1 ## Copyright (C) 2010-2012 Ben Abbott
2 ##
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
7 ##
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 ## GNU General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU General Public License
14 ## along with Octave; see the file COPYING.  If not, see
15 ## <http://www.gnu.org/licenses/>.
16
17 ## -*- texinfo -*-
18 ## @deftypefn {Function File} {@var{value} =} getappdata (@var{h}, @var{name})
19 ## Return the @var{value} for named application data for the object(s) with
20 ## handle(s) @var{h}.
21 ## @deftypefnx {Function File} {@var{appdata} =} getappdata (@var{h})
22 ## Return a structure, @var{appdata}, whose fields correspond to the appdata
23 ## properties.
24 ## @end deftypefn
25
26 ## Author: Ben Abbott <bpabbott@mac.com>
27 ## Created: 2010-07-15
28
29 function val = getappdata (h, name)
30
31   if (all (ishandle (h)) && nargin == 2 && ischar (name))
32     ## FIXME - Is there a better way to handle non-existent appdata
33     ## and missing fields?
34     val = cell (numel (h), 1);
35     appdata = struct();
36     for nh = 1:numel(h)
37       try
38         appdata = get (h(nh), "__appdata__");
39       end_try_catch
40       if (! isfield (appdata, name))
41         appdata.(name) = [];
42       endif
43       val(nh) = {appdata.(name)};
44     endfor
45     if (nh == 1)
46       val = val{1};
47     endif
48   elseif (ishandle (h) && numel (h) == 1 && nargin == 1)
49     try
50       val = get (h, "__appdata__");
51     catch
52       val = struct ();
53     end_try_catch
54   else
55     error ("getappdata: invalid input");
56   endif
57
58 endfunction
59