Mercurial > forge
annotate main/general/inst/@dict/get.m @ 9687:9df0cf7217ae octave-forge
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
author | carandraug |
---|---|
date | Tue, 13 Mar 2012 22:39:03 +0000 |
parents | ee31d2bacd42 |
children | 52bed4508230 |
rev | line source |
---|---|
5910 | 1 ## Copyright (C) 2009 VZLU Prague, a.s., Czech Republic |
2 ## | |
9687
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
6660
diff
changeset
|
3 ## This program is free software; you can redistribute it and/or modify it under |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
6660
diff
changeset
|
4 ## the terms of the GNU General Public License as published by the Free Software |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
6660
diff
changeset
|
5 ## Foundation; either version 3 of the License, or (at your option) any later |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
6660
diff
changeset
|
6 ## version. |
5910 | 7 ## |
9687
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
6660
diff
changeset
|
8 ## This program is distributed in the hope that it will be useful, but WITHOUT |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
6660
diff
changeset
|
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
6660
diff
changeset
|
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
6660
diff
changeset
|
11 ## details. |
5910 | 12 ## |
9687
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
6660
diff
changeset
|
13 ## You should have received a copy of the GNU General Public License along with |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
6660
diff
changeset
|
14 ## this program; if not, see <http://www.gnu.org/licenses/>. |
5910 | 15 |
16 ## -*- texinfo -*- | |
17 ## @deftypefn{Function File} {} get (d, key, defv) | |
18 ## Queries for the values of specified key(s). Unlike indexing, however, | |
19 ## this does not throw an error if a key is missing but rather substitutes | |
20 ## a default value. If @var{key} is a cell array, @var{defv} should be either | |
21 ## a cell array of the same shape as @var{key}, or a singleton cell. | |
22 ## Non-cell values will be converted to a singleton cell. | |
23 ## @end deftypefn | |
24 | |
9687
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
6660
diff
changeset
|
25 ## Author: Jaroslav Hajek <highegg@gmail.com> |
9df0cf7217ae
general: update licenses to GPLv3+ and DESCRIPTION to mention non GPL code
carandraug
parents:
6660
diff
changeset
|
26 |
5910 | 27 function val = get (d, key, defv = []) |
28 if (nargin < 2 || nargin > 3) | |
29 print_usage (); | |
30 endif | |
31 | |
6077 | 32 lookup = __lookup_compat__; # FIXME: remove when 3.3.x is required. |
33 | |
5910 | 34 if (ischar (key)) |
35 i = lookup (d.keys, key, "m"); | |
36 if (i) | |
37 val = d.values{i}; | |
38 else | |
39 val = defv; | |
40 endif | |
41 elseif (iscellstr (key)) | |
6580 | 42 if (! iscell (defv)) |
43 val = repmat ({defv}, size (key)); | |
44 elseif (numel (defv) == 1) | |
45 val = repmat (defv, size (key)); | |
6660 | 46 elseif (size_equal (key, defv)) |
47 val = defv; | |
6580 | 48 else |
6660 | 49 error ("get: sizes of key & defv must match"); |
6580 | 50 endif |
5910 | 51 i = lookup (d.keys, key, "m"); |
52 mask = i != 0; | |
6580 | 53 val(mask) = d.values(i(mask)); |
5910 | 54 else |
6580 | 55 error ("get: invalid key value"); |
5910 | 56 endif |
57 endfunction | |
58 |