Mercurial > octave
annotate scripts/miscellaneous/inputParser.m @ 31548:c8ad083a5802 stable
maint: Clean up m-files before Octave 8.1 release.
* external.txi, oop.txi, Table.h, documentation.cc, gui-preferences-ed.h,
lo-specfun.cc, range.tst : Eliminate triple newlines.
* Map.m, MemoizedFunction.m, delaunayn.m, inputParser.m,
__publish_latex_output__.m, publish.m, unpack.m, fminbnd.m,
__add_default_menu__.m, gammainc.m, gallery.m, hadamard.m, weboptions.m:
Add newline after keyword "function" or before keyword "endfunction" for
readability.
* getaudiodata.m, pkg.m : Add semicolon to end of line for error() statement.
* movegui.m: Combine mutliple calls to set() into one for performance.
* __unimplemented__.m (missing_functions): Remove missing functions that have
been implemented.
* __vectorize__.m, check_default_input.m, betaincinv.m, gammaincinv.m:
Remove semicolon at end of line with "function" declaration.
* weboptions.m: Remove semicolon at end of line with "if" keyword.
* integrate_adaptive.m, factor.m: Use keyword "endif" rather than bare "end".
author | Rik <rik@octave.org> |
---|---|
date | Fri, 25 Nov 2022 21:23:54 -0800 |
parents | 7797481038fc |
children | 597f3ee61a48 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30379
diff
changeset
|
3 ## Copyright (C) 2011-2022 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
7 ## |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
8 ## This file is part of Octave. |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
9 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24491
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24491
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22559
diff
changeset
|
13 ## (at your option) any later version. |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
14 ## |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
15 ## Octave is distributed in the hope that it will be useful, but |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22559
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22559
diff
changeset
|
18 ## GNU General Public License for more details. |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
19 ## |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
20 ## You should have received a copy of the GNU General Public License |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24491
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
25 |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
26 classdef inputParser < handle |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
27 |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
28 ## -*- texinfo -*- |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
29 ## @deftypefn {} {@var{p} =} inputParser () |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
30 ## Create object @var{p} of the inputParser class. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
31 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
32 ## This class is designed to allow easy parsing of function arguments. The |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
33 ## class supports four types of arguments: |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
34 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
35 ## @enumerate |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
36 ## @item mandatory (see @code{addRequired}); |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
37 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
38 ## @item optional (see @code{addOptional}); |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
39 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
40 ## @item named (see @code{addParameter}); |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
41 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
42 ## @item switch (see @code{addSwitch}). |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
43 ## @end enumerate |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
44 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
45 ## After defining the function API with these methods, the supplied arguments |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
46 ## can be parsed with the @code{parse} method and the parsing results |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
47 ## accessed with the @code{Results} accessor. |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
48 ## @end deftypefn |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
49 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
50 ## @deftypefn {} {} inputParser.Parameters |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
51 ## Return list of parameter names already defined. |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
52 ## @end deftypefn |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
53 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
54 ## @deftypefn {} {} inputParser.Results |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
55 ## Return structure with argument names as fieldnames and corresponding |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
56 ## values. |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
57 ## @end deftypefn |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
58 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
59 ## @deftypefn {} {} inputParser.Unmatched |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
60 ## Return structure similar to @code{Results}, but for unmatched parameters. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
61 ## See the @code{KeepUnmatched} property. |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
62 ## @end deftypefn |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
63 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
64 ## @deftypefn {} {} inputParser.UsingDefaults |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
65 ## Return cell array with the names of arguments that are using default |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
66 ## values. |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
67 ## @end deftypefn |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
68 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
69 ## @deftypefn {} {} inputParser.CaseSensitive = @var{boolean} |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
70 ## Set whether matching of argument names should be case sensitive. Defaults |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
71 ## to false. |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
72 ## @end deftypefn |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
73 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
74 ## @deftypefn {} {} inputParser.FunctionName = @var{name} |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
75 ## Set function name to be used in error messages; Defaults to empty string. |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
76 ## @end deftypefn |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
77 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
78 ## @deftypefn {} {} inputParser.KeepUnmatched = @var{boolean} |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
79 ## Set whether an error should be given for non-defined arguments. Defaults |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
80 ## to false. If set to true, the extra arguments can be accessed through |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
81 ## @code{Unmatched} after the @code{parse} method. Note that since |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
82 ## @code{Switch} and @code{Parameter} arguments can be mixed, it is |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
83 ## not possible to know the unmatched type. If argument is found unmatched |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
84 ## it is assumed to be of the @code{Parameter} type and it is expected to |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
85 ## be followed by a value. |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
86 ## @end deftypefn |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
87 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
88 ## @deftypefn {} {} inputParser.StructExpand = @var{boolean} |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
89 ## Set whether a structure can be passed to the function instead of |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
90 ## parameter/value pairs. Defaults to true. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
91 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
92 ## The following example shows how to use this class: |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
93 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
94 ## @example |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
95 ## function check (varargin) |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
96 ## @c The next two comments need to be indented by one for alignment |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
97 ## p = inputParser (); # create object |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
98 ## p.FunctionName = "check"; # set function name |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
99 ## p.addRequired ("pack", @@ischar); # mandatory argument |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
100 ## p.addOptional ("path", pwd(), @@ischar); # optional argument |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
101 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
102 ## ## create a function handle to anonymous functions for validators |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
103 ## val_mat = @@(x) isvector (x) && all (x <= 1) && all (x >= 0); |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
104 ## p.addOptional ("mat", [0 0], val_mat); |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
105 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
106 ## ## create two arguments of type "Parameter" |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
107 ## val_type = @@(x) any (strcmp (x, @{"linear", "quadratic"@})); |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
108 ## p.addParameter ("type", "linear", val_type); |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
109 ## val_verb = @@(x) any (strcmp (x, @{"low", "medium", "high"@})); |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
110 ## p.addParameter ("tolerance", "low", val_verb); |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
111 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
112 ## ## create a switch type of argument |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
113 ## p.addSwitch ("verbose"); |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
114 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
115 ## p.parse (varargin@{:@}); # Run created parser on inputs |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
116 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
117 ## ## the rest of the function can access inputs by using p.Results. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
118 ## ## for example, get the tolerance input with p.Results.tolerance |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
119 ## endfunction |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
120 ## @end example |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
121 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
122 ## @example |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
123 ## @group |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
124 ## check ("mech"); # valid, use defaults for other arguments |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
125 ## check (); # error, one argument is mandatory |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
126 ## check (1); # error, since ! ischar |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
127 ## check ("mech", "~/dev"); # valid, use defaults for other arguments |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
128 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
129 ## check ("mech", "~/dev", [0 1 0 0], "type", "linear"); # valid |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
130 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
131 ## ## following is also valid. Note how the Switch argument type can |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
132 ## ## be mixed into or before the Parameter argument type (but it |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
133 ## ## must still appear after any Optional argument). |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
134 ## check ("mech", "~/dev", [0 1 0 0], "verbose", "tolerance", "high"); |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
135 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
136 ## ## following returns an error since not all optional arguments, |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
137 ## ## 'path' and 'mat', were given before the named argument 'type'. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
138 ## check ("mech", "~/dev", "type", "linear"); |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
139 ## @end group |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
140 ## @end example |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
141 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
142 ## @emph{Note 1}: A function can have any mixture of the four API types but |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
143 ## they must appear in a specific order. @code{Required} arguments must be |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
144 ## first and can be followed by any @code{Optional} arguments. Only |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
145 ## the @code{Parameter} and @code{Switch} arguments may be mixed |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
146 ## together and they must appear at the end. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
147 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
148 ## @emph{Note 2}: If both @code{Optional} and @code{Parameter} arguments |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
149 ## are mixed in a function API then once a string Optional argument fails to |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
150 ## validate it will be considered the end of the @code{Optional} |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
151 ## arguments. The remaining arguments will be compared against any |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
152 ## @code{Parameter} or @code{Switch} arguments. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
153 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
154 ## @seealso{nargin, validateattributes, validatestring, varargin} |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
155 ## @end deftypefn |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
156 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
157 properties |
21578
683a1beee538
maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
158 ## FIXME: set input checking for these properties |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
159 CaseSensitive = false; |
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
160 FunctionName = ""; |
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
161 KeepUnmatched = false; |
21937
55f7de37b618
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
162 PartialMatching = false; # FIXME: unimplemented (and default should be true) |
21667
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
163 StructExpand = true; |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
164 endproperties |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
165 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
166 properties (SetAccess = protected) |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19597
diff
changeset
|
167 Parameters = cell (); |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19597
diff
changeset
|
168 Results = struct (); |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19597
diff
changeset
|
169 Unmatched = struct (); |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19597
diff
changeset
|
170 UsingDefaults = cell (); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
171 endproperties |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
172 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
173 properties (Access = protected) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
174 ## Since Required and Optional are ordered, they get a cell array of |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
175 ## structs with the fields "name", "def" (default), and "val" (validator). |
23164
99ca557fd34f
maint: Use Octave whitespace conventions for scripts/general/inputParser.m.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22755
diff
changeset
|
176 Required = cell (); |
99ca557fd34f
maint: Use Octave whitespace conventions for scripts/general/inputParser.m.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22755
diff
changeset
|
177 Optional = cell (); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
178 ## Parameter and Switch are unordered so we have a struct whose fieldnames |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
179 ## are the argname, and values are a struct with fields "def" and "val" |
23164
99ca557fd34f
maint: Use Octave whitespace conventions for scripts/general/inputParser.m.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22755
diff
changeset
|
180 Parameter = struct (); |
99ca557fd34f
maint: Use Octave whitespace conventions for scripts/general/inputParser.m.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22755
diff
changeset
|
181 Switch = struct (); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
182 |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
183 ## List of Parameter and Switch names to ease searches |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
184 ParameterNames = cell (); |
23164
99ca557fd34f
maint: Use Octave whitespace conventions for scripts/general/inputParser.m.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22755
diff
changeset
|
185 SwitchNames = cell (); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
186 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
187 ## When checking for fieldnames in a Case Insensitive way, this variable |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
188 ## holds the correct identifier for the last searched named using the |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
189 ## is_argname method. |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
190 last_name = ""; |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
191 endproperties |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
192 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
193 properties (Access = protected, Constant = true) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
194 ## Default validator, always returns scalar true. |
28563
5a07c798eb08
avoid function call input or output argument number mismatch
John W. Eaton <jwe@octave.org>
parents:
28378
diff
changeset
|
195 def_val = @(~) true; |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
196 endproperties |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
197 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
198 methods |
28945
6e460773bdda
maint: Use newlines after "function" and before "endfunction" for clarity.
Rik <rik@octave.org>
parents:
28929
diff
changeset
|
199 |
21668
58f5a6347851
inpputParser.m: fix display method.
Carnë Draug <carandraug@octave.org>
parents:
21667
diff
changeset
|
200 function set.PartialMatching (this, val) |
58f5a6347851
inpputParser.m: fix display method.
Carnë Draug <carandraug@octave.org>
parents:
21667
diff
changeset
|
201 if (val) |
58f5a6347851
inpputParser.m: fix display method.
Carnë Draug <carandraug@octave.org>
parents:
21667
diff
changeset
|
202 error ("inputParser: PartialMatching is not yet implemented"); |
58f5a6347851
inpputParser.m: fix display method.
Carnë Draug <carandraug@octave.org>
parents:
21667
diff
changeset
|
203 endif |
58f5a6347851
inpputParser.m: fix display method.
Carnë Draug <carandraug@octave.org>
parents:
21667
diff
changeset
|
204 endfunction |
58f5a6347851
inpputParser.m: fix display method.
Carnë Draug <carandraug@octave.org>
parents:
21667
diff
changeset
|
205 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
206 function addRequired (this, name, val = inputParser.def_val) |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
207 |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
208 ## -*- texinfo -*- |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
209 ## @deftypefn {} {} addRequired (@var{argname}) |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
210 ## @deftypefnx {} {} addRequired (@var{argname}, @var{validator}) |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
211 ## Add new mandatory argument to the object @var{parser} of inputParser |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
212 ## class. This method belongs to the inputParser class and implements |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
213 ## an ordered arguments type of API. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
214 ## |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
215 ## @var{argname} must be a string with the name of the new argument. The |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
216 ## order in which new arguments are added with @code{addrequired}, |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
217 ## represents the expected order of arguments. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
218 ## |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
219 ## @var{validator} is an optional function handle to validate the given |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
220 ## values for the argument with name @var{argname}. Alternatively, a |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
221 ## function name can be used. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
222 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
223 ## See @code{help inputParser} for examples. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
224 ## |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
225 ## @emph{Note}: this can be used together with the other type of |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
226 ## arguments but it must be the first (see @code{@@inputParser}). |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
227 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
228 ## @end deftypefn |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
229 |
28789
28de41192f3c
Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents:
28563
diff
changeset
|
230 if (nargin < 2) |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
231 print_usage (); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
232 elseif (numel (this.Optional) || numfields (this.Parameter) |
20937
3b2cc6ef0624
use numfields (x) instead of numel (fieldnames (x))
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
233 || numfields (this.Switch)) |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
234 error (["inputParser.addRequired: can't have a Required argument " ... |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
235 "after Optional, Parameter, or Switch"]); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
236 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
237 this.validate_name ("Required", name); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
238 this.Required{end+1} = struct ("name", name, "val", val); |
31548
c8ad083a5802
maint: Clean up m-files before Octave 8.1 release.
Rik <rik@octave.org>
parents:
31103
diff
changeset
|
239 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
240 endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
241 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
242 function addOptional (this, name, def, val = inputParser.def_val) |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
243 |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
244 ## -*- texinfo -*- |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
245 ## @deftypefn {} {} addOptional (@var{argname}, @var{default}) |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
246 ## @deftypefnx {} {} addOptional (@var{argname}, @var{default}, @var{validator}) |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
247 ## Add new optional argument to the object @var{parser} of the class |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
248 ## inputParser to implement an ordered arguments type of API |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
249 ## |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
250 ## @var{argname} must be a string with the name of the new argument. The |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
251 ## order in which new arguments are added with @code{addOptional}, |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
252 ## represents the expected order of arguments. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
253 ## |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
254 ## @var{default} will be the value used when the argument is not |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
255 ## specified. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
256 ## |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
257 ## @var{validator} is an optional anonymous function to validate the |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
258 ## given values for the argument with name @var{argname}. Alternatively, |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
259 ## a function name can be used. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
260 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
261 ## See @code{help inputParser} for examples. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
262 ## |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
263 ## @emph{Note}: if a string argument does not validate, it will be |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
264 ## considered a ParamValue key. If an optional argument is not given a |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
265 ## validator, anything will be valid, and so any string will be |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
266 ## considered will be the value of the optional argument (in @sc{matlab}, |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
267 ## if no validator is given and argument is a string it will also be |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
268 ## considered a ParamValue key). |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
269 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
270 ## @end deftypefn |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
271 |
28789
28de41192f3c
Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents:
28563
diff
changeset
|
272 if (nargin < 3) |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
273 print_usage (); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
274 elseif (numfields (this.Parameter) || numfields (this.Switch)) |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
275 error (["inputParser.Optional: can't have Optional arguments " ... |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
276 "after Parameter or Switch"]); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
277 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
278 this.validate_name ("Optional", name); |
31101
c415b218307f
inputParser: Correctly handle cell default values for optional parameters (bug #62639).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31074
diff
changeset
|
279 if (iscell (def)) |
c415b218307f
inputParser: Correctly handle cell default values for optional parameters (bug #62639).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31074
diff
changeset
|
280 def = {def}; |
c415b218307f
inputParser: Correctly handle cell default values for optional parameters (bug #62639).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31074
diff
changeset
|
281 endif |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
282 this.Optional{end+1} = struct ("name", name, "def", def, "val", val); |
31548
c8ad083a5802
maint: Clean up m-files before Octave 8.1 release.
Rik <rik@octave.org>
parents:
31103
diff
changeset
|
283 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
284 endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
285 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
286 function addParamValue (this, name, def, val = inputParser.def_val) |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
287 |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
288 ## -*- texinfo -*- |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
289 ## @deftypefn {} {} addParamValue (@var{argname}, @var{default}) |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
290 ## @deftypefnx {} {} addParamValue (@var{argname}, @var{default}, @var{validator}) |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
291 ## Add new parameter to the object @var{parser} of the class inputParser |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
292 ## to implement a name/value pair type of API. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
293 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
294 ## This is an alias for @code{addParameter} method without the |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
295 ## @qcode{"PartialMatchPriority"} option. See it for the help text. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
296 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
297 ## @end deftypefn |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
298 |
28789
28de41192f3c
Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents:
28563
diff
changeset
|
299 if (nargin < 3) |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
300 print_usage (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
301 endif |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
302 this.addParameter (name, def, val); |
31548
c8ad083a5802
maint: Clean up m-files before Octave 8.1 release.
Rik <rik@octave.org>
parents:
31103
diff
changeset
|
303 |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
304 endfunction |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
305 |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
306 function addParameter (this, name, def, varargin) |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
307 |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
308 ## -*- texinfo -*- |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
309 ## @deftypefn {} {} addParameter (@var{argname}, @var{default}) |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
310 ## @deftypefnx {} {} addParameter (@var{argname}, @var{default}, @var{validator}) |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
311 ## Add new parameter to the object @var{parser} of the class inputParser |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
312 ## to implement a name/value pair type of API. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
313 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
314 ## @var{argname} must be a string with the name of the new parameter. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
315 ## |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
316 ## @var{default} will be the value used when the parameter is not |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
317 ## specified. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
318 ## |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
319 ## @var{validator} is an optional function handle to validate the given |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
320 ## values for the parameter with name @var{argname}. Alternatively, a |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
321 ## function name can be used. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
322 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
323 ## See @code{help inputParser} for examples. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
324 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
325 ## @end deftypefn |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
326 |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
327 if (nargin < 3 || nargin > 6) |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
328 print_usage (); |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
329 endif |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
330 |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
331 n_opt = numel (varargin); |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
332 |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
333 if (n_opt == 0 || n_opt == 2) |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
334 val = inputParser.def_val; |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
335 else # n_opt is 1 or 3 |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
336 val = varargin{1}; |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
337 endif |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
338 |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
339 if (n_opt == 0 || n_opt == 1) |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
340 match_priority = 1; |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
341 else # n_opt is 2 or 3 |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
342 if (! strcmpi (varargin{end-1}, "PartialMatchPriority")) |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
343 error ("inputParser.addParameter: unrecognized option"); |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
344 endif |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
345 match_priority = varargin{end}; |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
346 validateattributes (match_priority, {"numeric"}, {"positive", "integer"}, |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
347 "inputParser.addParameter", |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
348 "PartialMatchPriority"); |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
349 endif |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
350 |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
351 this.validate_name ("Parameter", name); |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
352 this.Parameter.(name).def = def; |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
353 this.Parameter.(name).val = val; |
31548
c8ad083a5802
maint: Clean up m-files before Octave 8.1 release.
Rik <rik@octave.org>
parents:
31103
diff
changeset
|
354 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
355 endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
356 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
357 function addSwitch (this, name) |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
358 |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
359 ## -*- texinfo -*- |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
360 ## @deftypefn {} {} addSwitch (@var{argname}) |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
361 ## Add new switch type of argument to the object @var{parser} of |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
362 ## inputParser class. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
363 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
364 ## This method belongs to the inputParser class and implements a switch |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
365 ## arguments type of API. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
366 ## |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
367 ## @var{argname} must be a string with the name of the new argument. |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
368 ## Arguments of this type can be specified at the end, after |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
369 ## @code{Required} and @code{Optional}, and mixed between the |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
370 ## @code{Parameter}. They default to false. If one of the arguments |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
371 ## supplied is a string like @var{argname}, then after parsing the value |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
372 ## of @var{parse}.Results.@var{argname} will be true. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
373 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
374 ## See @code{help inputParser} for examples. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
375 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
376 ## @end deftypefn |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
377 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
378 if (nargin != 2) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
379 print_usage (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
380 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
381 this.validate_name ("Switch", name); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
382 this.Switch.(name).def = false; |
31548
c8ad083a5802
maint: Clean up m-files before Octave 8.1 release.
Rik <rik@octave.org>
parents:
31103
diff
changeset
|
383 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
384 endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
385 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
386 function parse (this, varargin) |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
387 |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
388 ## -*- texinfo -*- |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
389 ## @deftypefn {} {} parse (@var{varargin}) |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
390 ## Parses and validates list of arguments according to object |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
391 ## @var{parser} of the class inputParser. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
392 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
393 ## After parsing, the results can be accessed with the @code{Results} |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
394 ## accessor. See @code{help inputParser} for a more complete |
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
395 ## description. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
396 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
397 ## @end deftypefn |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
398 |
22541
4b7ab10b5c38
inputParser clear previous results before new parse (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22489
diff
changeset
|
399 this.Results = struct (); |
22559
27f2a7a3b55d
inputParser reset more parse results before new parse. (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22541
diff
changeset
|
400 this.Unmatched = struct (); |
27f2a7a3b55d
inputParser reset more parse results before new parse. (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22541
diff
changeset
|
401 this.UsingDefaults = cell (); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
402 if (numel (varargin) < numel (this.Required)) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
403 if (this.FunctionName) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
404 print_usage (this.FunctionName); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
405 else |
20726
25d676f9619c
Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20575
diff
changeset
|
406 this.error ("inputParser.parse: not enough input arguments"); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
407 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
408 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
409 pnargin = numel (varargin); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
410 |
23167
a2d6b84ce5c5
scripts/general/inputParser.m: refactor two xtest cases to normal test cases.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23165
diff
changeset
|
411 this.ParameterNames = fieldnames (this.Parameter); |
a2d6b84ce5c5
scripts/general/inputParser.m: refactor two xtest cases to normal test cases.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23165
diff
changeset
|
412 this.SwitchNames = fieldnames (this.Switch); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
413 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
414 ## Evaluate the Required arguments first |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
415 nReq = numel (this.Required); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
416 for idx = 1:nReq |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
417 req = this.Required{idx}; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
418 this.validate_arg (req.name, req.val, varargin{idx}); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
419 endfor |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
420 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
421 vidx = nReq; # current index in varargin |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
422 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
423 ## Search for a list of Optional arguments |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
424 idx = 0; # current index on the array of Optional |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
425 nOpt = numel (this.Optional); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
426 while (vidx < pnargin && idx < nOpt) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
427 opt = this.Optional{++idx}; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
428 in = varargin{++vidx}; |
23377
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
429 if ((this.is_argname ("Parameter", in) && vidx < pnargin) |
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
430 || this.is_argname ("Switch", in)) |
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
431 ## This looks like an optional parameter/value pair or a |
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
432 ## switch, not an positional option. This does mean that |
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
433 ## positional options cannot be strings named like parameter |
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
434 ## keys. See bug #50752. |
23365
7b594fcfa32b
improve inputParser compatibility for optional args (bug #50752)
John W. Eaton <jwe@octave.org>
parents:
23337
diff
changeset
|
435 idx -= 1; |
7b594fcfa32b
improve inputParser compatibility for optional args (bug #50752)
John W. Eaton <jwe@octave.org>
parents:
23337
diff
changeset
|
436 vidx -= 1; |
28917
72d57dbcc305
maint: Add semicolon after break and return keywords.
Rik <rik@octave.org>
parents:
28912
diff
changeset
|
437 break; |
23365
7b594fcfa32b
improve inputParser compatibility for optional args (bug #50752)
John W. Eaton <jwe@octave.org>
parents:
23337
diff
changeset
|
438 endif |
21666
09517e0a8aa0
inputParser.m: handle errors in Optional parameters (maybe is a param key).
Carnë Draug <carandraug@octave.org>
parents:
21634
diff
changeset
|
439 try |
09517e0a8aa0
inputParser.m: handle errors in Optional parameters (maybe is a param key).
Carnë Draug <carandraug@octave.org>
parents:
21634
diff
changeset
|
440 valid_option = opt.val (in); |
09517e0a8aa0
inputParser.m: handle errors in Optional parameters (maybe is a param key).
Carnë Draug <carandraug@octave.org>
parents:
21634
diff
changeset
|
441 catch |
09517e0a8aa0
inputParser.m: handle errors in Optional parameters (maybe is a param key).
Carnë Draug <carandraug@octave.org>
parents:
21634
diff
changeset
|
442 valid_option = false; |
09517e0a8aa0
inputParser.m: handle errors in Optional parameters (maybe is a param key).
Carnë Draug <carandraug@octave.org>
parents:
21634
diff
changeset
|
443 end_try_catch |
09517e0a8aa0
inputParser.m: handle errors in Optional parameters (maybe is a param key).
Carnë Draug <carandraug@octave.org>
parents:
21634
diff
changeset
|
444 if (! valid_option) |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
445 ## If it does not match there's two options: |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
446 ## 1) input is actually wrong and we should error; |
23377
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
447 ## 2) it's a Parameter or Switch name and we should use |
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
448 ## the default for the rest; |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
449 ## 3) it's a struct with the Parameter pairs. |
21667
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
450 if (ischar (in) || (this.StructExpand && isstruct (in) |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
451 && isscalar (in))) |
20735
418ae0cb752f
Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents:
20726
diff
changeset
|
452 idx -= 1; |
418ae0cb752f
Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents:
20726
diff
changeset
|
453 vidx -= 1; |
28917
72d57dbcc305
maint: Add semicolon after break and return keywords.
Rik <rik@octave.org>
parents:
28912
diff
changeset
|
454 break; |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
455 else |
23165
5291b67ff124
More verbose information when inputParser fails validating argument (patch #9241)
Georg Wiora
parents:
23164
diff
changeset
|
456 this.error (sprintf (["failed validation of %s\n", ... |
5291b67ff124
More verbose information when inputParser fails validating argument (patch #9241)
Georg Wiora
parents:
23164
diff
changeset
|
457 "Validation function: %s"], |
28912
0de38a6ef693
maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents:
28892
diff
changeset
|
458 toupper (opt.name), disp (opt.val))); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
459 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
460 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
461 this.Results.(opt.name) = in; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
462 endwhile |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
463 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
464 ## Fill in with defaults of missing Optional |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
465 while (idx++ < nOpt) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
466 opt = this.Optional{idx}; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
467 this.UsingDefaults{end+1} = opt.name; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
468 this.Results.(opt.name) = opt.def; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
469 endwhile |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
470 |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
471 ## Search unordered Options (Switch and Parameter) |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
472 while (vidx++ < pnargin) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
473 name = varargin{vidx}; |
21667
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
474 |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
475 if (this.StructExpand && isstruct (name) && isscalar (name)) |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
476 expanded_options = [fieldnames(name) struct2cell(name)]'(:); |
25628
a0d642f24349
Parse empty struct input correctly (bug #54318).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
477 if (isempty (expanded_options)) |
a0d642f24349
Parse empty struct input correctly (bug #54318).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
478 continue; # empty, continue to next argument |
a0d642f24349
Parse empty struct input correctly (bug #54318).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
479 endif |
21667
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
480 n_new_args = numel (expanded_options) -1; |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
481 pnargin += n_new_args; |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
482 varargin(vidx+n_new_args+1:pnargin) = varargin(vidx+1:end); |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
483 varargin(vidx:vidx+n_new_args) = expanded_options; |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
484 name = varargin{vidx}; |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
485 endif |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
486 |
23383
62320e943696
inputParser.m: check if Param key and Switch are strings for better errors.
Carnë Draug <carandraug@octave.org>
parents:
23382
diff
changeset
|
487 if (! ischar (name)) |
62320e943696
inputParser.m: check if Param key and Switch are strings for better errors.
Carnë Draug <carandraug@octave.org>
parents:
23382
diff
changeset
|
488 this.error ("non-string for Parameter name or Switch"); |
62320e943696
inputParser.m: check if Param key and Switch are strings for better errors.
Carnë Draug <carandraug@octave.org>
parents:
23382
diff
changeset
|
489 endif |
62320e943696
inputParser.m: check if Param key and Switch are strings for better errors.
Carnë Draug <carandraug@octave.org>
parents:
23382
diff
changeset
|
490 |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
491 if (this.is_argname ("Parameter", name)) |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
492 if (vidx++ > pnargin) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
493 this.error (sprintf ("no matching value for option '%s'", |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
494 toupper (name))); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
495 endif |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19597
diff
changeset
|
496 this.validate_arg (this.last_name, |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
497 this.Parameter.(this.last_name).val, |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
498 varargin{vidx}); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
499 elseif (this.is_argname ("Switch", name)) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
500 this.Results.(this.last_name) = true; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
501 else |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
502 if (vidx++ < pnargin && this.KeepUnmatched) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
503 this.Unmatched.(name) = varargin{vidx}; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
504 else |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
505 this.error (sprintf ("argument '%s' is not a valid parameter", |
23167
a2d6b84ce5c5
scripts/general/inputParser.m: refactor two xtest cases to normal test cases.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23165
diff
changeset
|
506 toupper (name))); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
507 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
508 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
509 endwhile |
23337
f04f32f08590
Override disp rather than display for class objects (bug #50640).
Rik <rik@octave.org>
parents:
23333
diff
changeset
|
510 ## Add them to the UsingDefaults list |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
511 this.add_missing ("Parameter"); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
512 this.add_missing ("Switch"); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
513 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
514 endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
515 |
23337
f04f32f08590
Override disp rather than display for class objects (bug #50640).
Rik <rik@octave.org>
parents:
23333
diff
changeset
|
516 function disp (this) |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
517 |
23333
b636f10ce53f
fix display methods to only expect one argument
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
518 if (nargin != 1) |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
519 print_usage (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
520 endif |
23337
f04f32f08590
Override disp rather than display for class objects (bug #50640).
Rik <rik@octave.org>
parents:
23333
diff
changeset
|
521 printf ("inputParser object with properties:\n\n"); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
522 b2s = @(x) ifelse (any (x), "true", "false"); |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
523 printf ([" CaseSensitive : %s\n FunctionName : %s\n" ... |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
524 " KeepUnmatched : %s\n PartialMatching : %s\n" ... |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
525 " StructExpand : %s\n\n"], |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
526 b2s (this.CaseSensitive), b2s (this.FunctionName), |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
527 b2s (this.KeepUnmatched), b2s (this.PartialMatching), |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
528 b2s (this.StructExpand)); |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
529 printf ("Defined parameters:\n\n {%s}\n", |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
530 strjoin (this.Parameters, ", ")); |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
531 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
532 endfunction |
28945
6e460773bdda
maint: Use newlines after "function" and before "endfunction" for clarity.
Rik <rik@octave.org>
parents:
28929
diff
changeset
|
533 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
534 endmethods |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
535 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
536 methods (Access = private) |
28945
6e460773bdda
maint: Use newlines after "function" and before "endfunction" for clarity.
Rik <rik@octave.org>
parents:
28929
diff
changeset
|
537 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
538 function validate_name (this, type, name) |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
539 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
540 if (! isvarname (name)) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
541 error ("inputParser.add%s: NAME is an invalid identifier", method); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
542 elseif (any (strcmpi (this.Parameters, name))) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
543 ## Even if CaseSensitive is "on", we still shouldn't allow |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
544 ## two args with the same name. |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
545 error ("inputParser.add%s: argname '%s' has already been specified", |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
546 type, name); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
547 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
548 this.Parameters{end+1} = name; |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
549 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
550 endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
551 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
552 function validate_arg (this, name, val, in) |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
553 |
31074
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
554 ## Checking "nargout (val)" doesn't work for builtin functions. |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
555 ## So, we need to use this nested try-catch construct. |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
556 err = sprintf ('Checked with "%s"', func2str (val)); |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
557 try |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
558 ok = val (in); |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
559 catch exception |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
560 if (strcmp (exception.identifier, "Octave:invalid-fun-call")) |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
561 ## check if function also fails when called without output argument |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
562 try |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
563 val (in); |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
564 ok = true; |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
565 catch exception |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
566 ok = false; |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
567 err = exception.message; |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
568 end_try_catch |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
569 else |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
570 ok = false; |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
571 err = exception.message; |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
572 endif |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
573 end_try_catch |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
574 if (! ok) |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
575 this.error (sprintf ("failed validation of %s. %s", |
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
576 toupper (name), err)); |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
577 endif |
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
578 this.Results.(name) = in; |
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
579 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
580 endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
581 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
582 function r = is_argname (this, type, name) |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
583 |
28187
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
584 r = ischar (name) && isrow (name); |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
585 if (r) |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
586 if (this.CaseSensitive) |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
587 r = isfield (this.(type), name); |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
588 if (r) |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
589 this.last_name = name; |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
590 endif |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
591 else |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
592 fnames = this.([type "Names"]); |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
593 l = strcmpi (name, fnames); |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
594 r = any (l(:)); |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
595 if (r) |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
596 this.last_name = fnames{l}; |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
597 endif |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
598 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
599 endif |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
600 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
601 endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
602 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
603 function add_missing (this, type) |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
604 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
605 unmatched = setdiff (fieldnames (this.(type)), fieldnames (this.Results)); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
606 for namec = unmatched(:)' |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
607 name = namec{1}; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
608 this.UsingDefaults{end+1} = name; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
609 this.Results.(name) = this.(type).(name).def; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
610 endfor |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
611 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
612 endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
613 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
614 function error (this, msg) |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
615 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
616 where = ""; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
617 if (this.FunctionName) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
618 where = [this.FunctionName ": "]; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
619 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
620 error ("%s%s", where, msg); |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
621 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
622 endfunction |
28945
6e460773bdda
maint: Use newlines after "function" and before "endfunction" for clarity.
Rik <rik@octave.org>
parents:
28929
diff
changeset
|
623 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
624 endmethods |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
625 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
626 endclassdef |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
627 |
28945
6e460773bdda
maint: Use newlines after "function" and before "endfunction" for clarity.
Rik <rik@octave.org>
parents:
28929
diff
changeset
|
628 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
629 %!function p = create_p () |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
630 %! p = inputParser (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
631 %! p.CaseSensitive = true; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
632 %! p.addRequired ("req1", @(x) ischar (x)); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
633 %! p.addOptional ("op1", "val", @(x) any (strcmp (x, {"val", "foo"}))); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
634 %! p.addOptional ("op2", 78, @(x) x > 50); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
635 %! p.addSwitch ("verbose"); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
636 %! p.addParameter ("line", "tree", @(x) any (strcmp (x, {"tree", "circle"}))); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
637 %!endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
638 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
639 ## check normal use, only required are given |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
640 %!test |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
641 %! p = create_p (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
642 %! p.parse ("file"); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
643 %! r = p.Results; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
644 %! assert (r.req1, "file"); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
645 %! assert (sort (p.UsingDefaults), sort ({"op1", "op2", "verbose", "line"})); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
646 %! assert ({r.req1, r.op1, r.op2, r.verbose, r.line}, |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21578
diff
changeset
|
647 %! {"file", "val", 78, false, "tree"}); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
648 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
649 ## check normal use, but give values different than defaults |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
650 %!test |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
651 %! p = create_p (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
652 %! p.parse ("file", "foo", 80, "line", "circle", "verbose"); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
653 %! r = p.Results; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
654 %! assert ({r.req1, r.op1, r.op2, r.verbose, r.line}, |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
655 %! {"file", "foo", 80, true, "circle"}); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
656 |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
657 ## check optional is skipped and considered Parameter if unvalidated string |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
658 %!test |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
659 %! p = create_p (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
660 %! p.parse ("file", "line", "circle"); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
661 %! r = p.Results; |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19039
diff
changeset
|
662 %! assert ({r.req1, r.op1, r.op2, r.verbose, r.line}, |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
663 %! {"file", "val", 78, false, "circle"}); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
664 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
665 ## check case insensitivity |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
666 %!test |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
667 %! p = create_p (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
668 %! p.CaseSensitive = false; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
669 %! p.parse ("file", "foo", 80, "LiNE", "circle", "vERbOSe"); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
670 %! r = p.Results; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
671 %! assert ({r.req1, r.op1, r.op2, r.verbose, r.line}, |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
672 %! {"file", "foo", 80, true, "circle"}); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
673 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
674 ## check KeepUnmatched |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
675 %!test |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
676 %! p = create_p (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
677 %! p.KeepUnmatched = true; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
678 %! p.parse ("file", "foo", 80, "line", "circle", "verbose", "extra", 50); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21578
diff
changeset
|
679 %! assert (p.Unmatched.extra, 50); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
680 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
681 ## check error when missing required |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
682 %!error <not enough input arguments> |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
683 %! p = create_p (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
684 %! p.parse (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
685 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
686 ## check error when given required does not validate |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
687 %!error <failed validation of > |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
688 %! p = create_p (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
689 %! p.parse (50); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
690 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
691 ## check error when given optional does not validate |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
692 %!error <is not a valid parameter> |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
693 %! p = create_p (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
694 %! p.parse ("file", "no-val"); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
695 |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
696 ## check error when given Parameter does not validate |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
697 %!error <failed validation of > |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
698 %! p = create_p (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
699 %! p.parse ("file", "foo", 51, "line", "round"); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
700 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
701 ## check alternative method (obj, ...) API |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
702 %!function p2 = create_p2 (); |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
703 %! p2 = inputParser (); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
704 %! addRequired (p2, "req1", @(x) ischar (x)); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
705 %! addOptional (p2, "op1", "val", @(x) any (strcmp (x, {"val", "foo"}))); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
706 %! addOptional (p2, "op2", 78, @(x) x > 50); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
707 %! addSwitch (p2, "verbose"); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
708 %! addParameter (p2, "line", "tree", @(x) any (strcmp (x, {"tree", "circle"}))); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
709 %!endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
710 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
711 ## check normal use, only required are given |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
712 %!test |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
713 %! p2 = create_p2 (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
714 %! parse (p2, "file"); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
715 %! r = p2.Results; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
716 %! assert ({r.req1, r.op1, r.op2, r.verbose, r.line}, |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
717 %! {"file", "val", 78, false, "tree"}); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
718 %! assert (sort (p2.UsingDefaults), sort ({"op1", "op2", "verbose", "line"})); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
719 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
720 ## check normal use, but give values different than defaults |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
721 %!test |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
722 %! p2 = create_p2 (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
723 %! parse (p2, "file", "foo", 80, "line", "circle", "verbose"); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
724 %! r = p2.Results; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
725 %! assert ({r.req1, r.op1, r.op2, r.verbose, r.line}, |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
726 %! {"file", "foo", 80, true, "circle"}); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
727 |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
728 ## We must not perform validation of default values |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
729 %!test <*45837> |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
730 %! p = inputParser (); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
731 %! p.addParameter ("Dir", [], @ischar); |
20575
a61f0d6beb71
inputParser: do not perform validation of default values (bug #45837)
Carnë Draug <carandraug@octave.org>
parents:
20470
diff
changeset
|
732 %! p.parse (); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21578
diff
changeset
|
733 %! assert (p.Results.Dir, []); |
20575
a61f0d6beb71
inputParser: do not perform validation of default values (bug #45837)
Carnë Draug <carandraug@octave.org>
parents:
20470
diff
changeset
|
734 |
a61f0d6beb71
inputParser: do not perform validation of default values (bug #45837)
Carnë Draug <carandraug@octave.org>
parents:
20470
diff
changeset
|
735 %!test |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
736 %! p = inputParser (); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
737 %! p.addParameter ("positive", -1, @(x) x > 5); |
20575
a61f0d6beb71
inputParser: do not perform validation of default values (bug #45837)
Carnë Draug <carandraug@octave.org>
parents:
20470
diff
changeset
|
738 %! p.parse (); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21578
diff
changeset
|
739 %! assert (p.Results.positive, -1); |
20575
a61f0d6beb71
inputParser: do not perform validation of default values (bug #45837)
Carnë Draug <carandraug@octave.org>
parents:
20470
diff
changeset
|
740 |
21666
09517e0a8aa0
inputParser.m: handle errors in Optional parameters (maybe is a param key).
Carnë Draug <carandraug@octave.org>
parents:
21634
diff
changeset
|
741 ## Throw an error on validation of optional argument to check that it |
09517e0a8aa0
inputParser.m: handle errors in Optional parameters (maybe is a param key).
Carnë Draug <carandraug@octave.org>
parents:
21634
diff
changeset
|
742 ## is caught without preventing continuation into param/value pairs. |
09517e0a8aa0
inputParser.m: handle errors in Optional parameters (maybe is a param key).
Carnë Draug <carandraug@octave.org>
parents:
21634
diff
changeset
|
743 %!test |
09517e0a8aa0
inputParser.m: handle errors in Optional parameters (maybe is a param key).
Carnë Draug <carandraug@octave.org>
parents:
21634
diff
changeset
|
744 %! p = inputParser (); |
09517e0a8aa0
inputParser.m: handle errors in Optional parameters (maybe is a param key).
Carnë Draug <carandraug@octave.org>
parents:
21634
diff
changeset
|
745 %! p.addOptional ("err", "foo", @error); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
746 %! p.addParameter ("not_err", "bar", @ischar); |
21666
09517e0a8aa0
inputParser.m: handle errors in Optional parameters (maybe is a param key).
Carnë Draug <carandraug@octave.org>
parents:
21634
diff
changeset
|
747 %! p.parse ("not_err", "qux"); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
748 %! assert (p.Results.err, "foo"); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
749 %! assert (p.Results.not_err, "qux"); |
21666
09517e0a8aa0
inputParser.m: handle errors in Optional parameters (maybe is a param key).
Carnë Draug <carandraug@octave.org>
parents:
21634
diff
changeset
|
750 |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
751 ## With more Parameters to test StructExpand |
21667
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
752 %!function p3 = create_p3 (); |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
753 %! p3 = inputParser (); |
21667
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
754 %! addOptional (p3, "op1", "val", @(x) any (strcmp (x, {"val", "foo"}))); |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
755 %! addOptional (p3, "op2", 78, @(x) x > 50); |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
756 %! addSwitch (p3, "verbose"); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
757 %! addParameter (p3, "line", "tree", @(x) any (strcmp (x, {"tree", "circle"}))); |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
758 %! addParameter (p3, "color", "red", @(x) any (strcmp (x, {"red", "green"}))); |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
759 %! addParameter (p3, "style", "tt", @(x) any (strcmp (x, {"tt", "f", "i"}))); |
21667
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
760 %!endfunction |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
761 |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
762 ## Test StructExpand |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
763 %!test |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
764 %! p3 = create_p3 (); |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
765 %! p3.parse (struct ("line", "circle", "color", "green")); |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
766 %! assert (p3.Results, struct ("op1", "val", "op2", 78, "verbose", false, |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
767 %! "line", "circle", "color", "green", |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
768 %! "style", "tt")) |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
769 |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
770 %!test |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
771 %! p3 = create_p3 (); |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
772 %! p3.parse (struct ("line", "circle", "color", "green"), "line", "tree"); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
773 %! assert (p3.Results.line, "tree"); |
21667
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
774 %! p3.parse ("line", "tree", struct ("line", "circle", "color", "green")); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
775 %! assert (p3.Results.line, "circle"); |
21667
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
776 |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
777 %!test # unmatched parameters with StructExpand |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
778 %! p3 = create_p3 (); |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
779 %! p3.KeepUnmatched = true; |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
780 %! p3.parse (struct ("line", "circle", "color", "green", "bar", "baz")); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
781 %! assert (p3.Unmatched.bar, "baz"); |
21667
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
782 |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
783 ## The validation for the second optional argument throws an error with |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
784 ## a struct so check that we can handle it. |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
785 %!test |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
786 %! p3 = create_p3 (); |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
787 %! p3.parse ("foo", struct ("color", "green"), "line", "tree"); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
788 %! assert (p3.Results.op1, "foo"); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
789 %! assert (p3.Results.line, "tree"); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
790 %! assert (p3.Results.color, "green"); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
791 %! assert (p3.Results.verbose, false); |
21667
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
792 |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
793 |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
794 ## Some simple tests for addParamValue since all the other ones use add |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
795 ## addParameter but they use the same codepath. |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
796 %!test |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
797 %! p = inputParser (); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
798 %! addParameter (p, "line", "tree", @(x) any (strcmp (x, {"tree", "circle"}))); |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
799 %! addParameter (p, "color", "red", @(x) any (strcmp (x, {"red", "green"}))); |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
800 %! p.parse ("line", "circle"); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
801 %! assert ({p.Results.line, p.Results.color}, {"circle", "red"}); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
802 |
23167
a2d6b84ce5c5
scripts/general/inputParser.m: refactor two xtest cases to normal test cases.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23165
diff
changeset
|
803 %!test |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
804 %! p = inputParser (); |
23167
a2d6b84ce5c5
scripts/general/inputParser.m: refactor two xtest cases to normal test cases.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23165
diff
changeset
|
805 %! p.addParameter ("foo", "bar", @ischar); |
a2d6b84ce5c5
scripts/general/inputParser.m: refactor two xtest cases to normal test cases.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23165
diff
changeset
|
806 %! p.parse (); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
807 %! assert (p.Results, struct ("foo", "bar")); |
23167
a2d6b84ce5c5
scripts/general/inputParser.m: refactor two xtest cases to normal test cases.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23165
diff
changeset
|
808 %! p.parse ("foo", "qux"); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
809 %! assert (p.Results, struct ("foo", "qux")); |
21508
04923b7b0d89
inputParser.m: add failing test due to bug in the parser (bug #44779)
Carnë Draug <carandraug@octave.org>
parents:
21505
diff
changeset
|
810 |
23377
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
811 ## This behaviour means that a positional option can never be a string |
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
812 ## that is the name of a parameter key. This is required for Matlab |
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
813 ## compatibility. |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
814 %!test <*50752> |
23382
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
815 %! p = inputParser (); |
21505
7f7d7cb73e0d
inputParser.m: uncomment failing test and use %!xtest instead.
Carnë Draug <carandraug@octave.org>
parents:
21316
diff
changeset
|
816 %! p.addOptional ("op1", "val"); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
817 %! p.addParameter ("line", "tree"); |
21505
7f7d7cb73e0d
inputParser.m: uncomment failing test and use %!xtest instead.
Carnë Draug <carandraug@octave.org>
parents:
21316
diff
changeset
|
818 %! p.parse ("line", "circle"); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
819 %! assert (p.Results, struct ("op1", "val", "line", "circle")); |
23377
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
820 %! |
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
821 %! p = inputParser (); |
23382
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
822 %! p.addOptional ("op1", "val1"); |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
823 %! p.addOptional ("op2", "val2"); |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
824 %! p.addParameter ("line", "tree"); |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
825 %! p.parse ("line", "circle"); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
826 %! assert (p.Results.op1, "val1"); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
827 %! assert (p.Results.op2, "val2"); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
828 %! assert (p.Results.line, "circle"); |
23382
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
829 %! |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
830 %! ## If there's enough arguments to fill the positional options and |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
831 %! ## param/key, it still skips positional options. |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
832 %! p = inputParser (); |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
833 %! p.addOptional ("op1", "val1"); |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
834 %! p.addOptional ("op2", "val2"); |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
835 %! p.addParameter ("line", "tree"); |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
836 %! p.parse ("line", "circle", "line", "rectangle"); |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
837 %! assert (p.Results, struct ("op1", "val1", "op2", "val2", |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
838 %! "line", "rectangle")) |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
839 %! |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
840 %! ## Even if the key/param fails validation, it does not backtrack to |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
841 %! ## check if the values are valid positional options. |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
842 %! p = inputParser (); |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
843 %! p.addOptional ("op1", "val1", @ischar); |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
844 %! p.addOptional ("op2", "val2", @isnumeric); |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
845 %! p.addParameter ("line", "circle", @ischar); |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
846 %! fail ('p.parse ("line", 89)', "failed validation of LINE") |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
847 %! |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
848 %! p = inputParser (); |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
849 %! p.addOptional ("op1", "val1"); |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
850 %! p.addParamValue ("line", "circle", @ischar); |
23383
62320e943696
inputParser.m: check if Param key and Switch are strings for better errors.
Carnë Draug <carandraug@octave.org>
parents:
23382
diff
changeset
|
851 %! fail ('p.parse ("line", "line", 89)', |
62320e943696
inputParser.m: check if Param key and Switch are strings for better errors.
Carnë Draug <carandraug@octave.org>
parents:
23382
diff
changeset
|
852 %! "non-string for Parameter name or Switch") |
23382
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
853 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
854 %!test <*50752> |
23382
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
855 %! ## This fails in Matlab but works in Octave. It is a bug there |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
856 %! ## that we do not replicate. |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
857 %! p = inputParser (); |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
858 %! p.addOptional ("op1", "val1"); |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
859 %! p.addParameter ("line", "circle"); |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
860 %! p.parse ("line"); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
861 %! assert (p.Results, struct ("op1", "line", "line", "circle")); |
23377
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
862 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
863 %!test <*50752> |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
864 %! p = inputParser (); |
23377
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
865 %! p.addOptional ("op1", "val1"); |
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
866 %! p.addSwitch ("line"); |
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
867 %! p.parse ("line"); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
868 %! assert (p.Results.op1, "val1"); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
869 %! assert (p.Results.line, true); |
22541
4b7ab10b5c38
inputParser clear previous results before new parse (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22489
diff
changeset
|
870 |
4b7ab10b5c38
inputParser clear previous results before new parse (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22489
diff
changeset
|
871 %!test |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
872 %! p = inputParser (); |
22541
4b7ab10b5c38
inputParser clear previous results before new parse (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22489
diff
changeset
|
873 %! p.addParameter ("a", []); |
4b7ab10b5c38
inputParser clear previous results before new parse (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22489
diff
changeset
|
874 %! p.addParameter ("b", []); |
4b7ab10b5c38
inputParser clear previous results before new parse (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22489
diff
changeset
|
875 %! p.parse ("a", 1); |
4b7ab10b5c38
inputParser clear previous results before new parse (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22489
diff
changeset
|
876 %! p.parse ("b", 1); |
4b7ab10b5c38
inputParser clear previous results before new parse (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22489
diff
changeset
|
877 %! assert (p.Results, struct ("a", [], "b", 1)); |
22559
27f2a7a3b55d
inputParser reset more parse results before new parse. (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22541
diff
changeset
|
878 %! assert (p.UsingDefaults, {"a"}); |
22541
4b7ab10b5c38
inputParser clear previous results before new parse (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22489
diff
changeset
|
879 |
22559
27f2a7a3b55d
inputParser reset more parse results before new parse. (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22541
diff
changeset
|
880 %!test |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
881 %! p = inputParser (); |
22559
27f2a7a3b55d
inputParser reset more parse results before new parse. (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22541
diff
changeset
|
882 %! p.addParameter ("b", []); |
27f2a7a3b55d
inputParser reset more parse results before new parse. (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22541
diff
changeset
|
883 %! p.KeepUnmatched = true; |
27f2a7a3b55d
inputParser reset more parse results before new parse. (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22541
diff
changeset
|
884 %! p.parse ("a", 1); |
27f2a7a3b55d
inputParser reset more parse results before new parse. (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22541
diff
changeset
|
885 %! p.parse ("b", 1); |
27f2a7a3b55d
inputParser reset more parse results before new parse. (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22541
diff
changeset
|
886 %! assert (p.Results, struct ("b", 1)); |
27f2a7a3b55d
inputParser reset more parse results before new parse. (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22541
diff
changeset
|
887 %! assert (p.Unmatched, struct ()); |
23165
5291b67ff124
More verbose information when inputParser fails validating argument (patch #9241)
Georg Wiora
parents:
23164
diff
changeset
|
888 |
5291b67ff124
More verbose information when inputParser fails validating argument (patch #9241)
Georg Wiora
parents:
23164
diff
changeset
|
889 ## Test for patch #9241 |
31074
2c8ab613e805
inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
890 %!error <failed validation of A.*ischar> |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
891 %! p = inputParser (); |
23165
5291b67ff124
More verbose information when inputParser fails validating argument (patch #9241)
Georg Wiora
parents:
23164
diff
changeset
|
892 %! p.addParameter ("a", [], @ischar); |
5291b67ff124
More verbose information when inputParser fails validating argument (patch #9241)
Georg Wiora
parents:
23164
diff
changeset
|
893 %! p.parse ("a", 1); |
28187
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
894 |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
895 %!test <*58112> |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
896 %! p = inputParser (); |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
897 %! p.addRequired ("first"); |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
898 %! p.addOptional ("second", []); |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
899 %! p.parse (1, {"test", 1, 2, 3}); |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
900 %! r = p.Results; |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
901 %! assert (r.first, 1); |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
902 %! assert (r.second, {"test", 1, 2, 3}); |
31103
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
903 |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
904 %!test <*62639> |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
905 %! p = inputParser (); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
906 %! p.addOptional ("opt", {}); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
907 %! p.parse (); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
908 %! r = p.Results; |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
909 %! assert (r.opt, {}); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
910 %! p.parse ("x"); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
911 %! r = p.Results; |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
912 %! assert (r.opt, "x"); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
913 |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
914 %!test <*62639> |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
915 %! p = inputParser (); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
916 %! p.addOptional ("opt", {1,2,3}); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
917 %! p.parse (); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
918 %! r = p.Results; |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
919 %! assert (r.opt, {1,2,3}); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
920 %! p.parse ("x"); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
921 %! r = p.Results; |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
922 %! assert (r.opt, "x"); |