Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions albatross/core/parameter_handling_mixin.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,27 @@ class ParameterHandlingMixin {

virtual ~ParameterHandlingMixin(){};

void check_param_key(const ParameterKey &key) {
const ParameterStore current_params = get_params();
if (!map_contains(current_params, key)) {
std::cerr << "Error: Key `" << key << "` not found in parameters: "
<< pretty_params(current_params);
exit(EXIT_FAILURE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this differ from a failed assert?

Copy link
Contributor Author

@benjamin0 benjamin0 Jul 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exit() "causes normal program termination to occur" while assert(false) "causes abnormal program termination". (https://en.cppreference.com/w/cpp/utility/program/abort) Practically, I don't think it really matters here, I just thought exit() was clearer in this case since we've already checked the condition.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool thanks.

}
}

/*
* Provides a safe interface to the parameter values
*/
void set_params(const ParameterStore &params) {
const ParameterStore current_params = get_params();
for (const auto &pair : params) {
assert(map_contains(current_params, pair.first));
check_param_key(pair.first);
unchecked_set_param(pair.first, pair.second);
}
}

void set_param(const ParameterKey &key, const ParameterValue &value) {
assert(map_contains(get_params(), key));
check_param_key(key);
unchecked_set_param(key, value);
}

Expand Down