Mercurial > octave-antonio
annotate scripts/miscellaneous/setappdata.m @ 11587:c792872f8942
all script files: untabify and strip trailing whitespace
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 20 Jan 2011 17:35:29 -0500 |
parents | 3c6e8aaa9555 |
children | d5bd2766c640 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2010-2011 Ben Abbott |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
2 ## |
11180 | 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. | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
7 ## |
11180 | 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. | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
12 ## |
11180 | 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} {} setappdata (@var{h}, @var{name}, @var{value}) | |
19 ## Sets the named application data to @var{value} for the object(s) with | |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
20 ## handle(s) @var{h}. If the application data with the specified name does |
11180 | 21 ## not exist, it is created. |
22 ## @end deftypefn | |
23 | |
24 ## Author: Ben Abbott <bpabbott@mac.com> | |
25 ## Created: 2010-07-15 | |
26 | |
27 function setappdata (h, varargin) | |
28 | |
29 if (! (all (ishandle (h)) && mod (numel (varargin), 2) == 0)) | |
30 error ("setappdata: invalid input.") | |
31 endif | |
32 | |
33 for nh = 1:numel(h) | |
34 if (! isfield (get (h(nh)), "__appdata__")) | |
35 addproperty ("__appdata__", h(nh), "any", struct ()); | |
36 end | |
37 appdata = get (h(nh), "__appdata__"); | |
38 for narg = 1:2:numel(varargin) | |
39 if (iscellstr (varargin{narg})) | |
40 ## Handle cell arrays like set() does. | |
41 set (h(nh), "__appdata__", appdata); | |
42 setappdata (h(nh), vertcat (varargin{narg}', varargin{narg+1}'){:}); | |
43 appdata = get (h(nh), "__appdata__"); | |
44 elseif (ischar (varargin{narg})) | |
45 appdata.(varargin{narg}) = varargin{narg+1}; | |
46 else | |
47 error ("setappdata: invalid input.") | |
48 endif | |
49 endfor | |
50 set (h(nh), "__appdata__", appdata); | |
51 endfor | |
52 | |
53 endfunction | |
54 | |
55 %!test | |
56 %! setappdata (0, "hello", "world") | |
57 %! assert (isappdata (0, "hello"), true) | |
58 %!assert (getappdata (0, "hello"), "world") | |
59 |