]> Creatis software - CreaPhase.git/blob - octave_packages/general-1.3.1/@inputParser/addParamValue.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / general-1.3.1 / @inputParser / addParamValue.m
1 ## Copyright (C) 2011 CarnĂ« Draug <carandraug+dev@gmail.com>
2 ##
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
6 ## version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 ## details.
12 ##
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} {@var{parser} =} addParamValue (@var{parser}, @var{argname}, @var{default})
18 ## @deftypefnx {Function File} {@var{parser} =} @var{parser}.addParamValue (@var{argname}, @var{default})
19 ## @deftypefnx {Function File} {@var{parser} =} addParamValue (@var{parser}, @var{argname}, @var{default}, @var{validator})
20 ## @deftypefnx {Function File} {@var{parser} =} @var{parser}.addParamValue (@var{argname}, @var{default}, @var{validator})
21 ## Add new parameter to the object @var{parser} of the class inputParser to implement
22 ## a name/value pair type of API.
23 ##
24 ## @var{argname} must be a string with the name of the new parameter.
25 ##
26 ## @var{default} will be the value used when the parameter is not specified.
27 ##
28 ## @var{validator} is an optional function handle to validate the given values
29 ## for the parameter with name @var{argname}. Alternatively, a function name
30 ## can be used.
31 ##
32 ## See @command{help inputParser} for examples.
33 ##
34 ## @seealso{inputParser, @@inputParser/addOptional, @@inputParser/addSwitch,
35 ## @@inputParser/addParamValue, @@inputParser/addRequired, @@inputParser/parse}
36 ## @end deftypefn
37
38 function inPar = addParamValue (inPar, name, def, val)
39
40   ## check @inputParser/subsref for the actual code
41   if (nargin == 3)
42     inPar = subsref (inPar, substruct(
43                                       '.' , 'addParamValue',
44                                       '()', {name, def}
45                                       ));
46   elseif (nargin == 4)
47     inPar = subsref (inPar, substruct(
48                                       '.' , 'addParamValue',
49                                       '()', {name, def, val}
50                                       ));
51   else
52     print_usage;
53   endif
54
55 endfunction