1 ## Copyright (C) 2011 Carnë Draug <carandraug+dev@gmail.com>
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
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
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/>.
17 ## @deftypefn {Function File} {@var{parser} =} addOptional (@var{parser}, @var{argname}, @var{default})
18 ## @deftypefnx {Function File} {@var{parser} =} @var{parser}.addOptional (@var{argname}, @var{default})
19 ## @deftypefnx {Function File} {@var{parser} =} addOptional (@var{parser}, @var{argname}, @var{default}, @var{validator})
20 ## @deftypefnx {Function File} {@var{parser} =} @var{parser}.addOptional (@var{argname}, @var{default}, @var{validator})
21 ## Add new optional argument to the object @var{parser} of the class inputParser
22 ## to implement an ordered arguments type of API
24 ## @var{argname} must be a string with the name of the new argument. The order
25 ## in which new arguments are added with @command{addOptional}, represents the
26 ## expected order of arguments.
28 ## @var{default} will be the value used when the argument is not specified.
30 ## @var{validator} is an optional anonymous function to validate the given values
31 ## for the argument with name @var{argname}. Alternatively, a function name
34 ## See @command{help inputParser} for examples.
36 ## @emph{Note}: if a string argument does not validate, it will be considered a
37 ## ParamValue key. If an optional argument is not given a validator, anything
38 ## will be valid, and so any string will be considered will be the value of the
39 ## optional argument (in @sc{matlab}, if no validator is given and argument is
40 ## a string it will also be considered a ParamValue key).
42 ## @seealso{inputParser, @@inputParser/addParamValue, @@inputParser/addSwitch,
43 ## @@inputParser/addParamValue, @@inputParser/addRequired, @@inputParser/parse}
46 function inPar = addOptional (inPar, name, def, val)
48 ## check @inputParser/subsref for the actual code
50 inPar = subsref (inPar, substruct(
55 inPar = subsref (inPar, substruct(
57 '()', {name, def, val}