Fix parser
Fixes #445 (closed).
I am using a new variable in the parameter
structure (is_default
) that I set to 1 if we write in params a default value.
Currently I am only checking on the get_opt_params
function. I am wondering if we should ensure that we are not reading a mandatory parameter from a default value.
For example:
parser_get_opt_param_double(params, "Test:test", 1.); // Test:test does not exist in params
parser_get_param_double(params, "Test:test"); // Here currently we read the previous default value without any warning
Merge request reports
Activity
So now we can ask for the same parameter multiple times as long as we provide the same default value. If
Test:test1
does not exists:/* This one pass and write in parser the parameter */ double a = parser_get_opt_param_double(parser, "Test:test1", 1.); /* This one pass and return the default value 1. which is the same than in the previous call */ a = parser_get_opt_param_double(parser, "Test:test1", 1.); /* This one fails because the previous default value is not the same */ a = parser_get_opt_param_double(parser, "Test:test1", 0.);
For the non optional parameters, the behavior is still the same. If we consider that
Test:test2
does not exist:/* Here we fails because Test:test2 does not exists */ double a = parser_get_param_double(parser, "Test:test2"); /* This one pass and write in parser the default value 1. */ a = parser_get_opt_param_double(parser, "Test:test2", 1.); /* Now this one pass because the previous line add the parameter to parser */ a = parser_get_param_double(parser, "Test:test2");
My question now is what should we do in the second case? Should we fail the last line or not? I think that both solutions can be accepted. If we accept it, it means that we do not have to update all the calls when changing a default value and we consider that the developer knows the call order. If we refuse it, it means that we do not accept changes in the type (mandatory/optional) of a parameter.
- Resolved by Matthieu Schaller
- Resolved by Matthieu Schaller
Thanks for the update!.
@pdraper was there anything more from last week's discussion that you think should be done here?
assigned to @matthieu
added 2 commits