]> Creatis software - CreaPhase.git/blob - octave_packages/m/miscellaneous/isappdata.m
update packages
[CreaPhase.git] / octave_packages / m / miscellaneous / isappdata.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{V} =} isappdata (@var{h}, @var{name})
19 ## Return true if the named application data, @var{name}, exists for the
20 ## object with handle @var{h}.
21 ## @seealso{getappdata, setappdata, rmappdata}
22 ## @end deftypefn
23
24 ## Author: Ben Abbott <bpabbott@mac.com>
25 ## Created: 2010-07-15
26
27 function res = isappdata (h, name)
28
29   if (! (all (ishandle (h)) && ischar (name)))
30     error ("isappdata: invalid input");
31   endif
32
33   for nh = 1:numel(h)
34     data = get (h(nh));
35     if (isfield (data, "__appdata__") && isfield (data.__appdata__, name))
36       res(nh) = true;
37     else
38       res(nh) = false;
39     endif
40   endfor
41
42 endfunction
43
44 %!test
45 %! setappdata (0, "hello", "world")
46 %! assert (isappdata (0, "hello"), true)
47 %!assert (isappdata (0, "foobar"), false)
48