option_map: Don't report unused options if option_map is not used

* spot/misc/optionmap.cc, spot/misc/optionmap.hh: here.
This commit is contained in:
Florian Renkin 2022-03-22 14:46:31 +01:00
parent 8d9597d80d
commit 0a6b627914
2 changed files with 23 additions and 16 deletions

View file

@ -130,6 +130,7 @@ namespace spot
int
option_map::get(const char* option, int def) const
{
is_used_ = true;
unused_.erase(option);
auto it = options_.find(option);
return (it == options_.end()) ? def : it->second;
@ -138,6 +139,7 @@ namespace spot
std::string
option_map::get_str(const char* option, std::string def) const
{
is_used_ = true;
unused_.erase(option);
auto it = options_str_.find(option);
return (it == options_str_.end()) ? def : it->second;
@ -225,6 +227,9 @@ namespace spot
}
void option_map::report_unused_options() const
{
// We don't consider that an unused map has unused options.
if (is_used_)
{
auto s = unused_.size();
if (s == 0U)
@ -244,3 +249,4 @@ namespace spot
throw std::runtime_error(os.str());
}
}
}

View file

@ -110,6 +110,7 @@ namespace spot
// will be erased as they are used. The resulting set can be used
// for diagnosing errors.
mutable std::set<std::string> unused_;
mutable bool is_used_ = false;
void set_(const std::string&, int val);
void set_str_(const std::string&, const std::string& val);