1
0
Fork 0

allow or disallow overriding options

This commit is contained in:
jsteemann 2016-02-26 22:31:44 +01:00
parent a0cec69852
commit 1dc877db5d
1 changed files with 14 additions and 1 deletions

View File

@ -105,9 +105,15 @@ class ProgramOptions {
ProcessingResult& processingResult() { return _processingResult; }
// seal the options
// tryin to add an option or a section after sealing will throw an error
// trying to add an option or a section after sealing will throw an error
void seal() { _sealed = true; }
// allow or disallow overriding already set options
bool allowOverride(bool value) {
checkIfSealed();
_overrideOptions = value;
}
// set context for error reporting
void setContext(std::string const& value) { _context = value; }
@ -260,6 +266,11 @@ class ProgramOptions {
// sets a value for an option
bool setValue(std::string const& name, std::string const& value) {
if (!_overrideOptions && _processingResult.touched(name)) {
// option already set. don't override it
return true;
}
auto parts = Option::splitName(name);
auto it = _sections.find(parts.first);
@ -463,6 +474,8 @@ class ProgramOptions {
ProcessingResult _processingResult;
// whether or not the program options setup is still mutable
bool _sealed;
// allow or disallow overriding already set options
bool _overrideOptions;
};
}
}