Mercurial > octave
annotate scripts/miscellaneous/inputParser.m @ 32151:72dcb1cef2c9
maint: Strip trailing whitespace from source files.
Modified files: NEWS.8.md, file-editor-tab.cc, call-stack.cc,
compile.cc, perms.cc, stack-frame.cc, ov-base.cc, ov-fcn-handle.cc,
ov-fcn-handle.h, ov-fcn.cc, ov-oncleanup.h, ov-range.cc, ov-range.h,
ov-ref.cc, ov-ref.h, ov-scalar.h, ov-struct.cc, ov-vm.h,
pt-bytecode-vm-internal.h, pt-bytecode-vm.cc, pt-bytecode-vm.h,
pt-bytecode-walk.cc, pt-eval.cc, isuniform.m, inputParser.m, xlim.m,
ylim.m, zlim.m, movfun.m, std.m, var.m, isstrprop.m, bench.m,
bench.py, bytecode.tst, bytecode_anon_handles.m, bytecode_cell.m,
bytecode_dountil.m, bytecode_end.m, bytecode_errors.m,
bytecode_eval_1.m, bytecode_for.m, bytecode_global_1.m, bytecode_if.m,
bytecode_leaks.m, bytecode_matrix.m, bytecode_multi_assign.m,
bytecode_persistant.m, bytecode_range.m, bytecode_trycatch.m,
bytecode_unwind.m, bytecode_while.m, bytecode_disp.m,
bytecode_disp.tst, parser.tst.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 19 Jun 2023 23:21:41 -0400 |
parents | e3de59065cf1 |
children | addd99059d4c |
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 ## |
31706
597f3ee61a48
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31548
diff
changeset
|
3 ## Copyright (C) 2011-2023 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 |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
46 ## can be parsed with the @code{parse} method and the results accessed with |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
47 ## 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 |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
51 ## Return the list of parameter names already defined. (read-only) |
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 |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
55 ## Return a structure with argument names as fieldnames and corresponding |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
56 ## values. (read-only) |
30353
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 |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
60 ## Return a structure similar to @code{Results}, but for unmatched |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
61 ## parameters. (read-only) |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
62 ## 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
|
63 ## @end deftypefn |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
64 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
65 ## @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
|
66 ## Return cell array with the names of arguments that are using default |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
67 ## values. (read-only) |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
68 ## @end deftypefn |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
69 ## |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
70 ## @deftypefn {} {} inputParser.FunctionName = @var{name} |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
71 ## Set function name to be used in error messages; Defaults to empty string. |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
72 ## @end deftypefn |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
73 ## |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
74 ## @deftypefn {} {} inputParser.CaseSensitive = @var{boolean} |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
75 ## Set whether matching of argument names should be case sensitive; Defaults |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
76 ## to false. |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
77 ## @end deftypefn |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
78 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
79 ## @deftypefn {} {} inputParser.KeepUnmatched = @var{boolean} |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
80 ## Set whether string arguments which do not match any Parameter are parsed |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
81 ## and stored in the @code{Unmatched} property; Defaults to false. If false, |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
82 ## an error will be emitted at the first unrecognized argument and parsing |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
83 ## will stop. Note that since @code{Switch} and @code{Parameter} arguments |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
84 ## can be mixed, it is not possible to know the type of the unmatched |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
85 ## argument. Octave assumes that all unmatched arguments are of the |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
86 ## @code{Parameter} type and therefore must 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
|
87 ## @end deftypefn |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
88 ## |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
89 ## @deftypefn {} {} inputParser.PartialMatching = @var{boolean} |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
90 ## Set whether argument names for @code{Parameter} and @code{Switch} options |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
91 ## may be given in shortened form as long as the name uniquely identifies |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
92 ## an option; Defaults to true. For example, the argument @qcode{'opt'} will |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
93 ## match a parameter @qcode{'opt_color'}, but will fail if there is also a |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
94 ## parameter @qcode{'opt_case'}. |
32036
c5c065221a0e
inputParser.m: Fix missing @end in TexInfo in cset 80fef9315743.
Rik <rik@octave.org>
parents:
32035
diff
changeset
|
95 ## @end deftypefn |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
96 ## |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
97 ## @deftypefn {} {} inputParser.StructExpand = @var{boolean} |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
98 ## Set whether a structure passed to the function is expanded into |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
99 ## parameter/value pairs (parameter = fieldname); Defaults to true. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
100 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
101 ## 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
|
102 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
103 ## @example |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
104 ## function check (varargin) |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
105 ## @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
|
106 ## p = inputParser (); # create object |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
107 ## p.FunctionName = "check"; # set function name |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
108 ## p.addRequired ("pack", @@ischar); # mandatory argument |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
109 ## 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
|
110 ## |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
111 ## ## Create anonymous function handle for validators |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
112 ## valid_vec = @@(x) isvector (x) && all (x >= 0) && all (x <= 1); |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
113 ## p.addOptional ("vec", [0 0], valid_vec); |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
114 ## |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
115 ## ## Create two arguments of type "Parameter" |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
116 ## vld_type = @@(x) any (strcmp (x, @{"linear", "quadratic"@})); |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
117 ## p.addParameter ("type", "linear", vld_type); |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
118 ## vld_tol = @@(x) any (strcmp (x, @{"low", "medium", "high"@})); |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
119 ## p.addParameter ("tolerance", "low", vld_tol); |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
120 ## |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
121 ## ## Create a switch type of argument |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
122 ## p.addSwitch ("verbose"); |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
123 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
124 ## 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
|
125 ## |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
126 ## ## The rest of the function can access inputs by using p.Results. |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
127 ## ## For example, get the tolerance input with p.Results.tolerance |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
128 ## endfunction |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
129 ## @end example |
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 ## @example |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
132 ## @group |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
133 ## 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
|
134 ## check (); # error, one argument is mandatory |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
135 ## check (1); # error, since ! ischar |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
136 ## 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
|
137 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
138 ## 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
|
139 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
140 ## ## following is also valid. Note how the Switch argument type can |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
141 ## ## be mixed in with or before the Parameter argument type (but it |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
142 ## ## must still appear after any Optional arguments). |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
143 ## 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
|
144 ## |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
145 ## ## following returns an error since an Optional argument, 'path', |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
146 ## ## was given after the Parameter argument 'type'. |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
147 ## check ("mech", "type", "linear", "~/dev"); |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
148 ## @end group |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
149 ## @end example |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
150 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
151 ## @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
|
152 ## 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
|
153 ## 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
|
154 ## the @code{Parameter} and @code{Switch} arguments may be mixed |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
155 ## together and they must appear following the first two types. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
156 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
157 ## @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
|
158 ## 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
|
159 ## 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
|
160 ## 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
|
161 ## @code{Parameter} or @code{Switch} arguments. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
162 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
163 ## @seealso{nargin, validateattributes, validatestring, varargin} |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
164 ## @end deftypefn |
19035
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 |
21578
683a1beee538
maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents:
21568
diff
changeset
|
167 ## FIXME: set input checking for these properties |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
168 CaseSensitive = false; |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
169 FunctionName = ""; |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
170 KeepUnmatched = false; |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
171 PartialMatching = true; |
21667
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
172 StructExpand = true; |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
173 endproperties |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
174 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
175 properties (SetAccess = protected) |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19597
diff
changeset
|
176 Parameters = cell (); |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19597
diff
changeset
|
177 Results = struct (); |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19597
diff
changeset
|
178 Unmatched = struct (); |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19597
diff
changeset
|
179 UsingDefaults = cell (); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
180 endproperties |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
181 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
182 properties (Access = protected) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
183 ## 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
|
184 ## 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
|
185 Required = cell (); |
99ca557fd34f
maint: Use Octave whitespace conventions for scripts/general/inputParser.m.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22755
diff
changeset
|
186 Optional = cell (); |
32047
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
187 ## Parameter and Switch are unordered so we use a struct array with |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
188 ## fields "name", "def" (default", and "val" (validator). |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
189 Parameter = struct ([]); # create 0x0 struct array, not scalar struct |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
190 Switch = struct ([]); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
191 |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
192 ## List of Parameter and Switch names to simplify searches |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
193 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
|
194 SwitchNames = cell (); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
195 |
32047
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
196 ## Simplify searches by cacheing the last name and last index of a |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
197 ## match from is_argname() into the Parameter or Switch struct arrays. |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21546
diff
changeset
|
198 last_name = ""; |
32047
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
199 last_idx = 1; |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
200 endproperties |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
201 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
202 properties (Access = protected, Constant = true) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
203 ## 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
|
204 def_val = @(~) true; |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
205 endproperties |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
206 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
207 methods |
28945
6e460773bdda
maint: Use newlines after "function" and before "endfunction" for clarity.
Rik <rik@octave.org>
parents:
28929
diff
changeset
|
208 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
209 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
|
210 |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
211 ## -*- texinfo -*- |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
212 ## @deftypefn {} {} addRequired (@var{argname}) |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
213 ## @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
|
214 ## 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
|
215 ## class. This method belongs to the inputParser class and implements |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
216 ## an ordered-argument type of API. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
217 ## |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
218 ## @var{argname} must be a string with the name of the new argument. The |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
219 ## order in which new arguments are added with @code{addRequired} |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
220 ## 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
|
221 ## |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
222 ## The optional argument @var{validator} is a function (handle or name) |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
223 ## that will return false or throw an error if the input @var{argname} |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
224 ## is invalid. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
225 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
226 ## See @code{help inputParser} for examples. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
227 ## |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
228 ## @emph{Note}: A Required argument can be used together with other |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
229 ## types of 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
|
230 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
231 ## @end deftypefn |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
232 |
28789
28de41192f3c
Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents:
28563
diff
changeset
|
233 if (nargin < 2) |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
234 print_usage (); |
32047
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
235 elseif (numel (this.Optional) |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
236 || numel (this.Parameter) || numel (this.Switch)) |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
237 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
|
238 "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
|
239 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
240 this.validate_name ("Required", name); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
241 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
|
242 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
243 endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
244 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
245 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
|
246 |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
247 ## -*- texinfo -*- |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
248 ## @deftypefn {} {} addOptional (@var{argname}, @var{default}) |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
249 ## @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
|
250 ## Add new optional argument to the object @var{parser} of the class |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
251 ## inputParser to implement an ordered-argument type of API |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
252 ## |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
253 ## @var{argname} must be a string with the name of the new argument. The |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
254 ## order in which new arguments are added with @code{addOptional} |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
255 ## 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
|
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{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
|
258 ## specified. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
259 ## |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
260 ## The optional argument @var{validator} is a function (handle or name) |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
261 ## that will return false or throw an error if the input @var{argname} |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
262 ## is invalid. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
263 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
264 ## See @code{help inputParser} for examples. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
265 ## |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
266 ## @emph{Note1}: If an optional argument is not given a |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
267 ## validator then anything will be valid, and therefore a string in the |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
268 ## correct position (after Required arguments) will be assigned to the |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
269 ## value of the Optional argument @emph{even} if the string is the name |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
270 ## of a Parameter key. @sc{matlab} adds a default validator |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
271 ## @code{@@(x) ~ischar (x)} if none is specified which emits an error |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
272 ## in this instance. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
273 ## |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
274 ## @emph{Note2}: if a string argument fails validation, it will be |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
275 ## considered as a possible Parameter. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
276 ## @end deftypefn |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
277 |
28789
28de41192f3c
Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents:
28563
diff
changeset
|
278 if (nargin < 3) |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
279 print_usage (); |
32047
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
280 elseif (numel (this.Parameter) || numel (this.Switch)) |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
281 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
|
282 "after Parameter or Switch"]); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
283 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
284 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
|
285 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
|
286 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
|
287 endif |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
288 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
|
289 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
290 endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
291 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
292 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
|
293 |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
294 ## -*- texinfo -*- |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
295 ## @deftypefn {} {} addParamValue (@var{argname}, @var{default}) |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
296 ## @deftypefnx {} {} addParamValue (@var{argname}, @var{default}, @var{validator}) |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
297 ## This function is deprecated. Use @code{addParameter} in all new code. |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
298 ## |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
299 ## 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
|
300 ## 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
|
301 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
302 ## This is an alias for @code{addParameter} method without the |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
303 ## @qcode{"PartialMatchPriority"} option. See @code{addParameter} for |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
304 ## the help text. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
305 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
306 ## @end deftypefn |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
307 |
28789
28de41192f3c
Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents:
28563
diff
changeset
|
308 if (nargin < 3) |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
309 print_usage (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
310 endif |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
311 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
|
312 |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
313 endfunction |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
314 |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
315 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
|
316 |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
317 ## -*- texinfo -*- |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
318 ## @deftypefn {} {} addParameter (@var{argname}, @var{default}) |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
319 ## @deftypefnx {} {} addParameter (@var{argname}, @var{default}, @var{validator}) |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
320 ## Add new parameter argument to the object @var{parser} of the class |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
321 ## inputParser 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
|
322 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
323 ## @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
|
324 ## |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
325 ## @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
|
326 ## specified. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
327 ## |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
328 ## The optional argument @var{validator} is a function (handle or name) |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
329 ## that will return false or throw an error if the input @var{argname} |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
330 ## is invalid. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
331 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
332 ## See @code{help inputParser} for examples. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
333 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
334 ## @end deftypefn |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
335 |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
336 if (nargin < 3 || nargin > 6) |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
337 print_usage (); |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
338 endif |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
339 |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
340 n_opt = numel (varargin); |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
341 |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
342 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
|
343 val = inputParser.def_val; |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
344 else # n_opt is 1 or 3 |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
345 val = varargin{1}; |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
346 endif |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
347 |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
348 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
|
349 match_priority = 1; |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
350 else # n_opt is 2 or 3 |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
351 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
|
352 error ("inputParser.addParameter: unrecognized option"); |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
353 endif |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
354 match_priority = varargin{end}; |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
355 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
|
356 "inputParser.addParameter", |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
357 "PartialMatchPriority"); |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
358 endif |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
359 |
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
360 this.validate_name ("Parameter", name); |
32047
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
361 this.Parameter(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
|
362 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
363 endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
364 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
365 function addSwitch (this, name) |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
366 |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
367 ## -*- texinfo -*- |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
368 ## @deftypefn {} {} addSwitch (@var{argname}) |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
369 ## Add new switch argument to the object @var{parser} of the class |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
370 ## inputParser to implement a name/boolean type of API. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
371 ## |
30353
212461a26e9c
doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
372 ## @var{argname} must be a string with the name of the new argument. |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
373 ## |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
374 ## Arguments of this type must be specified after @code{Required} and |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
375 ## @code{Optional} arguments, but can be mixed with any @code{Parameter} |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
376 ## definitions. The default for switch arguments is false. During |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
377 ## parsing, if one of the arguments supplied is a string such as |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
378 ## @var{argname} that matches a defined switch such as |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
379 ## @w{@code{addSwitch (@var{argname})}}, then after parsing the value |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
380 ## of @code{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
|
381 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
382 ## See @code{help inputParser} for examples. |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
383 ## |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
384 ## Compatibility Note: @code{addSwitch} is an Octave extension not |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
385 ## present in @sc{matlab}. |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
386 ## |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
387 ## @end deftypefn |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
388 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
389 if (nargin != 2) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
390 print_usage (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
391 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
392 this.validate_name ("Switch", name); |
32047
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
393 this.Switch(end+1) = struct ("name", name, "def", false); |
31548
c8ad083a5802
maint: Clean up m-files before Octave 8.1 release.
Rik <rik@octave.org>
parents:
31103
diff
changeset
|
394 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
395 endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
396 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
397 function parse (this, varargin) |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
398 |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
399 ## -*- texinfo -*- |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
400 ## @deftypefn {} {} parse (@var{varargin}) |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
401 ## Parse and validate list of arguments according to object @var{parser} |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
402 ## of the class inputParser. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
403 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
404 ## 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
|
405 ## 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
|
406 ## description. |
28378
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
407 ## |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
408 ## @end deftypefn |
8dbe4eec1741
move classdef docstring comments inside classdef definitions
John W. Eaton <jwe@octave.org>
parents:
28187
diff
changeset
|
409 |
22541
4b7ab10b5c38
inputParser clear previous results before new parse (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22489
diff
changeset
|
410 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
|
411 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
|
412 this.UsingDefaults = cell (); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
413 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
|
414 if (this.FunctionName) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
415 print_usage (this.FunctionName); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
416 else |
20726
25d676f9619c
Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20575
diff
changeset
|
417 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
|
418 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
419 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
420 pnargin = numel (varargin); |
32047
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
421 this.ParameterNames = {}; |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
422 if (numel (this.Parameter)) |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
423 this.ParameterNames = {this.Parameter.name}; |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
424 endif |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
425 this.SwitchNames = {}; |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
426 if (numel (this.Switch)) |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
427 this.SwitchNames = {this.Switch.name}; |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
428 endif |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
429 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
430 ## Evaluate the Required arguments first |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
431 nReq = numel (this.Required); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
432 for idx = 1:nReq |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
433 req = this.Required{idx}; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
434 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
|
435 endfor |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
436 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
437 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
|
438 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
439 ## 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
|
440 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
|
441 nOpt = numel (this.Optional); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
442 while (vidx < pnargin && idx < nOpt) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
443 opt = this.Optional{++idx}; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
444 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
|
445 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
|
446 || this.is_argname ("Switch", in)) |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
447 ## The string value looks like an optional parameter/value pair or a |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
448 ## switch. The Optional positional argument which could apply here |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
449 ## is specifically not used (this is Matlab compatible). |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
450 ## See bug #50752. |
23365
7b594fcfa32b
improve inputParser compatibility for optional args (bug #50752)
John W. Eaton <jwe@octave.org>
parents:
23337
diff
changeset
|
451 idx -= 1; |
7b594fcfa32b
improve inputParser compatibility for optional args (bug #50752)
John W. Eaton <jwe@octave.org>
parents:
23337
diff
changeset
|
452 vidx -= 1; |
28917
72d57dbcc305
maint: Add semicolon after break and return keywords.
Rik <rik@octave.org>
parents:
28912
diff
changeset
|
453 break; |
23365
7b594fcfa32b
improve inputParser compatibility for optional args (bug #50752)
John W. Eaton <jwe@octave.org>
parents:
23337
diff
changeset
|
454 endif |
32022
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
455 valid_option = this.validate_arg ("", opt.val, in); |
21666
09517e0a8aa0
inputParser.m: handle errors in Optional parameters (maybe is a param key).
Carnë Draug <carandraug@octave.org>
parents:
21634
diff
changeset
|
456 if (! valid_option) |
32022
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
457 ## If it does not match there are two options: |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
458 ## 1a) it's a Parameter or Switch name and we should use |
23377
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
459 ## the default for the rest; |
32022
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
460 ## 1b) it's a struct with the Parameter pairs. |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
461 ## 2) input is actually wrong and we should error; |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
462 if (ischar (in) |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
463 || (this.StructExpand && isstruct (in) && isscalar (in))) |
20735
418ae0cb752f
Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents:
20726
diff
changeset
|
464 idx -= 1; |
418ae0cb752f
Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents:
20726
diff
changeset
|
465 vidx -= 1; |
28917
72d57dbcc305
maint: Add semicolon after break and return keywords.
Rik <rik@octave.org>
parents:
28912
diff
changeset
|
466 break; |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
467 else |
32015
652a8eb4821f
Fix failing BIST tests caused by cset e2ad5720b29e.
Rik <rik@octave.org>
parents:
32014
diff
changeset
|
468 this.error (sprintf (["failed validation of '%s'\n", ... |
23165
5291b67ff124
More verbose information when inputParser fails validating argument (patch #9241)
Georg Wiora
parents:
23164
diff
changeset
|
469 "Validation function: %s"], |
32014
e2ad5720b29e
inputParser.m: Don't alter case of parameter names in error messages.
Rik <rik@octave.org>
parents:
32012
diff
changeset
|
470 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
|
471 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
472 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
473 this.Results.(opt.name) = in; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
474 endwhile |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
475 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
476 ## 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
|
477 while (idx++ < nOpt) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
478 opt = this.Optional{idx}; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
479 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
|
480 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
|
481 endwhile |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
482 |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
483 ## 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
|
484 while (vidx++ < pnargin) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
485 name = varargin{vidx}; |
21667
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
486 |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
487 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
|
488 expanded_options = [fieldnames(name) struct2cell(name)]'(:); |
25628
a0d642f24349
Parse empty struct input correctly (bug #54318).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
489 if (isempty (expanded_options)) |
a0d642f24349
Parse empty struct input correctly (bug #54318).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
490 continue; # empty, continue to next argument |
a0d642f24349
Parse empty struct input correctly (bug #54318).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
491 endif |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
492 n_new_args = numel (expanded_options) - 1; |
21667
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
493 pnargin += n_new_args; |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
494 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
|
495 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
|
496 name = varargin{vidx}; |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
497 endif |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
498 |
23383
62320e943696
inputParser.m: check if Param key and Switch are strings for better errors.
Carnë Draug <carandraug@octave.org>
parents:
23382
diff
changeset
|
499 if (! ischar (name)) |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
500 this.error ("Parameter or Switch name must be a string"); |
23383
62320e943696
inputParser.m: check if Param key and Switch are strings for better errors.
Carnë Draug <carandraug@octave.org>
parents:
23382
diff
changeset
|
501 endif |
62320e943696
inputParser.m: check if Param key and Switch are strings for better errors.
Carnë Draug <carandraug@octave.org>
parents:
23382
diff
changeset
|
502 |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
503 if (this.is_argname ("Parameter", name)) |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
504 if (++vidx > pnargin) |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
505 this.error (sprintf ("no value for parameter '%s'", name)); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
506 endif |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19597
diff
changeset
|
507 this.validate_arg (this.last_name, |
32047
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
508 this.Parameter(this.last_idx).val, |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
509 varargin{vidx}); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
510 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
|
511 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
|
512 else |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
513 if (vidx++ < pnargin && this.KeepUnmatched) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
514 this.Unmatched.(name) = varargin{vidx}; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
515 else |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
516 this.error (sprintf ("argument '%s' is not a declared parameter or switch", name)); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
517 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
518 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
519 endwhile |
23337
f04f32f08590
Override disp rather than display for class objects (bug #50640).
Rik <rik@octave.org>
parents:
23333
diff
changeset
|
520 ## 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
|
521 this.add_missing ("Parameter"); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
522 this.add_missing ("Switch"); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
523 |
32012
a00c7e103041
inputParser.m: Sort Results and Parameters fields for Matlab Compatibility (bug #64003)
Rik <rik@octave.org>
parents:
32002
diff
changeset
|
524 ## Sort fields for Matlab compatibility (bug #64003) |
a00c7e103041
inputParser.m: Sort Results and Parameters fields for Matlab Compatibility (bug #64003)
Rik <rik@octave.org>
parents:
32002
diff
changeset
|
525 this.Results = orderfields (this.Results); |
a00c7e103041
inputParser.m: Sort Results and Parameters fields for Matlab Compatibility (bug #64003)
Rik <rik@octave.org>
parents:
32002
diff
changeset
|
526 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
527 endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
528 |
23337
f04f32f08590
Override disp rather than display for class objects (bug #50640).
Rik <rik@octave.org>
parents:
23333
diff
changeset
|
529 function disp (this) |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
530 |
23333
b636f10ce53f
fix display methods to only expect one argument
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
531 if (nargin != 1) |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
532 print_usage (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
533 endif |
23337
f04f32f08590
Override disp rather than display for class objects (bug #50640).
Rik <rik@octave.org>
parents:
23333
diff
changeset
|
534 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
|
535 b2s = @(x) ifelse (any (x), "true", "false"); |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
536 printf ([" FunctionName : \"%s\"\n" ... |
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
537 " CaseSensitive : %s\n" ... |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
538 " KeepUnmatched : %s\n" ... |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
539 " PartialMatching : %s\n" ... |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
540 " StructExpand : %s\n\n"], |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
541 this.FunctionName, b2s (this.CaseSensitive), |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
542 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
|
543 b2s (this.StructExpand)); |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
544 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
|
545 strjoin (this.Parameters, ", ")); |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
546 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
547 endfunction |
28945
6e460773bdda
maint: Use newlines after "function" and before "endfunction" for clarity.
Rik <rik@octave.org>
parents:
28929
diff
changeset
|
548 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
549 endmethods |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
550 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
551 methods (Access = private) |
28945
6e460773bdda
maint: Use newlines after "function" and before "endfunction" for clarity.
Rik <rik@octave.org>
parents:
28929
diff
changeset
|
552 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
553 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
|
554 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
555 if (! isvarname (name)) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
556 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
|
557 elseif (any (strcmpi (this.Parameters, name))) |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
558 ## Even if CaseSensitive is true, we still shouldn't allow |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
559 ## two args with the same name. |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
560 error ("inputParser.add%s: argname '%s' has already been declared", |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
561 type, name); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
562 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
563 this.Parameters{end+1} = name; |
32012
a00c7e103041
inputParser.m: Sort Results and Parameters fields for Matlab Compatibility (bug #64003)
Rik <rik@octave.org>
parents:
32002
diff
changeset
|
564 ## Sort Parameters for Matlab compatibility (bug #64003) |
a00c7e103041
inputParser.m: Sort Results and Parameters fields for Matlab Compatibility (bug #64003)
Rik <rik@octave.org>
parents:
32002
diff
changeset
|
565 this.Parameters = sort (this.Parameters); |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
566 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
567 endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
568 |
32022
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
569 function r = 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
|
570 |
32022
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
571 ## Validation function can either produce a true/false result or have |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
572 ## no outputs but throw an error when failing. Tricky code here |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
573 ## relies on side effect, but calls validation function only once |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
574 ## which is a performance win and may also be necessary if validation |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
575 ## function maintains state. See bug #49793. |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
576 ans = true; |
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
|
577 try |
32022
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
578 val (in); # call function with no arguments in case nargout == 0 |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
579 ok = ans; # use side effect of assignment to 'ans' when nargout == 1 |
32047
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
580 catch |
32022
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
581 ok = false; |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
582 end_try_catch |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
583 |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
584 if (nargout > 0) |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
585 r = ok; |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
586 else |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
587 if (! ok) |
32047
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
588 err = sprintf ('Checked with "%s"', func2str (val)); |
32022
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
589 this.error (sprintf ("failed validation of '%s'. %s", name, err)); |
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
|
590 endif |
32022
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
591 this.Results.(name) = in; |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
592 endif |
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
593 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
594 endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
595 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
596 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
|
597 |
28187
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
598 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
|
599 if (r) |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
600 fnames = this.([type "Names"]); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
601 if (this.PartialMatching) |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
602 if (this.CaseSensitive) |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
603 idx = strncmp (name, fnames, numel (name)); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
604 r = sum (idx); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
605 if (r > 1) |
32039
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
606 ## Check for exact match and prefer it over a partial match |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
607 idx2 = strcmp (name, {fnames{idx}}); |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
608 if (any (idx2)) |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
609 idx = (find (idx))(idx2); |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
610 r = 1; |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
611 else |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
612 matches = sprintf ("'%s', ", fnames{idx})(1:end-1); |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
613 matches(end) = '.'; |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
614 this.error (sprintf ("argument '%s' matches more than one %s: %s", name, type, matches)); |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
615 endif |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
616 endif |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
617 r = logical (r); |
32039
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
618 else # not CaseSensitive |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
619 idx = strncmpi (name, fnames, numel (name)); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
620 r = sum (idx); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
621 if (r > 1) |
32039
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
622 idx2 = strcmpi (name, {fnames{idx}}); |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
623 if (any (idx2)) |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
624 idx = (find (idx))(idx2); |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
625 r = 1; |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
626 else |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
627 matches = sprintf ("'%s', ", fnames{idx})(1:end-1); |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
628 matches(end) = '.'; |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
629 this.error (sprintf ("argument '%s' matches more than one %s: %s", name, type, matches)); |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
630 endif |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
631 endif |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
632 r = logical (r); |
28187
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
633 endif |
32039
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
634 else # no PartialMatching |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
635 if (this.CaseSensitive) |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
636 idx = strcmp (name, fnames); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
637 r = any (idx(:)); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
638 else |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
639 idx = strcmpi (name, fnames); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
640 r = any (idx(:)); |
28187
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
641 endif |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
642 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
643 endif |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
644 |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
645 if (r) |
32047
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
646 ## Cache values to simplify and speed up later code. |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
647 this.last_name = fnames{idx}; |
32047
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
648 this.last_idx = find (idx); |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
649 endif |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
650 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
651 endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
652 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
653 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
|
654 |
32047
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
655 if (isempty (this.(type))) |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
656 return; |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
657 endif |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
658 |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
659 ## Implement setdiff() without calling out to function for performance. |
32151
72dcb1cef2c9
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
32047
diff
changeset
|
660 typenames = {this.(type).name}(:); |
32047
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
661 Resultnames = fieldnames (this.Results); |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
662 [sorted, sidx] = sort ([typenames; Resultnames]); |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
663 dups = strcmp (sorted(1:end-1), sorted(2:end)); |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
664 idx = true (size (typenames)); |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
665 idx(sidx(dups)) = false; |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
666 if (any (idx)) |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
667 unmatched_names = typenames(idx); |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
668 unmatched_def = {this.(type)(idx).def}(:); |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
669 this.Results = ... |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
670 cell2struct (vertcat (struct2cell (this.Results), unmatched_def), |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
671 [Resultnames; unmatched_names]); |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
672 this.UsingDefaults = [this.UsingDefaults, unmatched_names]; |
e3de59065cf1
inputParser.m: Re-architect internal data structures for 60% speed improvement.
Rik <rik@octave.org>
parents:
32040
diff
changeset
|
673 endif |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
674 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
675 endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
676 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
677 function error (this, msg) |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30353
diff
changeset
|
678 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
679 where = ""; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
680 if (this.FunctionName) |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
681 where = [this.FunctionName ": "]; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
682 endif |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
683 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
|
684 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
685 endfunction |
28945
6e460773bdda
maint: Use newlines after "function" and before "endfunction" for clarity.
Rik <rik@octave.org>
parents:
28929
diff
changeset
|
686 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
687 endmethods |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
688 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
689 endclassdef |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
690 |
28945
6e460773bdda
maint: Use newlines after "function" and before "endfunction" for clarity.
Rik <rik@octave.org>
parents:
28929
diff
changeset
|
691 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
692 %!function p = create_p () |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
693 %! p = inputParser (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
694 %! p.CaseSensitive = true; |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
695 %! p.PartialMatching = false; |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
696 %! 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
|
697 %! 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
|
698 %! 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
|
699 %! p.addSwitch ("verbose"); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
700 %! 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
|
701 %!endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
702 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
703 ## 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
|
704 %!test |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
705 %! p = create_p (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
706 %! p.parse ("file"); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
707 %! r = p.Results; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
708 %! assert (r.req1, "file"); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
709 %! 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
|
710 %! 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
|
711 %! {"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
|
712 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
713 ## 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
|
714 %!test |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
715 %! p = create_p (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
716 %! 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
|
717 %! r = p.Results; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
718 %! 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
|
719 %! {"file", "foo", 80, true, "circle"}); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
720 |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
721 ## 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
|
722 %!test |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
723 %! p = create_p (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
724 %! p.parse ("file", "line", "circle"); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
725 %! r = p.Results; |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19039
diff
changeset
|
726 %! 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
|
727 %! {"file", "val", 78, false, "circle"}); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
728 |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
729 ## check CaseSensitive (default false state) |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
730 %!test |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
731 %! p = create_p (); |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
732 %! p.CaseSensitive = false; |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
733 %! 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
|
734 %! r = p.Results; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
735 %! 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
|
736 %! {"file", "foo", 80, true, "circle"}); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
737 |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
738 ## check PartialMatching (default true state) |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
739 %!test |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
740 %! p = create_p (); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
741 %! p.PartialMatching = true; |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
742 %! p.parse ("file", "foo", 80, "l", "circle", "verb"); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
743 %! r = p.Results; |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
744 %! assert ({r.req1, r.op1, r.op2, r.verbose, r.line}, |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
745 %! {"file", "foo", 80, true, "circle"}); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
746 |
32039
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
747 ## Check PartialMatching selects an exact match if it exists |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
748 %!test |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
749 %! p = inputParser (); |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
750 %! p.addParameter ('Mass', []); |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
751 %! p.addParameter ('MassSingular', []); |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
752 %! p.parse ("Mass", pi); |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
753 %! r = p.Results; |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
754 %! assert ({r.Mass, r.MassSingular}, {pi, []}); |
01868cd10060
inputParser.m: Choose exact Parameter match if it exists under PartialMatching (bug #64050).
Rik <rik@octave.org>
parents:
32037
diff
changeset
|
755 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
756 ## check KeepUnmatched |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
757 %!test |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
758 %! p = create_p (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
759 %! p.KeepUnmatched = true; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
760 %! 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
|
761 %! 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
|
762 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
763 ## check error when missing required |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
764 %!error <not enough input arguments> |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
765 %! p = create_p (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
766 %! p.parse (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
767 |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
768 ## check error when required arg does not validate |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
769 %!error <failed validation of > |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
770 %! p = create_p (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
771 %! p.parse (50); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
772 |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
773 ## check error when optional arg does not validate |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
774 %!error <is not a declared parameter or switch> |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
775 %! p = create_p (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
776 %! p.parse ("file", "no-val"); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
777 |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
778 ## check error when Parameter arg does not validate |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
779 %!error <failed validation of > |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
780 %! p = create_p (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
781 %! 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
|
782 |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
783 ## check PartialMatching errors |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
784 %!error <'arg' matches more than one Parameter: 'arg123', 'arg456'> |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
785 %! p = inputParser (); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
786 %! p.addParameter ('arg123', 123); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
787 %! p.addParameter ('arg456', 456); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
788 %! p.addSwitch ('arg789'); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
789 %! p.addSwitch ('arg790'); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
790 %! p.parse ('arg', 'bad'); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
791 |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
792 %!error <'arg7' matches more than one Switch: 'arg789', 'arg790'> |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
793 %! p = inputParser (); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
794 %! p.addParameter ('arg123', 123); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
795 %! p.addParameter ('arg456', 456); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
796 %! p.addSwitch ('arg789'); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
797 %! p.addSwitch ('arg790'); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
798 %! p.parse ('arg7', 'bad'); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
799 |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
800 ## check alternative method (obj, ...) API |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
801 %!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
|
802 %! p2 = inputParser (); |
19035
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
803 %! 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
|
804 %! 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
|
805 %! 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
|
806 %! addSwitch (p2, "verbose"); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
807 %! 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
|
808 %!endfunction |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
809 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
810 ## 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
|
811 %!test |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
812 %! p2 = create_p2 (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
813 %! parse (p2, "file"); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
814 %! r = p2.Results; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
815 %! 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
|
816 %! {"file", "val", 78, false, "tree"}); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
817 %! 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
|
818 |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
819 ## 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
|
820 %!test |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
821 %! p2 = create_p2 (); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
822 %! 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
|
823 %! r = p2.Results; |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
824 %! 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
|
825 %! {"file", "foo", 80, true, "circle"}); |
ff820f92cbb5
inputParser: classdef port of @inputParser from Octave Forge general pkg.
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
826 |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
827 ## Octave 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
|
828 %!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
|
829 %! p = inputParser (); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
830 %! 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
|
831 %! p.parse (); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21578
diff
changeset
|
832 %! 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
|
833 |
a61f0d6beb71
inputParser: do not perform validation of default values (bug #45837)
Carnë Draug <carandraug@octave.org>
parents:
20470
diff
changeset
|
834 %!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
|
835 %! p = inputParser (); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
836 %! 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
|
837 %! p.parse (); |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21578
diff
changeset
|
838 %! 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
|
839 |
21666
09517e0a8aa0
inputParser.m: handle errors in Optional parameters (maybe is a param key).
Carnë Draug <carandraug@octave.org>
parents:
21634
diff
changeset
|
840 ## 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
|
841 ## 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
|
842 %!test |
09517e0a8aa0
inputParser.m: handle errors in Optional parameters (maybe is a param key).
Carnë Draug <carandraug@octave.org>
parents:
21634
diff
changeset
|
843 %! p = inputParser (); |
09517e0a8aa0
inputParser.m: handle errors in Optional parameters (maybe is a param key).
Carnë Draug <carandraug@octave.org>
parents:
21634
diff
changeset
|
844 %! 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
|
845 %! 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
|
846 %! p.parse ("not_err", "qux"); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
847 %! assert (p.Results.err, "foo"); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
848 %! 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
|
849 |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
850 ## 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
|
851 %!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
|
852 %! p3 = inputParser (); |
21667
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
853 %! 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
|
854 %! 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
|
855 %! addSwitch (p3, "verbose"); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
856 %! 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
|
857 %! 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
|
858 %! 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
|
859 %!endfunction |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
860 |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
861 ## check StructExpand |
21667
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
862 %!test |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
863 %! p3 = create_p3 (); |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
864 %! 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
|
865 %! 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
|
866 %! "line", "circle", "color", "green", |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
867 %! "style", "tt")) |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
868 |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
869 %!test # check last param/value pair overrides previous |
21667
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
870 %! p3 = create_p3 (); |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
871 %! 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
|
872 %! 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
|
873 %! 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
|
874 %! 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
|
875 |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
876 %!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
|
877 %! p3 = create_p3 (); |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
878 %! p3.KeepUnmatched = true; |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
879 %! 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
|
880 %! 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
|
881 |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
882 ## 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
|
883 ## 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
|
884 %!test |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
885 %! p3 = create_p3 (); |
84092ccb45e2
inputParser.m: implement StructExpand option (struct with param/value pairs).
Carnë Draug <carandraug@octave.org>
parents:
21666
diff
changeset
|
886 %! 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
|
887 %! assert (p3.Results.op1, "foo"); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
888 %! assert (p3.Results.line, "tree"); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
889 %! assert (p3.Results.color, "green"); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
890 %! 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
|
891 |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
892 ## 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
|
893 ## 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
|
894 %!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
|
895 %! p = inputParser (); |
32040
ba0596c25479
inputParser.m: Fix BIST tests designed to test addParamValue method.
Rik <rik@octave.org>
parents:
32039
diff
changeset
|
896 %! addParamValue (p, "line", "tree", @(x) any (strcmp (x, {"tree", "circle"}))); |
ba0596c25479
inputParser.m: Fix BIST tests designed to test addParamValue method.
Rik <rik@octave.org>
parents:
32039
diff
changeset
|
897 %! addParamValue (p, "color", "red", @(x) any (strcmp (x, {"red", "green"}))); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
898 %! p.parse ("line", "circle"); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
899 %! 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
|
900 |
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
|
901 %!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
|
902 %! p = inputParser (); |
32040
ba0596c25479
inputParser.m: Fix BIST tests designed to test addParamValue method.
Rik <rik@octave.org>
parents:
32039
diff
changeset
|
903 %! p.addParamValue ("foo", "bar", @ischar); |
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
|
904 %! p.parse (); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
905 %! 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
|
906 %! p.parse ("foo", "qux"); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
907 %! 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
|
908 |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
909 ## An Optional argument which has a string value that is the name of a |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
910 ## Parameter will be parsed as a Parameter/Value pair. |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
911 ## This is required for Matlab compatibility. |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
912 %!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
|
913 %! p = inputParser (); |
21505
7f7d7cb73e0d
inputParser.m: uncomment failing test and use %!xtest instead.
Carnë Draug <carandraug@octave.org>
parents:
21316
diff
changeset
|
914 %! p.addOptional ("op1", "val"); |
21677
1cd04fb745f6
inputParser: new method addParameter --- just like addParamValue (bug #45367)
Carnë Draug <carandraug@octave.org>
parents:
21668
diff
changeset
|
915 %! p.addParameter ("line", "tree"); |
21505
7f7d7cb73e0d
inputParser.m: uncomment failing test and use %!xtest instead.
Carnë Draug <carandraug@octave.org>
parents:
21316
diff
changeset
|
916 %! p.parse ("line", "circle"); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
917 %! 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
|
918 %! |
f1bf2590272a
inputParser.m: do not confuse Switch options with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23365
diff
changeset
|
919 %! 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
|
920 %! 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
|
921 %! 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
|
922 %! 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
|
923 %! p.parse ("line", "circle"); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
924 %! assert (p.Results.op1, "val1"); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
925 %! assert (p.Results.op2, "val2"); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
926 %! 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
|
927 %! |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
928 %! ## 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
|
929 %! ## 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
|
930 %! 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
|
931 %! 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
|
932 %! 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
|
933 %! 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
|
934 %! 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
|
935 %! 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
|
936 %! "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
|
937 %! |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
938 %! ## 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
|
939 %! ## 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
|
940 %! 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
|
941 %! 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
|
942 %! 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
|
943 %! p.addParameter ("line", "circle", @ischar); |
32015
652a8eb4821f
Fix failing BIST tests caused by cset e2ad5720b29e.
Rik <rik@octave.org>
parents:
32014
diff
changeset
|
944 %! fail ('p.parse ("line", 89)', "failed validation of 'line'") |
23382
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
945 %! |
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
946 %! 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
|
947 %! 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
|
948 %! 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
|
949 %! fail ('p.parse ("line", "line", 89)', |
32037
619e2314ebba
inputParser.m: Overhaul class and documentation.
Rik <rik@octave.org>
parents:
32036
diff
changeset
|
950 %! "Parameter or Switch name must be a string") |
23382
5a3c3ff03167
inputParser.m: more tests for mix Param keys with positional options (bug #50752)
Carnë Draug <carandraug@octave.org>
parents:
23377
diff
changeset
|
951 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
952 %!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
|
953 %! ## 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
|
954 %! ## 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
|
955 %! 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
|
956 %! 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
|
957 %! 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
|
958 %! p.parse ("line"); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
959 %! 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
|
960 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
961 %!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
|
962 %! 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
|
963 %! 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
|
964 %! 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
|
965 %! p.parse ("line"); |
28929
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
966 %! assert (p.Results.op1, "val1"); |
9e43deb9bfc3
maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents:
28917
diff
changeset
|
967 %! 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
|
968 |
4b7ab10b5c38
inputParser clear previous results before new parse (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22489
diff
changeset
|
969 %!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
|
970 %! p = inputParser (); |
22541
4b7ab10b5c38
inputParser clear previous results before new parse (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22489
diff
changeset
|
971 %! p.addParameter ("a", []); |
4b7ab10b5c38
inputParser clear previous results before new parse (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22489
diff
changeset
|
972 %! p.addParameter ("b", []); |
4b7ab10b5c38
inputParser clear previous results before new parse (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22489
diff
changeset
|
973 %! 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
|
974 %! 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
|
975 %! 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
|
976 %! 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
|
977 |
22559
27f2a7a3b55d
inputParser reset more parse results before new parse. (bug #49198)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
22541
diff
changeset
|
978 %!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
|
979 %! 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
|
980 %! 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
|
981 %! 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
|
982 %! 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
|
983 %! 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
|
984 %! 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
|
985 %! assert (p.Unmatched, struct ()); |
23165
5291b67ff124
More verbose information when inputParser fails validating argument (patch #9241)
Georg Wiora
parents:
23164
diff
changeset
|
986 |
5291b67ff124
More verbose information when inputParser fails validating argument (patch #9241)
Georg Wiora
parents:
23164
diff
changeset
|
987 ## Test for patch #9241 |
32015
652a8eb4821f
Fix failing BIST tests caused by cset e2ad5720b29e.
Rik <rik@octave.org>
parents:
32014
diff
changeset
|
988 %!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
|
989 %! p = inputParser (); |
23165
5291b67ff124
More verbose information when inputParser fails validating argument (patch #9241)
Georg Wiora
parents:
23164
diff
changeset
|
990 %! p.addParameter ("a", [], @ischar); |
5291b67ff124
More verbose information when inputParser fails validating argument (patch #9241)
Georg Wiora
parents:
23164
diff
changeset
|
991 %! 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
|
992 |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
993 %!test <*58112> |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
994 %! p = inputParser (); |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
995 %! p.addRequired ("first"); |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
996 %! p.addOptional ("second", []); |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
997 %! 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
|
998 %! r = p.Results; |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
999 %! assert (r.first, 1); |
3faa700d64d4
inputParser.m: Fix error with cell array Optional argument (bug #58112)
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
1000 %! 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
|
1001 |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
1002 %!test <*62639> |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
1003 %! p = inputParser (); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
1004 %! p.addOptional ("opt", {}); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
1005 %! p.parse (); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
1006 %! r = p.Results; |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
1007 %! assert (r.opt, {}); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
1008 %! p.parse ("x"); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
1009 %! r = p.Results; |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
1010 %! assert (r.opt, "x"); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
1011 |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
1012 %!test <*62639> |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
1013 %! p = inputParser (); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
1014 %! 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
|
1015 %! p.parse (); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
1016 %! r = p.Results; |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
1017 %! 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
|
1018 %! p.parse ("x"); |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
1019 %! r = p.Results; |
7797481038fc
inputParser: Add some tests for bug #62639.
Markus Mützel <markus.muetzel@gmx.de>
parents:
31101
diff
changeset
|
1020 %! assert (r.opt, "x"); |
32016
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
1021 |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
1022 %!test <*64003> |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
1023 %! p = inputParser (); |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
1024 %! p.addOptional ('c',3); |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
1025 %! p.addOptional ('z',4); |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
1026 %! p.addParameter ('b',2); |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
1027 %! p.addParameter ('a',1); |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
1028 %! p.parse (30, 'b', 20, 'a',10); |
61b86eaefe80
inputParser.m: Cleanup function documentation and spacing.
Rik <rik@octave.org>
parents:
32015
diff
changeset
|
1029 %! assert (fieldnames (p.Results), {'a'; 'b'; 'c'; 'z'}); |
32022
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
1030 |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
1031 %!test <*49793> |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
1032 %! p = inputParser (); |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
1033 %! p.addRequired ("name", @(x) validateattributes (x, {'char'}, {'nonempty'})); |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
1034 %! p.addOptional ("year", 0001, @(x) validateattributes (x, {'numeric'}, ... |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
1035 %! {'nonempty','integer','positive'})); |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
1036 %! p.addParameter ("color", '-', @(x) validateattributes (x, {'char'}, ... |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
1037 %! {'nonempty'})); |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
1038 %! p.parse ('Jim', 1980, 'color', 'black'); |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
1039 %! assert (p.Results.name, 'Jim'); |
5945e1bd73ea
inputParser.m: Handle validation functions which either return true/false or throw error (bug #49793)
Rik <rik@octave.org>
parents:
32016
diff
changeset
|
1040 %! assert (p.Results.year, 1980); |
32035
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
1041 %! assert (p.Results.color, 'black'); |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
1042 |
80fef9315743
inputParser.m: Implement "PartialMatching" property (bug #64050)
Rik <rik@octave.org>
parents:
32022
diff
changeset
|
1043 |