Skip to content

Configuration: new method and exception

Simon Spannagel requested to merge config_count into master

It turned out at a few places that we will have mutually exclusive parameters in some modules and it would be nice to add a way to check this. This MR adds a new method to the Configuration object:

unsigned int number = config_.count({"key1","key2","key3"});
if(number > 1) {
    // do something
}

This allows to check if more than one key of a certain set is defined. Documentation is updated.

Furthermore, it also adds a new exception since InvalidValueError is not really suited here, as already pointed out earlier by @mvicente (thanks!). So now we have

// Check if we have mutually exclusive options defined:
if(config.count({"exclusive_opt_a", "exclusive_opt_b"}) > 1) {
    // Raise an error if the combination of keys is not valid
    //   provide the configuration object, keys and an explanation
    throw InvalidCombinationError(config, {"exclusive_opt_a", "exclusive_opt_b"}, "Options A and B are mutually exclusive, specify only one.");
}

which is appropriate to notify the user about a wrong combination of options. Options not present in the file are filtered and only the offending keys are printed in the error message.

This MR also applies this to the CapactiveTransfer module. It is ready and can be merged after review.

Merge request reports