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:
parent
8d9597d80d
commit
0a6b627914
2 changed files with 23 additions and 16 deletions
|
|
@ -130,6 +130,7 @@ namespace spot
|
||||||
int
|
int
|
||||||
option_map::get(const char* option, int def) const
|
option_map::get(const char* option, int def) const
|
||||||
{
|
{
|
||||||
|
is_used_ = true;
|
||||||
unused_.erase(option);
|
unused_.erase(option);
|
||||||
auto it = options_.find(option);
|
auto it = options_.find(option);
|
||||||
return (it == options_.end()) ? def : it->second;
|
return (it == options_.end()) ? def : it->second;
|
||||||
|
|
@ -138,6 +139,7 @@ namespace spot
|
||||||
std::string
|
std::string
|
||||||
option_map::get_str(const char* option, std::string def) const
|
option_map::get_str(const char* option, std::string def) const
|
||||||
{
|
{
|
||||||
|
is_used_ = true;
|
||||||
unused_.erase(option);
|
unused_.erase(option);
|
||||||
auto it = options_str_.find(option);
|
auto it = options_str_.find(option);
|
||||||
return (it == options_str_.end()) ? def : it->second;
|
return (it == options_str_.end()) ? def : it->second;
|
||||||
|
|
@ -225,6 +227,9 @@ namespace spot
|
||||||
}
|
}
|
||||||
|
|
||||||
void option_map::report_unused_options() const
|
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();
|
auto s = unused_.size();
|
||||||
if (s == 0U)
|
if (s == 0U)
|
||||||
|
|
@ -244,3 +249,4 @@ namespace spot
|
||||||
throw std::runtime_error(os.str());
|
throw std::runtime_error(os.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,7 @@ namespace spot
|
||||||
// will be erased as they are used. The resulting set can be used
|
// will be erased as they are used. The resulting set can be used
|
||||||
// for diagnosing errors.
|
// for diagnosing errors.
|
||||||
mutable std::set<std::string> unused_;
|
mutable std::set<std::string> unused_;
|
||||||
|
mutable bool is_used_ = false;
|
||||||
|
|
||||||
void set_(const std::string&, int val);
|
void set_(const std::string&, int val);
|
||||||
void set_str_(const std::string&, const std::string& val);
|
void set_str_(const std::string&, const std::string& val);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue