Mercurial > hg > octave-lyh
annotate scripts/miscellaneous/rmappdata.m @ 17535:c12c688a35ed default tip lyh
Fix warnings
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 27 Sep 2013 17:43:27 +0800 |
parents | 1c89599167a6 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
1 ## Copyright (C) 2010-2012 Ben Abbott |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
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:
11523
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:
11523
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} {} rmappdata (@var{h}, @var{name}) | |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11589
diff
changeset
|
19 ## Delete the named application data for the object(s) with |
11180 | 20 ## handle(s) @var{h}. |
21 ## @end deftypefn | |
22 | |
23 ## Author: Ben Abbott <bpabbott@mac.com> | |
24 ## Created: 2010-07-15 | |
25 | |
26 function rmappdata (h, varargin) | |
27 | |
28 if (! (all (ishandle (h)) && iscellstr (varargin))) | |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11588
diff
changeset
|
29 error ("rmappdata: invalid input"); |
11180 | 30 endif |
31 | |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
32 for nh = 1:numel (h) |
15331
aaf938d17e0c
Verify appdata exists before removing a propery. Also verify the property
Philip Nienhuis <philipnienhuis>
parents:
14868
diff
changeset
|
33 if (isprop (h(nh), "__appdata__")) |
aaf938d17e0c
Verify appdata exists before removing a propery. Also verify the property
Philip Nienhuis <philipnienhuis>
parents:
14868
diff
changeset
|
34 appdata = get (h(nh), "__appdata__"); |
aaf938d17e0c
Verify appdata exists before removing a propery. Also verify the property
Philip Nienhuis <philipnienhuis>
parents:
14868
diff
changeset
|
35 for v = 1:numel(varargin) |
aaf938d17e0c
Verify appdata exists before removing a propery. Also verify the property
Philip Nienhuis <philipnienhuis>
parents:
14868
diff
changeset
|
36 if (isfield (appdata, varargin{v})) |
aaf938d17e0c
Verify appdata exists before removing a propery. Also verify the property
Philip Nienhuis <philipnienhuis>
parents:
14868
diff
changeset
|
37 appdata = rmfield (appdata, varargin{v}); |
aaf938d17e0c
Verify appdata exists before removing a propery. Also verify the property
Philip Nienhuis <philipnienhuis>
parents:
14868
diff
changeset
|
38 else |
aaf938d17e0c
Verify appdata exists before removing a propery. Also verify the property
Philip Nienhuis <philipnienhuis>
parents:
14868
diff
changeset
|
39 error ("rmappdata: appdata '%s' is not present") |
aaf938d17e0c
Verify appdata exists before removing a propery. Also verify the property
Philip Nienhuis <philipnienhuis>
parents:
14868
diff
changeset
|
40 endif |
aaf938d17e0c
Verify appdata exists before removing a propery. Also verify the property
Philip Nienhuis <philipnienhuis>
parents:
14868
diff
changeset
|
41 endfor |
aaf938d17e0c
Verify appdata exists before removing a propery. Also verify the property
Philip Nienhuis <philipnienhuis>
parents:
14868
diff
changeset
|
42 set (h(nh), "__appdata__", appdata); |
aaf938d17e0c
Verify appdata exists before removing a propery. Also verify the property
Philip Nienhuis <philipnienhuis>
parents:
14868
diff
changeset
|
43 endif |
11180 | 44 endfor |
45 | |
46 endfunction | |
47 | |
17346
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
15331
diff
changeset
|
48 |
11180 | 49 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
50 %! setappdata (0, "hello", "world"); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
51 %! rmappdata (0, "hello"); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
52 %! assert (isappdata (0, "hello"), false); |
11180 | 53 |
15331
aaf938d17e0c
Verify appdata exists before removing a propery. Also verify the property
Philip Nienhuis <philipnienhuis>
parents:
14868
diff
changeset
|
54 %!test |
aaf938d17e0c
Verify appdata exists before removing a propery. Also verify the property
Philip Nienhuis <philipnienhuis>
parents:
14868
diff
changeset
|
55 %! setappdata (0, "data1", rand (3)); |
aaf938d17e0c
Verify appdata exists before removing a propery. Also verify the property
Philip Nienhuis <philipnienhuis>
parents:
14868
diff
changeset
|
56 %! setappdata (0, "data2", {"hello", "world"}); |
aaf938d17e0c
Verify appdata exists before removing a propery. Also verify the property
Philip Nienhuis <philipnienhuis>
parents:
14868
diff
changeset
|
57 %! rmappdata (0, "data1", "data2"); |
aaf938d17e0c
Verify appdata exists before removing a propery. Also verify the property
Philip Nienhuis <philipnienhuis>
parents:
14868
diff
changeset
|
58 %! assert (isappdata (0, "data1"), false); |
aaf938d17e0c
Verify appdata exists before removing a propery. Also verify the property
Philip Nienhuis <philipnienhuis>
parents:
14868
diff
changeset
|
59 %! assert (isappdata (0, "data2"), false); |
aaf938d17e0c
Verify appdata exists before removing a propery. Also verify the property
Philip Nienhuis <philipnienhuis>
parents:
14868
diff
changeset
|
60 |