From: <car...@us...> - 2012-03-30 00:08:44
|
Revision: 10102 http://octave.svn.sourceforge.net/octave/?rev=10102&view=rev Author: carandraug Date: 2012-03-30 00:08:36 +0000 (Fri, 30 Mar 2012) Log Message: ----------- @inputParser/addSwitch: implemented addSwitch method Modified Paths: -------------- trunk/octave-forge/main/general/inst/@inputParser/addOptional.m trunk/octave-forge/main/general/inst/@inputParser/addParamValue.m trunk/octave-forge/main/general/inst/@inputParser/addRequired.m trunk/octave-forge/main/general/inst/@inputParser/addSwitch.m trunk/octave-forge/main/general/inst/@inputParser/createCopy.m trunk/octave-forge/main/general/inst/@inputParser/inputParser.m trunk/octave-forge/main/general/inst/@inputParser/parse.m trunk/octave-forge/main/general/inst/@inputParser/subsref.m Modified: trunk/octave-forge/main/general/inst/@inputParser/addOptional.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/addOptional.m 2012-03-29 22:55:39 UTC (rev 10101) +++ trunk/octave-forge/main/general/inst/@inputParser/addOptional.m 2012-03-30 00:08:36 UTC (rev 10102) @@ -34,7 +34,7 @@ ## @emph{Note}: if @command{ParamValue} arguments are also specified, all @command{Optional} ## arguments will have to be specified before. ## -## @seealso{inputParser, @@inputParser/addParamValue +## @seealso{inputParser, @@inputParser/addParamValue, @@inputParser/addSwitch, ## @@inputParser/addParamValue, @@inputParser/addRequired, @@inputParser/parse} ## @end deftypefn Modified: trunk/octave-forge/main/general/inst/@inputParser/addParamValue.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/addParamValue.m 2012-03-29 22:55:39 UTC (rev 10101) +++ trunk/octave-forge/main/general/inst/@inputParser/addParamValue.m 2012-03-30 00:08:36 UTC (rev 10102) @@ -29,7 +29,7 @@ ## for the parameter with name @var{argname}. Alternatively, a function name ## can be used. ## -## @seealso{inputParser, @@inputParser/addOptional, +## @seealso{inputParser, @@inputParser/addOptional, @@inputParser/addSwitch, ## @@inputParser/addParamValue, @@inputParser/addRequired, @@inputParser/parse} ## @end deftypefn Modified: trunk/octave-forge/main/general/inst/@inputParser/addRequired.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/addRequired.m 2012-03-29 22:55:39 UTC (rev 10101) +++ trunk/octave-forge/main/general/inst/@inputParser/addRequired.m 2012-03-30 00:08:36 UTC (rev 10102) @@ -37,7 +37,7 @@ ## it must be the first (see @command{@@inputParser}). ## ## @seealso{inputParser, @@inputParser/addOptional, @@inputParser/addParamValue -## @@inputParser/addParamValue, @@inputParser/parse} +## @@inputParser/addParamValue, @@inputParser/addSwitch, @@inputParser/parse} ## @end deftypefn function inPar = addRequired (inPar, name, val) Modified: trunk/octave-forge/main/general/inst/@inputParser/addSwitch.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/addSwitch.m 2012-03-29 22:55:39 UTC (rev 10101) +++ trunk/octave-forge/main/general/inst/@inputParser/addSwitch.m 2012-03-30 00:08:36 UTC (rev 10102) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 Carnë Draug <car...@gm...> +## Copyright (C) 2011-2012 Carnë Draug <car...@gm...> ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software @@ -14,11 +14,35 @@ ## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{parser} =} addSwitch (@var{parser}, @var{argname}, @var{default}) -## @deftypefnx {Function File} {@var{parser} =} @var{parser}.addSwitch (@var{argname}, @var{default}) -## Not implemented yet +## @deftypefn {Function File} {@var{parser} =} addSwitch (@var{parser}, @var{argname}) +## @deftypefnx {Function File} {@var{parser} =} @var{parser}.addSwitch (@var{argname}) +## Add new switch type of argument to the object @var{parser} of inputParser class. +## +## This method belongs to the inputParser class and implements a switch +## arguments type of API. +## +## @var{argname} must be a string with the name of the new argument. Arguments +## of this type can be specified at the end, after @code{Required} and @code{Optional}, +## and mixed between the @code{ParamValue}. They default to false. If one of the +## arguments supplied is a string like @var{argname}, then after parsing the value +## of @var{parse}.Results.@var{argname} will be true. +## +## See @command{help @@inputParser} for examples. +## +## @seealso{inputParser, @@inputParser/addOptional, @@inputParser/addParamValue +## @@inputParser/addParamValue, @@inputParser/addRequired, @@inputParser/parse} ## @end deftypefn -function inPar = addSwitch (inPar, name, def) +function inPar = addSwitch (inPar, name) + ## check @inputParser/subsref for the actual code + if (nargin == 2) + inPar = subsref (inPar, substruct( + '.' , 'addParamValue', + '()', {name} + )); + else + print_usage; + endif + endfunction Modified: trunk/octave-forge/main/general/inst/@inputParser/createCopy.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/createCopy.m 2012-03-29 22:55:39 UTC (rev 10101) +++ trunk/octave-forge/main/general/inst/@inputParser/createCopy.m 2012-03-30 00:08:36 UTC (rev 10102) @@ -19,7 +19,7 @@ ## class. ## ## @seealso{inputParser, @@inputParser/addOptional, @@inputParser/addParamValue -## @@inputParser/addParamValue, @@inputParser/addRequired, +## @@inputParser/addParamValue, @@inputParser/addRequired, @@inputParser/addSwitch, ## @@inputParser/parse} ## @end deftypefn Modified: trunk/octave-forge/main/general/inst/@inputParser/inputParser.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/inputParser.m 2012-03-29 22:55:39 UTC (rev 10101) +++ trunk/octave-forge/main/general/inst/@inputParser/inputParser.m 2012-03-30 00:08:36 UTC (rev 10102) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 Carnë Draug <car...@gm...> +## Copyright (C) 2011-2012 Carnë Draug <car...@gm...> ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software @@ -24,7 +24,7 @@ ## @item mandatory (see @command{@@inputParser/addRequired}); ## @item optional (see @command{@@inputParser/addOptional}); ## @item named (see @command{@@inputParser/addParamValue}); -## @item switch (not implemented yet). +## @item switch (see @command{@@inputParser/addSwitch}). ## @end enumerate ## ## After defining the function API with this methods, the supplied arguments can @@ -53,7 +53,10 @@ ## @deftypefnx {Class property} parser.KeepUnmatched = @var{boolean} ## Set whether an error should be given for non-defined arguments. Defaults to ## false. If set to true, the extra arguments can be accessed through -## @code{Unmatched} after the @code{parse} method. +## @code{Unmatched} after the @code{parse} method. Note that since @command{Switch} +## and @command{ParamValue} arguments can be mixed, it is not possible to know +## the unmatched type. If argument is found unmatched it is assumed to be of the +## @command{ParamValue} type and it is expected to be followed by a value. ## ## @deftypefnx {Class property} parser.StructExpand = @var{boolean} ## Set whether a structure can be passed to the function instead of parameter @@ -77,13 +80,16 @@ ## ## create two ParamValue type of arguments ## val_type = @@(x) ischar(x) && any(strcmp(x, @{"linear", "quadratic"@}); ## p = p.addParamValue ("type", "linear", @@val_type); -## val_verb = @@(x) ischar(x) && any(strcmp(x, @{"silent", "verbose", "debug"@}); -## p = p.addParamValue ("verbosity", "silent", @@val_verb)'; +## val_verb = @@(x) ischar(x) && any(strcmp(x, @{"low", "medium", "high"@}); +## p = p.addParamValue ("tolerance", "low", @@val_verb); ## +## ## create a switch type of argument +## p = p.addSwitch ("verbose"); +## ## p = p.parse (pack, path, mat, varargin@{:@}); ## ## ## the rest of the function can access the input by accessing p.Results -## ## for example, to access the value of verbosity, use p.Results.verbosity +## ## for example, to access the value of tolerance, use p.Results.tolerance ## endfunction ## ## check ("mech"); # valid, will use defaults for other arguments @@ -93,6 +99,10 @@ ## ## check ("mech", "~/dev", [0 1 0 0], "type", "linear"); # valid ## +## ## the following is also valid. Note how the Switch type of argument can be +## ## mixed into or before the ParamValue (but still after Optional) +## check ("mech", "~/dev", [0 1 0 0], "verbose", "tolerance", "high"); +## ## ## the following returns an error since not all optional arguments, `path' and ## ## `mat', were given before the named argument `type'. ## check ("mech", "~/dev", "type", "linear"); @@ -107,7 +117,8 @@ ## ## @emph{Note 2}: if both @command{Optional} and @command{ParamValue} arguments ## are mixed in a function API, the user will have to specify @emph{all} -## @command{Optional} arguments before the @command{ParamValue} arguments. +## @command{Optional} arguments before the @command{ParamValue} and +## @command{Switch}arguments. ## ## @seealso{@@inputParser/addOptional, @@inputParser/addSwitch, ## @@inputParser/addParamValue, @@inputParser/addRequired, @@ -128,6 +139,7 @@ inPar.ParamValue = struct; inPar.Optional = struct; inPar.Required = struct; + inPar.Switch = struct; ## this will be filled when the methodd parse is used and will be a struct whose ## fieldnames are the argnames that return their value Modified: trunk/octave-forge/main/general/inst/@inputParser/parse.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/parse.m 2012-03-29 22:55:39 UTC (rev 10101) +++ trunk/octave-forge/main/general/inst/@inputParser/parse.m 2012-03-30 00:08:36 UTC (rev 10102) @@ -23,7 +23,7 @@ ## accessor. See @command{help inputParser} for a more complete description. ## ## @seealso{inputParser, @@inputParser/addOptional, @@inputParser/addParamValue -## @@inputParser/addParamValue, @@inputParser/addRequired} +## @@inputParser/addParamValue, @@inputParser/addRequired, @@inputParser/addSwitch} ## @end deftypefn function inPar = parse (inPar, varargin) Modified: trunk/octave-forge/main/general/inst/@inputParser/subsref.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/subsref.m 2012-03-29 22:55:39 UTC (rev 10101) +++ trunk/octave-forge/main/general/inst/@inputParser/subsref.m 2012-03-30 00:08:36 UTC (rev 10102) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 Carnë Draug <car...@gm...> +## Copyright (C) 2011-2012 Carnë Draug <car...@gm...> ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software @@ -38,7 +38,7 @@ inPar = parse_args (inPar, idx); case 'Unmatched' case 'UsingDefaults' - case {'addOptional', 'addParamValue', 'addRequired'} + case {'addOptional', 'addParamValue', 'addRequired', 'addSwitch'} inPar = check_methods (inPar, idx); otherwise error ("invalid index for reference of class %s", class (inPar) ); @@ -109,39 +109,47 @@ inPar.Results.(name) = value; endfor - ## only ParamValue can be after Optional so their number must be even - if ( rem (numel (args), 2) ) - error("%sodd number of Parameter/Values arguments", inPar.FunctionName); - endif - ## loop a maximum #times of the number of ParamValue, taking pairs of keys and ## values out 'args'. We no longer expect an order so we need the index in ## 'copy' to remove it from there. Once ran out of 'args', move their name ## into usingDefaults, place their default values into 'Results', and break - for i = 1 : numel (fieldnames (inPar.ParamValue)) + for i = 1 : (numel (fieldnames (inPar.ParamValue)) + numel (fieldnames (inPar.Switch))) if ( !numel (args) ) ## loops the number of times left in 'copy' since these are the last type for n = 1 : numel (inPar.copy) [name, inPar.copy] = pop (inPar.copy); inPar.UsingDefaults = push (inPar.UsingDefaults, name); - inPar.Results.(name) = inPar.ParamValue.(name).default; + if (isfield (inPar.ParamValue, name)) + inPar.Results.(name) = inPar.ParamValue.(name).default; + else + inPar.Results.(name) = inPar.Switch.(name).default; + endif endfor break endif - [key, args] = pop (args); - [value, args] = pop (args); + [key, args] = pop (args); if ( !ischar (key) ) - error("%sParameter names must be strings", inPar.FunctionName); + error("%sParameter/Switch names must be strings", inPar.FunctionName); endif if (inPar.CaseSensitive) index = find( strcmp(inPar.copy, key)); else index = find( strcmpi(inPar.copy, key)); endif + ## we can't use isfield here to support case insensitive + if (any (strcmpi (fieldnames (inPar.Switch), key))) + value = true; + method = "Switch"; + else + ## then it must be a ParamValue, pop its value + [value, args] = pop (args); + method = "ParamValue"; + endif + ## index == 0 means no match so either return error or move them into 'Unmatched' if ( index != 0 ) [name, inPar.copy] = pop (inPar.copy, index); - if ( !feval (inPar.ParamValue.(name).validator, value) ) + if ( !feval (inPar.(method).(name).validator, value)) error("%sinvalid value for parameter '%s'", inPar.FunctionName, key); endif ## we use the name popped from 'copy' instead of the key from 'args' in case @@ -188,7 +196,7 @@ ## a validator is optional but that complicates handling all the parsing with ## few functions and conditions. If not specified @() true will always return ## true. Simply using true is not enough because if the argument is zero it - ## return false and it it's too large, takes up memory + ## return false and if it's too large, takes up memory switch method case {'addOptional', 'addParamValue'} if ( numel (args) == 1 ) @@ -208,6 +216,9 @@ print_usage(func); endif def = false; + case {'addSwitch'} + val = def_val; + def = false; otherwise error ("invalid index for reference of class %s", class (inPar) ); endswitch @@ -238,13 +249,14 @@ endif ## because the order arguments are specified are the order they are expected, - ## can't have ParamValue before Optional, and Optional before Required + ## can't have ParamValue/Switch before Optional, and Optional before Required n_optional = numel (fieldnames (inPar.Optional)); n_params = numel (fieldnames (inPar.ParamValue)); - if ( strcmp (method, 'Required') && ( n_optional || n_params ) ) - error ("Can't specify 'Required' arguments after Optional or ParamValue"); - elseif ( strcmp (method, 'Optional') && n_params ) - error ("Can't specify 'Required' arguments after Optional or ParamValue"); + n_switch = numel (fieldnames (inPar.Switch)); + if ( strcmp (method, 'Required') && ( n_optional || n_params || n_switch) ) + error ("Can't specify 'Required' arguments after Optional, ParamValue or Switch"); + elseif ( strcmp (method, 'Optional') && ( n_params || n_switch) ) + error ("Can't specify 'Optional' arguments after ParamValue or Switch"); endif ## even if CaseSensitive is turned on, we still shouldn't have two args with This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-04-20 13:17:38
|
Revision: 10299 http://octave.svn.sourceforge.net/octave/?rev=10299&view=rev Author: carandraug Date: 2012-04-20 13:17:29 +0000 (Fri, 20 Apr 2012) Log Message: ----------- inputParser: small adjustement on documentation Modified Paths: -------------- trunk/octave-forge/main/general/inst/@inputParser/addOptional.m trunk/octave-forge/main/general/inst/@inputParser/addParamValue.m trunk/octave-forge/main/general/inst/@inputParser/addRequired.m trunk/octave-forge/main/general/inst/@inputParser/addSwitch.m Modified: trunk/octave-forge/main/general/inst/@inputParser/addOptional.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/addOptional.m 2012-04-19 18:28:07 UTC (rev 10298) +++ trunk/octave-forge/main/general/inst/@inputParser/addOptional.m 2012-04-20 13:17:29 UTC (rev 10299) @@ -31,6 +31,8 @@ ## for the argument with name @var{argname}. Alternatively, a function name ## can be used. ## +## See @command{help @inputParser} for examples. +## ## @emph{Note}: if @command{ParamValue} arguments are also specified, all @command{Optional} ## arguments will have to be specified before. ## Modified: trunk/octave-forge/main/general/inst/@inputParser/addParamValue.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/addParamValue.m 2012-04-19 18:28:07 UTC (rev 10298) +++ trunk/octave-forge/main/general/inst/@inputParser/addParamValue.m 2012-04-20 13:17:29 UTC (rev 10299) @@ -29,6 +29,8 @@ ## for the parameter with name @var{argname}. Alternatively, a function name ## can be used. ## +## See @command{help @inputParser} for examples. +## ## @seealso{inputParser, @@inputParser/addOptional, @@inputParser/addSwitch, ## @@inputParser/addParamValue, @@inputParser/addRequired, @@inputParser/parse} ## @end deftypefn Modified: trunk/octave-forge/main/general/inst/@inputParser/addRequired.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/addRequired.m 2012-04-19 18:28:07 UTC (rev 10298) +++ trunk/octave-forge/main/general/inst/@inputParser/addRequired.m 2012-04-20 13:17:29 UTC (rev 10299) @@ -31,7 +31,7 @@ ## for the argument with name @var{argname}. Alternatively, a function name ## can be used. ## -## See @command{help @@inputParser} for examples. +## See @command{help @inputParser} for examples. ## ## @emph{Note}: this can be used together with the other type of arguments but ## it must be the first (see @command{@@inputParser}). Modified: trunk/octave-forge/main/general/inst/@inputParser/addSwitch.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/addSwitch.m 2012-04-19 18:28:07 UTC (rev 10298) +++ trunk/octave-forge/main/general/inst/@inputParser/addSwitch.m 2012-04-20 13:17:29 UTC (rev 10299) @@ -27,7 +27,7 @@ ## arguments supplied is a string like @var{argname}, then after parsing the value ## of @var{parse}.Results.@var{argname} will be true. ## -## See @command{help @@inputParser} for examples. +## See @command{help inputParser} for examples. ## ## @seealso{inputParser, @@inputParser/addOptional, @@inputParser/addParamValue ## @@inputParser/addParamValue, @@inputParser/addRequired, @@inputParser/parse} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-05-10 14:55:38
|
Revision: 10401 http://octave.svn.sourceforge.net/octave/?rev=10401&view=rev Author: carandraug Date: 2012-05-10 14:55:27 +0000 (Thu, 10 May 2012) Log Message: ----------- inputParser: if a supposed Optional argument is a string and fails to validate, consider start of ParamValue arguments Modified Paths: -------------- trunk/octave-forge/main/general/inst/@inputParser/addOptional.m trunk/octave-forge/main/general/inst/@inputParser/inputParser.m trunk/octave-forge/main/general/inst/@inputParser/subsref.m Modified: trunk/octave-forge/main/general/inst/@inputParser/addOptional.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/addOptional.m 2012-05-10 13:18:41 UTC (rev 10400) +++ trunk/octave-forge/main/general/inst/@inputParser/addOptional.m 2012-05-10 14:55:27 UTC (rev 10401) @@ -33,8 +33,11 @@ ## ## See @command{help @inputParser} for examples. ## -## @emph{Note}: if @command{ParamValue} arguments are also specified, all @command{Optional} -## arguments will have to be specified before. +## @emph{Note}: if a string argument does not validate, it will be considered a +## ParamValue key. If an optional argument is not given a validator, anything +## will be valid, and so any string will be considered will be the value of the +## optional argument (in @sc{matlab}, if no validator is given and argument is +## a string it will also be considered a ParamValue key). ## ## @seealso{inputParser, @@inputParser/addParamValue, @@inputParser/addSwitch, ## @@inputParser/addParamValue, @@inputParser/addRequired, @@inputParser/parse} Modified: trunk/octave-forge/main/general/inst/@inputParser/inputParser.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/inputParser.m 2012-05-10 13:18:41 UTC (rev 10400) +++ trunk/octave-forge/main/general/inst/@inputParser/inputParser.m 2012-05-10 14:55:27 UTC (rev 10401) @@ -116,9 +116,9 @@ ## must be at the end. ## ## @emph{Note 2}: if both @command{Optional} and @command{ParamValue} arguments -## are mixed in a function API, the user will have to specify @emph{all} -## @command{Optional} arguments before the @command{ParamValue} and -## @command{Switch}arguments. +## are mixed in a function API, once a string Optional argument fails to validate +## against, it will be considered the end of @command{Optional} arguments and the +## first key for a @command{ParamValue} and @command{Switch} arguments. ## ## @seealso{@@inputParser/addOptional, @@inputParser/addSwitch, ## @@inputParser/addParamValue, @@inputParser/addRequired, Modified: trunk/octave-forge/main/general/inst/@inputParser/subsref.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/subsref.m 2012-05-10 13:18:41 UTC (rev 10400) +++ trunk/octave-forge/main/general/inst/@inputParser/subsref.m 2012-05-10 14:55:27 UTC (rev 10401) @@ -59,7 +59,7 @@ ## when parsing options, here's the principle: Required options have to be the ## first ones. They are followed by Optional if any. In the end come the -## ParamValue. Any other order makes no sense +## ParamValue mixed with Switch. Any other order makes no sense function inPar = parse_args (inPar, idx) ## make copy of ordered list of Parameters to keep the original intact and readable @@ -80,8 +80,8 @@ ## we take names out of 'copy' and values out of 'args', evaluate them and ## store them into 'Results' for i = 1 : numel (fieldnames (inPar.Required)) - [name, inPar.copy] = pop (inPar.copy); - [value, args] = pop (args); + [name, inPar.copy] = shift (inPar.copy); + [value, args] = shift (args); if ( !feval (inPar.Required.(name).validator, value) ) error("%sinvalid value for parameter '%s'", inPar.FunctionName, name); endif @@ -91,22 +91,39 @@ ## loop a maximum #times of the number of Optional, similarly to the required ## loop. Once ran out of 'args', move their name into usingDefaults, place ## their default values into 'Results', and break + + ## because if an argument is string and does not validate, should be considered + ## a ParamValue key + found_possible_key = false; + for i = 1 : numel (fieldnames (inPar.Optional)) - if ( !numel (args) ) + if ( !numel (args) || found_possible_key) ## loops the number of Optional options minus the number of them already processed for n = 1 : (numel (fieldnames (inPar.Optional)) - i + 1 ) - [name, inPar.copy] = pop (inPar.copy); + [name, inPar.copy] = shift (inPar.copy); inPar.UsingDefaults = push (inPar.UsingDefaults, name); inPar.Results.(name) = inPar.Optional.(name).default; endfor break endif - [name, inPar.copy] = pop (inPar.copy); - [value, args] = pop (args); + [name, inPar.copy] = shift (inPar.copy); + [value, args] = shift (args); if ( !feval (inPar.Optional.(name).validator, value) ) - error("%sinvalid value for parameter '%s'", inPar.FunctionName, name); + if (ischar (value) ) + ## maybe the other optional are not defined, this can be Paramvalue + ## place this one on defaults and go back to the top with note to clean loop + inPar.UsingDefaults = push (inPar.UsingDefaults, name); + inPar.Results.(name) = inPar.Optional.(name).default; + found_possible_key = true; + args = unshift (args, value); + continue + else + error("%sinvalid value for parameter '%s'", inPar.FunctionName, name); + endif + else + + inPar.Results.(name) = value; endif - inPar.Results.(name) = value; endfor ## loop a maximum #times of the number of ParamValue, taking pairs of keys and @@ -117,7 +134,7 @@ if ( !numel (args) ) ## loops the number of times left in 'copy' since these are the last type for n = 1 : numel (inPar.copy) - [name, inPar.copy] = pop (inPar.copy); + [name, inPar.copy] = shift (inPar.copy); inPar.UsingDefaults = push (inPar.UsingDefaults, name); if (isfield (inPar.ParamValue, name)) inPar.Results.(name) = inPar.ParamValue.(name).default; @@ -127,7 +144,7 @@ endfor break endif - [key, args] = pop (args); + [key, args] = shift (args); if ( !ischar (key) ) error("%sParameter/Switch names must be strings", inPar.FunctionName); endif @@ -141,18 +158,18 @@ value = true; method = "Switch"; else - ## then it must be a ParamValue, pop its value - [value, args] = pop (args); + ## then it must be a ParamValue, shift its value + [value, args] = shift (args); method = "ParamValue"; endif ## index == 0 means no match so either return error or move them into 'Unmatched' if ( index != 0 ) - [name, inPar.copy] = pop (inPar.copy, index); + [name, inPar.copy] = shift (inPar.copy, index); if ( !feval (inPar.(method).(name).validator, value)) error("%sinvalid value for parameter '%s'", inPar.FunctionName, key); endif - ## we use the name popped from 'copy' instead of the key from 'args' in case + ## we use the name shifted from 'copy' instead of the key from 'args' in case ## the key is in the wrong case inPar.Results.(name) = value; elseif ( index == 0 && inPar.KeepUnmatched ) @@ -167,8 +184,8 @@ ## have already been processed in the ParamValue loop if ( numel (args) && inPar.KeepUnmatched ) for i = 1 : ( numel(args) / 2 ) - [key, args] = pop (args); - [value, args] = pop (args); + [key, args] = shift (args); + [value, args] = shift (args); inPar.Unmatched.(key) = value; endfor elseif ( numel (args) ) @@ -192,7 +209,7 @@ print_usage (func); endif def_val = @() true; - [name, args] = pop (args); + [name, args] = shift (args); ## a validator is optional but that complicates handling all the parsing with ## few functions and conditions. If not specified @() true will always return ## true. Simply using true is not enough because if the argument is zero it @@ -285,11 +302,19 @@ ## very auxiliary functions ################################################################################ -function [out, in] = pop (in, idx = 1) +function [out, in] = shift (in, idx = 1) out = in{idx}; in(idx) = []; endfunction +function [in] = unshift (in, add) + if ( !iscell (add) ) + add = {add}; + endif + in (numel(add) + 1 : end + numel(add)) = in; + in (1:numel(add)) = add; +endfunction + function [in] = push (in, add) if ( !iscell (add) ) add = {add}; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-05-14 09:04:34
|
Revision: 10437 http://octave.svn.sourceforge.net/octave/?rev=10437&view=rev Author: carandraug Date: 2012-05-14 09:04:23 +0000 (Mon, 14 May 2012) Log Message: ----------- inputParser: texinfo fixes Modified Paths: -------------- trunk/octave-forge/main/general/inst/@inputParser/addOptional.m trunk/octave-forge/main/general/inst/@inputParser/addParamValue.m trunk/octave-forge/main/general/inst/@inputParser/addRequired.m Modified: trunk/octave-forge/main/general/inst/@inputParser/addOptional.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/addOptional.m 2012-05-14 08:46:11 UTC (rev 10436) +++ trunk/octave-forge/main/general/inst/@inputParser/addOptional.m 2012-05-14 09:04:23 UTC (rev 10437) @@ -31,7 +31,7 @@ ## for the argument with name @var{argname}. Alternatively, a function name ## can be used. ## -## See @command{help @inputParser} for examples. +## See @command{help inputParser} for examples. ## ## @emph{Note}: if a string argument does not validate, it will be considered a ## ParamValue key. If an optional argument is not given a validator, anything Modified: trunk/octave-forge/main/general/inst/@inputParser/addParamValue.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/addParamValue.m 2012-05-14 08:46:11 UTC (rev 10436) +++ trunk/octave-forge/main/general/inst/@inputParser/addParamValue.m 2012-05-14 09:04:23 UTC (rev 10437) @@ -29,7 +29,7 @@ ## for the parameter with name @var{argname}. Alternatively, a function name ## can be used. ## -## See @command{help @inputParser} for examples. +## See @command{help inputParser} for examples. ## ## @seealso{inputParser, @@inputParser/addOptional, @@inputParser/addSwitch, ## @@inputParser/addParamValue, @@inputParser/addRequired, @@inputParser/parse} Modified: trunk/octave-forge/main/general/inst/@inputParser/addRequired.m =================================================================== --- trunk/octave-forge/main/general/inst/@inputParser/addRequired.m 2012-05-14 08:46:11 UTC (rev 10436) +++ trunk/octave-forge/main/general/inst/@inputParser/addRequired.m 2012-05-14 09:04:23 UTC (rev 10437) @@ -31,7 +31,7 @@ ## for the argument with name @var{argname}. Alternatively, a function name ## can be used. ## -## See @command{help @inputParser} for examples. +## See @command{help inputParser} for examples. ## ## @emph{Note}: this can be used together with the other type of arguments but ## it must be the first (see @command{@@inputParser}). This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |