]> Creatis software - CreaPhase.git/blob - octave_packages/general-1.3.1/@inputParser/addRequired.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / general-1.3.1 / @inputParser / addRequired.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} =} addRequired (@var{parser}, @var{argname})
18 ## @deftypefnx {Function File} {@var{parser} =} @var{parser}.addRequired (@var{argname})
19 ## @deftypefnx {Function File} {@var{parser} =} addRequired (@var{parser}, @var{argname}, @var{validator})
20 ## @deftypefnx {Function File} {@var{parser} =} @var{parser}.addRequired (@var{argname}, @var{validator})
21 ## Add new mandatory argument to the object @var{parser} of inputParser class.
22 ##
23 ## This method belongs to the inputParser class and implements an ordered
24 ## arguments type of API.
25 ##
26 ## @var{argname} must be a string with the name of the new argument. The order
27 ## in which new arguments are added with @command{addrequired}, represents the
28 ## expected order of arguments.
29 ##
30 ## @var{validator} is an optional function handle to validate the given values
31 ## for the argument with name @var{argname}. Alternatively, a function name
32 ## can be used.
33 ##
34 ## See @command{help inputParser} for examples.
35 ##
36 ## @emph{Note}: this can be used together with the other type of arguments but
37 ## it must be the first (see @command{@@inputParser}).
38 ##
39 ## @seealso{inputParser, @@inputParser/addOptional, @@inputParser/addParamValue
40 ## @@inputParser/addParamValue, @@inputParser/addSwitch, @@inputParser/parse}
41 ## @end deftypefn
42
43 function inPar = addRequired (inPar, name, val)
44
45   ## check @inputParser/subsref for the actual code
46   if (nargin == 2)
47     inPar = subsref (inPar, substruct(
48                                       '.' , 'addRequired',
49                                       '()', {name}
50                                       ));
51   elseif (nargin == 3)
52     inPar = subsref (inPar, substruct(
53                                       '.' , 'addRequired',
54                                       '()', {name, val}
55                                       ));
56   else
57     print_usage;
58   endif
59
60 endfunction