Returns options from key-value pairs.
options=apifun_keyvaluepairs(default) options=apifun_keyvaluepairs(default,key1,value1) options=apifun_keyvaluepairs(default,key1,value1,key2,value2,...)
a struct, the default values of the options
a 1-by-1 matrix of strings, the name of the first option
the value of the first option
a struct, the actual values of the options
The function manages a set of options identified by their keys. The key-value pairs are processed by replacing any actual option by its actual value. This function is designed to be used within functions having optional arguments.
The default
input argument must contain the default values
of the arguments.
Its fields define the set of valid options.
The calling sequence options=apifun_keyvaluepairs (default)
returns options
as a copy of default
.
The calling sequence options=apifun_keyvaluepairs (default,key1,value1)
first checks that key1
is a valid key,
by comparing it to the list of fields of the default
data structure.
If the field is unknown, an error is generated.
If the field is valid, the associated field of options
is set to value1
.
The value1
variable can have any valid data type.
There is no check that value1
has the same type
as the associated field in default
:
the check of the type is left to the user of apifun_keyvaluepairs
.
The other key-value pairs are treated in the same way.
"Why using key=value syntax to manage input arguments is not a good idea", Michael Baudin, 2011, http://wiki.scilab.org/